From 76c4f767c4312976dba0fbadfa6c27b84e31faa9 Mon Sep 17 00:00:00 2001 From: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> Date: Fri, 22 Mar 2024 19:46:39 -0700 Subject: [PATCH] chore: Move `db.` to a new branch (#4349) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Aljaž Mur Eržen --- CHANGELOG.md | 7 - README.md | 4 +- lutra/bindings/python/README.md | 2 +- lutra/example-project/Project.prql | 6 +- .../dotnet/PrqlCompiler.Tests/CompilerTest.cs | 4 +- prqlc/bindings/dotnet/README.md | 2 +- prqlc/bindings/elixir/README.md | 4 +- prqlc/bindings/elixir/lib/prql.ex | 4 +- prqlc/bindings/elixir/test/prql_test.exs | 2 +- .../org/prql/prql4j/PrqlCompilerTest.java | 4 +- prqlc/bindings/js/README.md | 16 +- prqlc/bindings/js/tests/test_all.mjs | 20 +- prqlc/bindings/php/README.md | 2 +- prqlc/bindings/php/tests/CompilerTest.php | 6 +- .../prqlc-c/examples/minimal-c/main.c | 2 +- .../prqlc-c/examples/minimal-cpp/main.cpp | 2 +- .../prqlc-c/examples/minimal-zig/src/main.zig | 4 +- prqlc/bindings/prqlc-python/README.md | 4 +- .../prqlc-python/python/tests/test_all.py | 8 +- prqlc/bindings/prqlc-python/src/lib.rs | 4 +- prqlc/prql-compiler-macros/src/lib.rs | 2 +- ...qlc_parser__test__pipeline_parse_tree.snap | 5 +- prqlc/prqlc-parser/src/test.rs | 81 +-- prqlc/prqlc/README.md | 6 +- .../compile-files/queries/query1.prql | 4 +- .../compile-files/queries/variables.prql | 2 +- prqlc/prqlc/src/cli/mod.rs | 16 +- prqlc/prqlc/src/lib.rs | 6 +- prqlc/prqlc/src/semantic/mod.rs | 19 +- prqlc/prqlc/src/semantic/resolver/expr.rs | 1 + .../prqlc/src/semantic/resolver/functions.rs | 10 +- prqlc/prqlc/src/semantic/resolver/mod.rs | 26 +- prqlc/prqlc/src/semantic/resolver/names.rs | 47 +- ...c__resolver__test__frames_and_names-2.snap | 6 +- ...c__resolver__test__frames_and_names-3.snap | 14 +- ...tic__resolver__test__frames_and_names.snap | 4 +- ..._resolver__test__functions_pipeline-2.snap | 9 +- ...c__resolver__test__functions_pipeline.snap | 9 +- ...ms__tests__aggregate_positional_arg-2.snap | 31 +- .../prqlc/src/semantic/resolver/transforms.rs | 12 +- prqlc/prqlc/src/semantic/std.prql | 12 +- prqlc/prqlc/src/sql/gen_projection.rs | 2 +- prqlc/prqlc/src/sql/gen_query.rs | 6 +- prqlc/prqlc/src/sql/mod.rs | 2 +- prqlc/prqlc/src/sql/srq/mod.rs | 8 +- .../tests/integration/bad_error_messages.rs | 32 +- prqlc/prqlc/tests/integration/cli.rs | 18 +- prqlc/prqlc/tests/integration/dbs/README.md | 4 +- .../prqlc/tests/integration/error_messages.rs | 46 +- .../integration/queries/aggregation.prql | 2 +- .../tests/integration/queries/arithmetic.prql | 2 +- .../prqlc/tests/integration/queries/cast.prql | 2 +- .../integration/queries/constants_only.prql | 2 +- .../integration/queries/date_to_text.prql | 2 +- .../tests/integration/queries/distinct.prql | 2 +- .../integration/queries/distinct_on.prql | 2 +- .../integration/queries/genre_counts.prql | 4 +- .../tests/integration/queries/group_all.prql | 5 +- .../tests/integration/queries/group_sort.prql | 2 +- .../queries/group_sort_limit_take.prql | 4 +- .../integration/queries/invoice_totals.prql | 5 +- .../tests/integration/queries/loop_01.prql | 2 +- .../integration/queries/math_module.prql | 2 +- .../tests/integration/queries/pipelines.prql | 2 +- .../tests/integration/queries/read_csv.prql | 2 +- .../integration/queries/set_ops_remove.prql | 2 +- .../prqlc/tests/integration/queries/sort.prql | 5 +- .../tests/integration/queries/switch.prql | 2 +- .../prqlc/tests/integration/queries/take.prql | 2 +- .../integration/queries/text_module.prql | 2 +- .../tests/integration/queries/window.prql | 2 +- prqlc/prqlc/tests/integration/resolving.rs | 4 +- .../snapshots/integration__cli__debug.snap | 22 +- ...egration__queries__compile__group_all.snap | 4 +- ...ion__queries__compile__invoice_totals.snap | 26 +- .../integration__queries__compile__sort.snap | 26 +- ...ntegration__queries__fmt__aggregation.snap | 4 +- ...integration__queries__fmt__arithmetic.snap | 4 +- .../integration__queries__fmt__cast.snap | 4 +- ...gration__queries__fmt__constants_only.snap | 4 +- ...tegration__queries__fmt__date_to_text.snap | 4 +- .../integration__queries__fmt__distinct.snap | 4 +- ...ntegration__queries__fmt__distinct_on.snap | 4 +- ...tegration__queries__fmt__genre_counts.snap | 6 +- .../integration__queries__fmt__group_all.snap | 7 +- ...integration__queries__fmt__group_sort.snap | 4 +- ...__queries__fmt__group_sort_limit_take.snap | 6 +- ...gration__queries__fmt__invoice_totals.snap | 9 +- .../integration__queries__fmt__loop_01.snap | 4 +- ...ntegration__queries__fmt__math_module.snap | 4 +- .../integration__queries__fmt__pipelines.snap | 4 +- .../integration__queries__fmt__read_csv.snap | 4 +- ...gration__queries__fmt__set_ops_remove.snap | 7 +- .../integration__queries__fmt__sort.snap | 7 +- .../integration__queries__fmt__switch.snap | 4 +- .../integration__queries__fmt__take.snap | 4 +- ...ntegration__queries__fmt__text_module.snap | 4 +- .../integration__queries__fmt__window.snap | 4 +- ...ntegration__queries__lex__aggregation.snap | 60 +- ...integration__queries__lex__arithmetic.snap | 503 ++++++------- .../integration__queries__lex__cast.snap | 66 +- ...gration__queries__lex__constants_only.snap | 40 +- ...tegration__queries__lex__date_to_text.snap | 310 ++++---- .../integration__queries__lex__distinct.snap | 48 +- ...ntegration__queries__lex__distinct_on.snap | 74 +- ...tegration__queries__lex__genre_counts.snap | 53 +- .../integration__queries__lex__group_all.snap | 97 ++- ...integration__queries__lex__group_sort.snap | 90 ++- ...__queries__lex__group_sort_limit_take.snap | 102 ++- ...gration__queries__lex__invoice_totals.snap | 310 ++++---- .../integration__queries__lex__loop_01.snap | 81 +-- ...ntegration__queries__lex__math_module.snap | 392 +++++----- .../integration__queries__lex__pipelines.snap | 84 ++- .../integration__queries__lex__read_csv.snap | 15 +- ...gration__queries__lex__set_ops_remove.snap | 71 +- .../integration__queries__lex__sort.snap | 120 ++-- .../integration__queries__lex__switch.snap | 70 +- .../integration__queries__lex__take.snap | 28 +- ...ntegration__queries__lex__text_module.snap | 250 ++++--- .../integration__queries__lex__window.snap | 126 ++-- prqlc/prqlc/tests/integration/sql.rs | 676 ++++++++---------- web/book/src/how-do-i/distinct.md | 1 - web/book/src/lib.rs | 4 +- .../src/project/integrations/postgresql.md | 2 +- .../integrations/syntax-highlighting.md | 2 +- web/book/src/project/target.md | 10 +- web/book/src/reference/data/from.md | 18 +- web/book/src/reference/data/read-files.md | 2 +- .../src/reference/data/relation-literals.md | 4 +- .../src/reference/declarations/functions.md | 14 +- .../src/reference/declarations/variables.md | 12 +- web/book/src/reference/spec/modules.md | 13 +- .../src/reference/spec/name-resolution.md | 6 +- web/book/src/reference/spec/null.md | 2 +- web/book/src/reference/stdlib/README.md | 2 +- web/book/src/reference/stdlib/date.md | 6 +- web/book/src/reference/stdlib/distinct.md | 10 +- web/book/src/reference/stdlib/math.md | 2 +- web/book/src/reference/stdlib/text.md | 2 +- .../reference/stdlib/transforms/aggregate.md | 6 +- .../src/reference/stdlib/transforms/append.md | 23 +- .../src/reference/stdlib/transforms/derive.md | 4 +- .../src/reference/stdlib/transforms/filter.md | 8 +- .../src/reference/stdlib/transforms/group.md | 6 +- .../src/reference/stdlib/transforms/join.md | 24 +- .../src/reference/stdlib/transforms/loop.md | 2 +- .../src/reference/stdlib/transforms/select.md | 17 +- .../src/reference/stdlib/transforms/sort.md | 14 +- .../src/reference/stdlib/transforms/take.md | 4 +- .../src/reference/stdlib/transforms/window.md | 12 +- web/book/src/reference/syntax/README.md | 2 +- web/book/src/reference/syntax/case.md | 4 +- web/book/src/reference/syntax/comments.md | 2 +- web/book/src/reference/syntax/f-strings.md | 6 +- .../src/reference/syntax/function-calls.md | 8 +- web/book/src/reference/syntax/keywords.md | 24 +- web/book/src/reference/syntax/literals.md | 10 +- web/book/src/reference/syntax/operators.md | 28 +- web/book/src/reference/syntax/parameters.md | 2 +- web/book/src/reference/syntax/pipes.md | 10 +- web/book/src/reference/syntax/r-strings.md | 2 +- web/book/src/reference/syntax/ranges.md | 4 +- web/book/src/reference/syntax/s-strings.md | 19 +- web/book/src/reference/syntax/strings.md | 6 +- web/book/src/reference/syntax/tuples.md | 4 +- web/book/src/tutorial/aggregation.md | 12 +- web/book/src/tutorial/annotated_example.md | 4 +- web/book/src/tutorial/filtering.md | 8 +- web/book/src/tutorial/relations.md | 22 +- ...ation__book__reference__data__from__3.snap | 10 + ...ame-resolution__translating-to-sql__1.snap | 2 +- ..._remove-duplicates-from-each-group__0.snap | 3 +- ..._remove-duplicates-from-each-group__1.snap | 3 +- ...stdlib__transforms__join__examples__1.snap | 11 +- ...stdlib__transforms__join__examples__2.snap | 5 +- ...stdlib__transforms__join__examples__3.snap | 11 + ...dlib__transforms__select__examples__3.snap | 4 +- ...syntax__pipes__cest-ne-pas-un-pipe__1.snap | 2 +- ...book__reference__syntax__s-strings__2.snap | 18 +- web/playground/src/examples.js | 17 +- web/prql-codemirror-demo/src/main.ts | 2 +- web/website/content/demos/ace-demo.html | 4 +- web/website/content/faq.md | 6 +- .../content/posts/2022-05-19-examples.md | 6 +- .../posts/2023-01-07-functional-relations.md | 10 +- .../content/posts/2023-01-27-prql-query.md | 2 +- .../_index.md | 2 +- .../posts/2023-02-02-one-year/_index.md | 2 +- .../content/posts/2023-03-14-pi-day.md | 2 +- web/website/data/examples/basic.yaml | 2 +- web/website/data/examples/dialects.yaml | 2 +- web/website/data/examples/expressions.yaml | 2 +- web/website/data/examples/f-strings.yaml | 2 +- .../data/examples/friendly-syntax.yaml | 2 +- web/website/data/examples/functions.yaml | 2 +- web/website/data/examples/hero.yaml | 4 +- web/website/data/examples/joins.yaml | 6 +- web/website/data/examples/null-handling.yaml | 2 +- web/website/data/examples/orthogonal.yaml | 2 +- web/website/data/examples/s-strings.yaml | 2 +- web/website/data/examples/top-n.yaml | 2 +- web/website/data/examples/windows.yaml | 2 +- 202 files changed, 2464 insertions(+), 2557 deletions(-) delete mode 100644 web/book/src/how-do-i/distinct.md create mode 100644 web/book/tests/documentation/snapshots/documentation__book__reference__data__from__3.snap create mode 100644 web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__transforms__join__examples__3.snap diff --git a/CHANGELOG.md b/CHANGELOG.md index 878667f22060..85a157ec9f80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,13 +10,6 @@ generates Markdown documentation from `.prql` files. (@vanillajonathan, #4152). -- _Breaking_: References to database tables now require an explicit `db.` - prefix. Example: - ```prql no-eval - from db.my_table - join db.another_table (==some_id) - ``` - **Fixes**: **Documentation**: diff --git a/README.md b/README.md index 8020592c4064..adc8d946fc55 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ since it compiles to SQL. PRQL can be as simple as: ```elm -from db.tracks +from tracks filter artist == "Bob Marley" # Each line transforms the previous result aggregate { # `aggregate` reduces each column to a value plays = sum plays, @@ -38,7 +38,7 @@ aggregate { # `aggregate` reduces each column Here's a fuller example of the language; ```elm -from db.employees +from employees filter start_date > @2021-01-01 # Clear date syntax derive { # `derive` adds columns / variables gross_salary = salary + (tax ?? 0), # Terse coalesce diff --git a/lutra/bindings/python/README.md b/lutra/bindings/python/README.md index 8df18960690d..71ef3fc70394 100644 --- a/lutra/bindings/python/README.md +++ b/lutra/bindings/python/README.md @@ -16,7 +16,7 @@ module my_database { let artists <[{artist_id = int, name = text}]> } -from db.my_database.artists +from my_database.artists select {artist_id, text} into main ``` diff --git a/lutra/example-project/Project.prql b/lutra/example-project/Project.prql index e8f2999926da..7328d0d41d0e 100644 --- a/lutra/example-project/Project.prql +++ b/lutra/example-project/Project.prql @@ -12,8 +12,8 @@ let favourite_artists = [ {artist_id = 7, last_listen = @2023-05-16}, ] -favourite_artists -join (chinook.artists | select {artist_id, name}) side:left (==artist_id) +from favourite_artists +join input = (from chinook.artists | select {artist_id, name}) side:left (==artist_id) derive aid = favourite_artists.artist_id * 2 -select {aid, name, favourite_artists.last_listen} +select {aid, input.name, favourite_artists.last_listen} sort {-aid} diff --git a/prqlc/bindings/dotnet/PrqlCompiler.Tests/CompilerTest.cs b/prqlc/bindings/dotnet/PrqlCompiler.Tests/CompilerTest.cs index c4e021851cea..5d7fdf1e1e91 100644 --- a/prqlc/bindings/dotnet/PrqlCompiler.Tests/CompilerTest.cs +++ b/prqlc/bindings/dotnet/PrqlCompiler.Tests/CompilerTest.cs @@ -17,7 +17,7 @@ public void ToCompile_Works() }; // Act - var result = PrqlCompiler.Compile("from db.employees", options); + var result = PrqlCompiler.Compile("from employees", options); // Assert Assert.Equal(expected, result.Output); @@ -28,7 +28,7 @@ public void TestOtherFunctions() { // Arrange var query = """ - let a = (from db.employees | take 10) + let a = (from employees | take 10) from a | select {first_name} """; diff --git a/prqlc/bindings/dotnet/README.md b/prqlc/bindings/dotnet/README.md index c6347c7244fb..e0ddacd4e050 100644 --- a/prqlc/bindings/dotnet/README.md +++ b/prqlc/bindings/dotnet/README.md @@ -27,7 +27,7 @@ var options = new PrqlCompilerOptions Format = false, SignatureComment = false, }; -var sql = PrqlCompiler.Compile("from db.employees", options); +var sql = PrqlCompiler.Compile("from employees", options); Console.WriteLine(sql); ``` diff --git a/prqlc/bindings/elixir/README.md b/prqlc/bindings/elixir/README.md index 89d9caa62135..151620dc8b96 100644 --- a/prqlc/bindings/elixir/README.md +++ b/prqlc/bindings/elixir/README.md @@ -15,11 +15,11 @@ end ## Basic Usage ```elixir - iex> PRQL.compile("from db.customers") + iex> PRQL.compile("from customers") {:ok, "SELECT\n *\nFROM\n customers\n\n-- Generated by PRQL compiler version 0.3.1 (https://prql-lang.org)\n"} - iex> PRQL.compile("from db.customers\ntake 10", dialect: :mssql) + iex> PRQL.compile("from customers\ntake 10", dialect: :mssql) {:ok, "SELECT\n *\nFROM\n customers\nORDER BY\n (\n SELECT\n NULL\n ) OFFSET 0 ROWS\nFETCH FIRST\n 10 ROWS ONLY\n\n-- Generated by PRQL compiler version 0.3.1 (https://prql-lang.org)\n"} ``` diff --git a/prqlc/bindings/elixir/lib/prql.ex b/prqlc/bindings/elixir/lib/prql.ex index c1d4c50b5b33..a7c6f7e16f6a 100644 --- a/prqlc/bindings/elixir/lib/prql.ex +++ b/prqlc/bindings/elixir/lib/prql.ex @@ -47,12 +47,12 @@ defmodule PRQL do ## Examples Using default `Generic` target: - iex> PRQL.compile("from db.customers", signature_comment: false) + iex> PRQL.compile("from customers", signature_comment: false) {:ok, "SELECT\n *\nFROM\n customers\n"} Using `MSSQL` target: - iex> PRQL.compile("from db.customers\ntake 10", target: :mssql, signature_comment: false) + iex> PRQL.compile("from customers\ntake 10", target: :mssql, signature_comment: false) {:ok, "SELECT\n *\nFROM\n customers\nORDER BY\n (\n SELECT\n NULL\n ) OFFSET 0 ROWS\nFETCH FIRST\n 10 ROWS ONLY\n"} """ @spec compile(binary(), [compile_opts()]) :: {:ok, binary()} | {:error, binary()} diff --git a/prqlc/bindings/elixir/test/prql_test.exs b/prqlc/bindings/elixir/test/prql_test.exs index d963dbeadd0b..287ec1de7d06 100644 --- a/prqlc/bindings/elixir/test/prql_test.exs +++ b/prqlc/bindings/elixir/test/prql_test.exs @@ -5,7 +5,7 @@ defmodule PRQLTest do @compile_opts [signature_comment: false] test "compiles PRQL" do - prql_query = "from db.customers" + prql_query = "from customers" assert PRQL.compile(prql_query, @compile_opts) == {:ok, diff --git a/prqlc/bindings/java/java/src/test/java/org/prql/prql4j/PrqlCompilerTest.java b/prqlc/bindings/java/java/src/test/java/org/prql/prql4j/PrqlCompilerTest.java index 2c59ba8a1744..3b3f7d591136 100644 --- a/prqlc/bindings/java/java/src/test/java/org/prql/prql4j/PrqlCompilerTest.java +++ b/prqlc/bindings/java/java/src/test/java/org/prql/prql4j/PrqlCompilerTest.java @@ -5,7 +5,7 @@ public class PrqlCompilerTest { @Test public void compile() throws Exception { - String found = PrqlCompiler.toSql("from db.my_table", "sql.mysql", true, true); + String found = PrqlCompiler.toSql("from my_table", "sql.mysql", true, true); // remove signature found = found.substring(0, found.indexOf("\n\n--")); @@ -19,6 +19,6 @@ public void compile() throws Exception { @Test(expected = Exception.class) public void compileWithError() throws Exception { - PrqlCompiler.toSql("from db.table | filter id >> 1", "sql.mysql", true, true); + PrqlCompiler.toSql("from table | filter id >> 1", "sql.mysql", true, true); } } diff --git a/prqlc/bindings/js/README.md b/prqlc/bindings/js/README.md index 175ed96d78dd..0d77688b7f4e 100644 --- a/prqlc/bindings/js/README.md +++ b/prqlc/bindings/js/README.md @@ -31,7 +31,7 @@ Direct usage ```javascript const prqljs = require("prql-js"); -const sql = prqljs.compile(`from db.employees | select first_name`); +const sql = prqljs.compile(`from employees | select first_name`); console.log(sql); ``` @@ -43,7 +43,7 @@ opts.target = "sql.mssql"; opts.format = false; opts.signature_comment = false; -const sql = prqljs.compile(`from db.employees | take 10`, opts); +const sql = prqljs.compile(`from employees | take 10`, opts); console.log(sql); ``` @@ -53,7 +53,7 @@ Template literal const prqljs = require("prql-js"); const prql = (string) => prqljs.compile(string[0] || ""); -const sql = prql`from db.employees | select first_name`; +const sql = prql`from employees | select first_name`; console.log(sql); ``` @@ -64,7 +64,7 @@ const prqljs = require("prql-js"); const prql = (string) => prqljs.compile(string[0] || ""); const sql = prql` - from db.employees + from employees select first_name `; console.log(sql); @@ -76,10 +76,10 @@ console.log(sql); @@ -93,7 +93,7 @@ console.log(sql); ```typescript import compile from "prql-js/dist/bundler"; -const sql = compile(`from db.employees | select first_name`); +const sql = compile(`from employees | select first_name`); console.log(sql); ``` @@ -135,7 +135,7 @@ These errors can be caught as such: ```javascript try { - const sql = prqlJs.compile(`from db.employees | foo first_name`); + const sql = prqlJs.compile(`from employees | foo first_name`); } catch (error) { const errorMessages = JSON.parse(error.message).inner; diff --git a/prqlc/bindings/js/tests/test_all.mjs b/prqlc/bindings/js/tests/test_all.mjs index 0191ade2f97e..8619dc3648a8 100644 --- a/prqlc/bindings/js/tests/test_all.mjs +++ b/prqlc/bindings/js/tests/test_all.mjs @@ -2,15 +2,15 @@ import assert from "assert"; import { expect } from "chai"; import prql from "../dist/node/prql_js.js"; -const employee_prql = `from db.employees -join db.salaries (==emp_no) +const employee_prql = `from employees +join salaries (==emp_no) group {employees.emp_no, employees.gender} ( aggregate { emp_salary = average salaries.salary } ) -join de = db.dept_emp (==emp_no) -join dm = db.dept_manager ( +join de=dept_emp (==emp_no) +join dm=dept_manager ( (dm.dept_no == de.dept_no) && s"(de.from_date, de.to_date) OVERLAPS (dm.from_date, dm.to_date)" ) group {dm.emp_no, gender} ( @@ -20,7 +20,7 @@ group {dm.emp_no, gender} ( } ) derive mng_no = emp_no -join managers = db.employees (==emp_no) +join managers=employees (==emp_no) derive mng_name = s"managers.first_name || ' ' || managers.last_name" select {mng_name, managers.gender, salary_avg, salary_sd}`; @@ -46,7 +46,7 @@ describe("prql-js", () => { opts.format = false; opts.signature_comment = false; - const res = prql.compile("from db.a | take 10", opts); + const res = prql.compile("from a | take 10", opts); assert.equal( res, "SELECT * FROM a ORDER BY (SELECT NULL) OFFSET 0 ROWS FETCH FIRST 10 ROWS ONLY", @@ -60,7 +60,7 @@ describe("prql-js", () => { opts.signature_comment = true; const res = prql.compile( - "prql target:sql.sqlite\nfrom db.a | take 10", + "prql target:sql.sqlite\nfrom a | take 10", opts, ); assert( @@ -94,7 +94,7 @@ describe("prql-js", () => { const opts = new prql.CompileOptions(); opts.target = "sql.any"; - const res = prql.compile("prql target:sql.mssql\nfrom db.a | take 1", opts); + const res = prql.compile("prql target:sql.mssql\nfrom a | take 1", opts); assert(res.includes("1 ROWS ONLY")); }); }); @@ -110,7 +110,7 @@ describe("prql-js", () => { describe("compile error", () => { it("should contain json", () => { try { - prql.compile("from db.x | select a | select b"); + prql.compile("from x | select a | select b"); } catch (error) { const errorMessages = JSON.parse(error.message).inner; @@ -122,7 +122,7 @@ describe("prql-js", () => { it("should contain error code", () => { try { - prql.compile("let a = (from db.x)"); + prql.compile("let a = (from x)"); } catch (error) { const errorMessages = JSON.parse(error.message).inner; diff --git a/prqlc/bindings/php/README.md b/prqlc/bindings/php/README.md index 0fa2234bb563..4df0b060a273 100644 --- a/prqlc/bindings/php/README.md +++ b/prqlc/bindings/php/README.md @@ -21,7 +21,7 @@ enabled. Set `ffi.enable` in your php.ini configuration file to `"true"`. use Prql\Compiler\Compiler; $prql = new Compiler(); -$result = $prql->compile("from db.employees"); +$result = $prql->compile("from employees"); echo $result->output; ``` diff --git a/prqlc/bindings/php/tests/CompilerTest.php b/prqlc/bindings/php/tests/CompilerTest.php index 17b986fcaf2d..2050da32b110 100644 --- a/prqlc/bindings/php/tests/CompilerTest.php +++ b/prqlc/bindings/php/tests/CompilerTest.php @@ -45,7 +45,7 @@ public function testCompileWorks(): void $options->target = "sql.mssql"; $prql = new Compiler(); - $actual = $prql->compile("from db.employees | take 10", $options); + $actual = $prql->compile("from employees | take 10", $options); $this->assertCount(0, $actual->messages); $this->assertEquals( @@ -59,9 +59,9 @@ public function testOtherFunctions(): void $prql = new Compiler(); $query = " - let a = (from db.employees | take 10) + let a = (from employees | take 10) - from db.a | select {first_name} + from a | select {first_name} "; $pl = $prql->prqlToPL($query); diff --git a/prqlc/bindings/prqlc-c/examples/minimal-c/main.c b/prqlc/bindings/prqlc-c/examples/minimal-c/main.c index 36c11f4a4004..66c6f00b5aa2 100644 --- a/prqlc/bindings/prqlc-c/examples/minimal-c/main.c +++ b/prqlc/bindings/prqlc-c/examples/minimal-c/main.c @@ -23,7 +23,7 @@ void print_result(CompileResult res) { int main() { char *prql_query; - prql_query = "from db.albums | select {album_id, title} | take 3"; + prql_query = "from albums | select {album_id, title} | take 3"; CompileResult res; CompileResult res2; diff --git a/prqlc/bindings/prqlc-c/examples/minimal-cpp/main.cpp b/prqlc/bindings/prqlc-c/examples/minimal-cpp/main.cpp index 1032596d66ae..0f6e9cb7cc6d 100644 --- a/prqlc/bindings/prqlc-c/examples/minimal-cpp/main.cpp +++ b/prqlc/bindings/prqlc-c/examples/minimal-cpp/main.cpp @@ -14,7 +14,7 @@ void print_result(CompileResult res) { } int main() { - const auto prql_query = "from db.albums | select {album_id, title} | take 3"; + const auto prql_query = "from albums | select {album_id, title} | take 3"; CompileResult res = compile(prql_query, nullptr); print_result(res); diff --git a/prqlc/bindings/prqlc-c/examples/minimal-zig/src/main.zig b/prqlc/bindings/prqlc-c/examples/minimal-zig/src/main.zig index 6f881fe1392f..b81f07d1d1c8 100644 --- a/prqlc/bindings/prqlc-c/examples/minimal-zig/src/main.zig +++ b/prqlc/bindings/prqlc-c/examples/minimal-zig/src/main.zig @@ -14,7 +14,7 @@ pub fn main() !void { }; // Compile the PRQL query - const prql_query = "from db.albums | select {album_id, title} | take 3"; + const prql_query = "from albums | select {album_id, title} | take 3"; const result = prql.compile(prql_query, &options); defer prql.result_destroy(result); @@ -23,7 +23,7 @@ pub fn main() !void { } test "simple test" { - const prql_query = "from db.albums | select {album_id, title} | take 3"; + const prql_query = "from albums | select {album_id, title} | take 3"; const result = prql.compile(prql_query, null); defer prql.result_destroy(result); try std.testing.expect(result.messages_len == 0); diff --git a/prqlc/bindings/prqlc-python/README.md b/prqlc/bindings/prqlc-python/README.md index 35d7a1b52df7..b639e8d9325d 100644 --- a/prqlc/bindings/prqlc-python/README.md +++ b/prqlc/bindings/prqlc-python/README.md @@ -21,8 +21,8 @@ The crate is not published to crates.io; only to PyPI at import prqlc prql_query = """ - from db.employees - join db.salaries (==emp_id) + from employees + join salaries (==emp_id) group {employees.dept_id, employees.gender} ( aggregate { avg_salary = average salaries.salary diff --git a/prqlc/bindings/prqlc-python/python/tests/test_all.py b/prqlc/bindings/prqlc-python/python/tests/test_all.py index f0ca0e27ea2b..e18f4d884154 100644 --- a/prqlc/bindings/prqlc-python/python/tests/test_all.py +++ b/prqlc/bindings/prqlc-python/python/tests/test_all.py @@ -9,7 +9,7 @@ def test_all() -> None: should write more tests at some point. """ - prql_query = "from db.employee" + prql_query = "from employee" res = prqlc.prql_to_pl(prql_query) assert res is not None @@ -26,8 +26,8 @@ def test_all() -> None: # Example from readme prql_query = """ - from db.employees - join db.salaries (==emp_id) + from employees + join salaries (==emp_id) group {employees.dept_id, employees.gender} ( aggregate { avg_salary = average salaries.salary @@ -47,7 +47,7 @@ def test_compile_options() -> None: """ Test the CompileOptions """ - query_mssql = "prql target:sql.mssql\nfrom db.a | take 3" + query_mssql = "prql target:sql.mssql\nfrom a | take 3" assert prqlc.compile(query_mssql).startswith( "SELECT\n *\nFROM\n a\nORDER BY\n (\n SELECT\n NULL\n ) OFFSET 0 ROWS\nFETCH FIRST\n 3 ROWS ONLY" diff --git a/prqlc/bindings/prqlc-python/src/lib.rs b/prqlc/bindings/prqlc-python/src/lib.rs index e89cda7c04d0..51b26fc9b41f 100644 --- a/prqlc/bindings/prqlc-python/src/lib.rs +++ b/prqlc/bindings/prqlc-python/src/lib.rs @@ -148,7 +148,7 @@ mod test { }); assert_snapshot!( - compile("from db.employees | filter (age | in 20..30)", opts).unwrap(), + compile("from employees | filter (age | in 20..30)", opts).unwrap(), @r###" SELECT * @@ -170,7 +170,7 @@ mod test { display: "plain".to_string(), }); - let prql = r#"from db.artists | select {name, id} | filter (id | in [1, 2, 3])"#; + let prql = r#"from artists | select {name, id} | filter (id | in [1, 2, 3])"#; assert_snapshot!( prql_to_pl(prql).and_then(|x| pl_to_rq(x.as_str())).and_then(|x|rq_to_sql(x.as_str(), opts)).unwrap(), @r###" SELECT diff --git a/prqlc/prql-compiler-macros/src/lib.rs b/prqlc/prql-compiler-macros/src/lib.rs index 59a652adb923..05d885f084e0 100644 --- a/prqlc/prql-compiler-macros/src/lib.rs +++ b/prqlc/prql-compiler-macros/src/lib.rs @@ -3,7 +3,7 @@ //! ``` //! use prql_compiler_macros::prql_to_sql; //! -//! let sql: &str = prql_to_sql!("from db.albums | select {title, artist_id}"); +//! let sql: &str = prql_to_sql!("from albums | select {title, artist_id}"); //! assert_eq!(sql, "SELECT title, artist_id FROM albums"); //! ``` //! diff --git a/prqlc/prqlc-parser/src/snapshots/prqlc_parser__test__pipeline_parse_tree.snap b/prqlc/prqlc-parser/src/snapshots/prqlc_parser__test__pipeline_parse_tree.snap index 5ffb11b89503..9a2444c7d54c 100644 --- a/prqlc/prqlc-parser/src/snapshots/prqlc_parser__test__pipeline_parse_tree.snap +++ b/prqlc/prqlc-parser/src/snapshots/prqlc_parser__test__pipeline_parse_tree.snap @@ -1,6 +1,6 @@ --- source: prqlc/prqlc-parser/src/test.rs -expression: "parse_single(r#\"\nfrom db.employees\nfilter country == \"USA\" # Each line transforms the previous result.\nderive { # This adds columns / variables.\n gross_salary = salary + payroll_tax,\n gross_cost = gross_salary + benefits_cost # Variables can use other variables.\n}\nfilter gross_cost > 0\ngroup {title, country} ( # For each group use a nested pipeline\n aggregate { # Aggregate each group to a single row\n average salary,\n average gross_salary,\n sum salary,\n sum gross_salary,\n average gross_cost,\n sum_gross_cost = sum gross_cost,\n ct = count salary,\n }\n)\nsort sum_gross_cost\nfilter ct > 200\ntake 20\n \"#).unwrap()" +expression: "parse_single(r#\"\nfrom employees\nfilter country == \"USA\" # Each line transforms the previous result.\nderive { # This adds columns / variables.\n gross_salary = salary + payroll_tax,\n gross_cost = gross_salary + benefits_cost # Variables can use other variables.\n}\nfilter gross_cost > 0\ngroup {title, country} ( # For each group use a nested pipeline\n aggregate { # Aggregate each group to a single row\n average salary,\n average gross_salary,\n sum salary,\n sum gross_salary,\n average gross_cost,\n sum_gross_cost = sum gross_cost,\n ct = count salary,\n }\n)\nsort sum_gross_cost\nfilter ct > 200\ntake 20\n \"#).unwrap()" --- - VarDef: kind: Main @@ -14,7 +14,6 @@ expression: "parse_single(r#\"\nfrom db.employees\nfilter country == \"USA\" - from args: - Ident: - - db - employees - FuncCall: name: @@ -160,5 +159,5 @@ expression: "parse_single(r#\"\nfrom db.employees\nfilter country == \"USA\" args: - Literal: Integer: 20 - span: "0:1-717" + span: "0:1-714" diff --git a/prqlc/prqlc-parser/src/test.rs b/prqlc/prqlc-parser/src/test.rs index ecf69b1c558a..f4ccce3e48df 100644 --- a/prqlc/prqlc-parser/src/test.rs +++ b/prqlc/prqlc-parser/src/test.rs @@ -93,7 +93,7 @@ fn test_error_unexpected() { fn test_pipeline_parse_tree() { assert_yaml_snapshot!(parse_single( r#" -from db.employees +from employees filter country == "USA" # Each line transforms the previous result. derive { # This adds columns / variables. gross_salary = salary + payroll_tax, @@ -1511,7 +1511,7 @@ fn test_op_precedence() { #[test] fn test_var_def() { assert_yaml_snapshot!(parse_single( - "let newest_employees = (from db.employees)" + "let newest_employees = (from employees)" ).unwrap(), @r###" --- - VarDef: @@ -1524,15 +1524,14 @@ fn test_var_def() { - from args: - Ident: - - db - employees - span: "0:0-42" + span: "0:0-39" "###); assert_yaml_snapshot!(parse_single( r#" let newest_employees = ( - from db.employees + from employees group country ( aggregate { average_country_salary = average salary @@ -1555,7 +1554,6 @@ fn test_var_def() { - from args: - Ident: - - db - employees - FuncCall: name: @@ -1592,7 +1590,7 @@ fn test_var_def() { args: - Literal: Integer: 50 - span: "0:0-234" + span: "0:0-231" "###); assert_yaml_snapshot!(parse_single(r#" @@ -1611,13 +1609,13 @@ fn test_var_def() { assert_yaml_snapshot!(parse_single( "let x = ( - from db.x_table + from x_table select only_in_x = foo ) - from db.x" + from x" ).unwrap(), @r###" --- - VarDef: @@ -1632,7 +1630,6 @@ fn test_var_def() { - from args: - Ident: - - db - x_table - FuncCall: name: @@ -1642,7 +1639,7 @@ fn test_var_def() { - Ident: - foo alias: only_in_x - span: "0:0-87" + span: "0:0-84" - VarDef: kind: Main name: main @@ -1653,9 +1650,8 @@ fn test_var_def() { - from args: - Ident: - - db - x - span: "0:99-108" + span: "0:96-102" "###); } @@ -1707,7 +1703,7 @@ fn test_inline_pipeline() { #[test] fn test_sql_parameters() { assert_yaml_snapshot!(parse_single(r#" - from db.mytable + from mytable filter { first_name == $1, last_name == $2.name @@ -1726,7 +1722,6 @@ fn test_sql_parameters() { - from args: - Ident: - - db - mytable - FuncCall: name: @@ -1748,7 +1743,7 @@ fn test_sql_parameters() { op: Eq right: Param: 2.name - span: "0:9-111" + span: "0:9-108" "###); } @@ -1839,7 +1834,7 @@ join `my-proj`.`dataset`.`table` #[test] fn test_sort() { assert_yaml_snapshot!(parse_single(" - from db.invoices + from invoices sort issued_at sort (-issued_at) sort {issued_at} @@ -1859,7 +1854,6 @@ fn test_sort() { - from args: - Ident: - - db - invoices - FuncCall: name: @@ -1915,14 +1909,14 @@ fn test_sort() { expr: Ident: - num_of_articles - span: "0:9-178" + span: "0:9-175" "###); } #[test] fn test_dates() { assert_yaml_snapshot!(parse_single(" - from db.employees + from employees derive {age_plus_two_years = (age + 2years)} ").unwrap(), @r###" --- @@ -1938,7 +1932,6 @@ fn test_dates() { - from args: - Ident: - - db - employees - FuncCall: name: @@ -1957,7 +1950,7 @@ fn test_dates() { n: 2 unit: years alias: age_plus_two_years - span: "0:9-80" + span: "0:9-77" "###); assert_yaml_snapshot!(parse_expr("@2011-02-01").unwrap(), @r###" @@ -2009,7 +2002,7 @@ fn test_multiline_string() { #[test] fn test_coalesce() { assert_yaml_snapshot!(parse_single(r###" - from db.employees + from employees derive amount = amount ?? 0 "###).unwrap(), @r###" --- @@ -2025,7 +2018,6 @@ fn test_coalesce() { - from args: - Ident: - - db - employees - FuncCall: name: @@ -2041,7 +2033,7 @@ fn test_coalesce() { Literal: Integer: 0 alias: amount - span: "0:9-63" + span: "0:9-60" "### ) } @@ -2070,7 +2062,7 @@ fn test_literal() { #[test] fn test_allowed_idents() { assert_yaml_snapshot!(parse_single(r###" - from db.employees + from employees join _salary (==employee_id) # table with leading underscore filter first_name == $1 select {_employees._underscored_column} @@ -2088,7 +2080,6 @@ fn test_allowed_idents() { - from args: - Ident: - - db - employees - FuncCall: name: @@ -2123,14 +2114,14 @@ fn test_allowed_idents() { - Ident: - _employees - _underscored_column - span: "0:9-176" + span: "0:9-173" "###) } #[test] fn test_gt_lt_gte_lte() { assert_yaml_snapshot!(parse_single(r###" - from db.people + from people filter age >= 100 filter num_grandchildren <= 10 filter salary > 0 @@ -2149,7 +2140,6 @@ fn test_gt_lt_gte_lte() { - from args: - Ident: - - db - people - FuncCall: name: @@ -2203,15 +2193,15 @@ fn test_gt_lt_gte_lte() { right: Literal: Integer: 2 - span: "0:9-143" + span: "0:9-140" "###) } #[test] fn test_assign() { assert_yaml_snapshot!(parse_single(r###" -from db.employees -join (db.salaries | select {s = this}) (==id) +from employees +join s=salaries (==id) "###).unwrap(), @r###" --- - VarDef: @@ -2226,33 +2216,21 @@ join (db.salaries | select {s = this}) (==id) - from args: - Ident: - - db - employees - FuncCall: name: Ident: - join args: - - Pipeline: - exprs: - - Ident: - - db - - salaries - - FuncCall: - name: - Ident: - - select - args: - - Tuple: - - Ident: - - this - alias: s + - Ident: + - salaries + alias: s - Unary: op: EqSelf expr: Ident: - id - span: "0:1-65" + span: "0:1-39" "###); } @@ -2530,7 +2508,7 @@ fn test_target() { r#" prql target:sql.sqlite - from db.film + from film remove film2 "#, ) @@ -2553,7 +2531,6 @@ fn test_target() { - from args: - Ident: - - db - film - FuncCall: name: @@ -2562,7 +2539,7 @@ fn test_target() { args: - Ident: - film2 - span: "0:45-81" + span: "0:45-78" "###); } diff --git a/prqlc/prqlc/README.md b/prqlc/prqlc/README.md index c0ddf7d6c698..3203d2fa42e9 100644 --- a/prqlc/prqlc/README.md +++ b/prqlc/prqlc/README.md @@ -18,7 +18,7 @@ binary that compiles PRQL into SQL. This command works as a filter that compiles a PRQL string into an SQL string. ```sh -$ echo 'from db.employees | filter has_dog | select salary' | prqlc compile +$ echo 'from employees | filter has_dog | select salary' | prqlc compile SELECT salary @@ -33,7 +33,7 @@ A PRQL query can be executed with CLI tools compatible with SQL,, such as ```sh $ curl -fsL https://raw.githubusercontent.com/PRQL/prql/0.8.1/prql-compiler/tests/integration/data/chinook/albums.csv -o albums.csv -$ echo 'from.`albums.csv` | take 3' | prqlc compile | duckdb +$ echo 'from `albums.csv` | take 3' | prqlc compile | duckdb ┌──────────┬───────────────────────────────────────┬───────────┐ │ album_id │ title │ artist_id │ │ int64 │ varchar │ int64 │ @@ -183,7 +183,7 @@ Compile a PRQL string to a SQLite dialect string: use prqlc::{compile, Options, DisplayOptions, Target, sql::Dialect}; -let prql = "from db.employees | select {name, age}"; +let prql = "from employees | select {name, age}"; let opts = &Options { format: false, target: Target::Sql(Some(Dialect::SQLite)), diff --git a/prqlc/prqlc/examples/compile-files/queries/query1.prql b/prqlc/prqlc/examples/compile-files/queries/query1.prql index 0f47d282be57..372bf480e168 100644 --- a/prqlc/prqlc/examples/compile-files/queries/query1.prql +++ b/prqlc/prqlc/examples/compile-files/queries/query1.prql @@ -1,3 +1,3 @@ -from db.albums +from albums select {title, artist_id} -join db.artists (==artist_id) +join artists (==artist_id) diff --git a/prqlc/prqlc/examples/compile-files/queries/variables.prql b/prqlc/prqlc/examples/compile-files/queries/variables.prql index e44b20c293ad..7c5f1ae661e9 100644 --- a/prqlc/prqlc/examples/compile-files/queries/variables.prql +++ b/prqlc/prqlc/examples/compile-files/queries/variables.prql @@ -1,4 +1,4 @@ -from db.employees +from employees filter country == "USA" # Each line transforms the previous result. derive { # This adds columns / variables. gross_salary = salary + payroll_tax, diff --git a/prqlc/prqlc/src/cli/mod.rs b/prqlc/prqlc/src/cli/mod.rs index a316fcd35f00..b2ec36dbb837 100644 --- a/prqlc/prqlc/src/cli/mod.rs +++ b/prqlc/prqlc/src/cli/mod.rs @@ -578,7 +578,7 @@ mod tests { let output = Command::execute( &Command::Debug(DebugCommand::Annotate(IoArgs::default())), &mut r#" -from db.initial_table +from initial_table select {f = first_name, l = last_name, gender} derive full_name = f"{f} {l}" take 23 @@ -591,7 +591,7 @@ sort full .unwrap(); assert_snapshot!(String::from_utf8(output).unwrap().trim(), @r###" - from db.initial_table + from initial_table select {f = first_name, l = last_name, gender} # [f, l, initial_table.gender] derive full_name = f"{f} {l}" # [f, l, initial_table.gender, full_name] take 23 # [f, l, initial_table.gender, full_name] @@ -641,7 +641,7 @@ sort full ("Project.prql".into(), "orders.x | select y".to_string()), ( "orders.prql".into(), - "let x = (from db.z | select {y, u})".to_string(), + "let x = (from z | select {y, u})".to_string(), ), ], None, @@ -709,7 +709,7 @@ sort full io_args: IoArgs::default(), format: Format::Yaml, }, - &mut "from db.x | select y".into(), + &mut "from x | select y".into(), "", ) .unwrap(); @@ -753,7 +753,7 @@ sort full io_args: IoArgs::default(), format: Format::Yaml, }, - &mut "from db.employees | sort salary | take 3 | filter salary > 0".into(), + &mut "from employees | sort salary | take 3 | filter salary > 0".into(), "", ) .unwrap(); @@ -802,12 +802,12 @@ sort full args: - kind: ColumnRef: 2 - span: 1:50-56 + span: 1:47-53 - kind: Literal: Integer: 0 - span: 1:59-60 - span: 1:50-60 + span: 1:56-57 + span: 1:47-57 - Sort: - direction: Asc column: 2 diff --git a/prqlc/prqlc/src/lib.rs b/prqlc/prqlc/src/lib.rs index 0716a2440166..a78785f89841 100644 --- a/prqlc/prqlc/src/lib.rs +++ b/prqlc/prqlc/src/lib.rs @@ -39,7 +39,7 @@ //! ``` //! # fn main() -> Result<(), prqlc::ErrorMessages> { //! let sql = prqlc::compile( -//! "from db.albums | select {title, artist_id}", +//! "from albums | select {title, artist_id}", //! &prqlc::Options::default().no_format() //! )?; //! assert_eq!(&sql[..35], "SELECT title, artist_id FROM albums"); @@ -51,7 +51,7 @@ //! //! For inline strings, use the `prql-compiler-macros` crate; for example: //! ```ignore -//! let sql: &str = prql_to_sql!("from db.albums | select {title, artist_id}"); +//! let sql: &str = prql_to_sql!("from albums | select {title, artist_id}"); //! ``` //! //! For compiling whole files (`.prql` to `.sql`), call `prqlc` @@ -129,7 +129,7 @@ use strum::VariantNames; /// ``` /// use prqlc::{compile, Options, Target, sql::Dialect}; /// -/// let prql = "from db.employees | select {name,age}"; +/// let prql = "from employees | select {name,age}"; /// let opts = Options::default().with_target(Target::Sql(Some(Dialect::SQLite))).with_signature_comment(false).with_format(false); /// let sql = compile(&prql, &opts).unwrap(); /// println!("PRQL: {}\nSQLite: {}", prql, &sql); diff --git a/prqlc/prqlc/src/semantic/mod.rs b/prqlc/prqlc/src/semantic/mod.rs index 6c7ad94f634f..8e595e19e673 100644 --- a/prqlc/prqlc/src/semantic/mod.rs +++ b/prqlc/prqlc/src/semantic/mod.rs @@ -96,7 +96,7 @@ pub const NS_STD: &str = "std"; pub const NS_THIS: &str = "this"; pub const NS_THAT: &str = "that"; pub const NS_PARAM: &str = "_param"; -pub const NS_DEFAULT_DB: &str = "db"; +pub const NS_DEFAULT_DB: &str = "default_db"; pub const NS_QUERY_DEF: &str = "prql"; pub const NS_MAIN: &str = "main"; @@ -179,7 +179,7 @@ pub mod test { #[test] fn test_resolve_01() { assert_yaml_snapshot!(parse_resolve_and_lower(r###" - from db.employees + from employees select !{foo} "###).unwrap().relation.columns, @r###" --- @@ -190,7 +190,7 @@ pub mod test { #[test] fn test_resolve_02() { assert_yaml_snapshot!(parse_resolve_and_lower(r###" - from db.foo + from foo sort day window range:-4..4 ( derive {next_four_days = sum b} @@ -207,8 +207,7 @@ pub mod test { #[test] fn test_resolve_03() { assert_yaml_snapshot!(parse_resolve_and_lower(r###" - from db.albums - select {a = this} + from a=albums filter is_sponsored select {a.*} "###).unwrap().relation.columns, @r###" @@ -221,7 +220,7 @@ pub mod test { #[test] fn test_resolve_04() { assert_yaml_snapshot!(parse_resolve_and_lower(r###" - from db.x + from x select {a, a, a = a + 1} "###).unwrap().relation.columns, @r###" --- @@ -236,7 +235,7 @@ pub mod test { assert_yaml_snapshot!(parse_resolve_and_lower(r#" prql target:sql.mssql version:"0" - from db.employees + from employees "#).unwrap(), @r###" --- def: @@ -270,7 +269,7 @@ pub mod test { assert!(parse_resolve_and_lower( r###" prql target:sql.bigquery version:foo - from db.employees + from employees "###, ) .is_err()); @@ -278,7 +277,7 @@ pub mod test { assert!(parse_resolve_and_lower( r#" prql target:sql.bigquery version:"25" - from db.employees + from employees "#, ) .is_err()); @@ -286,7 +285,7 @@ pub mod test { assert!(parse_resolve_and_lower( r###" prql target:sql.yah version:foo - from db.employees + from employees "###, ) .is_err()); diff --git a/prqlc/prqlc/src/semantic/resolver/expr.rs b/prqlc/prqlc/src/semantic/resolver/expr.rs index b11a8a69f73b..f86a79c630bd 100644 --- a/prqlc/prqlc/src/semantic/resolver/expr.rs +++ b/prqlc/prqlc/src/semantic/resolver/expr.rs @@ -162,6 +162,7 @@ impl PlFold for Resolver<'_> { named_args, }) => { // fold function name + self.default_namespace = None; let old = self.in_func_call_name; self.in_func_call_name = true; let name = Box::new(self.fold_expr(*name)?); diff --git a/prqlc/prqlc/src/semantic/resolver/functions.rs b/prqlc/prqlc/src/semantic/resolver/functions.rs index 6bbff4886b60..4f451593571e 100644 --- a/prqlc/prqlc/src/semantic/resolver/functions.rs +++ b/prqlc/prqlc/src/semantic/resolver/functions.rs @@ -372,11 +372,19 @@ impl Resolver<'_> { } fn fold_within_namespace(&mut self, expr: Expr, param_name: &str) -> Result { + let prev_namespace = self.default_namespace.take(); + if param_name.starts_with("noresolve.") { return Ok(expr); + } else if let Some((ns, _)) = param_name.split_once('.') { + self.default_namespace = Some(ns.to_string()); + } else { + self.default_namespace = None; }; - self.fold_expr(expr) + let res = self.fold_expr(expr); + self.default_namespace = prev_namespace; + res } } diff --git a/prqlc/prqlc/src/semantic/resolver/mod.rs b/prqlc/prqlc/src/semantic/resolver/mod.rs index 4cd1b9212a5e..d0224186d374 100644 --- a/prqlc/prqlc/src/semantic/resolver/mod.rs +++ b/prqlc/prqlc/src/semantic/resolver/mod.rs @@ -19,6 +19,8 @@ pub struct Resolver<'a> { current_module_path: Vec, + default_namespace: Option, + /// Sometimes ident closures must be resolved and sometimes not. See [test::test_func_call_resolve]. in_func_call_name: bool, @@ -38,6 +40,7 @@ impl Resolver<'_> { root_mod, options, current_module_path: Vec::new(), + default_namespace: None, in_func_call_name: false, id: IdGenerator::new(), generics: Default::default(), @@ -96,7 +99,7 @@ pub(super) mod test { fn test_variables_1() { assert_yaml_snapshot!(resolve_derive( r#" - from db.employees + from employees derive { gross_salary = salary + payroll_tax, gross_cost = gross_salary + benefits_cost @@ -121,7 +124,7 @@ pub(super) mod test { r#" let subtract = a b -> a - b - from db.employees + from employees derive { net_salary = subtract gross_salary tax } @@ -137,7 +140,7 @@ pub(super) mod test { let lag_day = x -> s"lag_day_todo({x})" let ret = x dividend_return -> x / (lag_day x) - 1 + dividend_return - from db.a + from a derive (ret b c) "# ) @@ -148,7 +151,7 @@ pub(super) mod test { fn test_functions_pipeline() { assert_yaml_snapshot!(resolve_derive( r#" - from db.a + from a derive one = (foo | sum) "# ) @@ -159,7 +162,7 @@ pub(super) mod test { let plus_one = x -> x + 1 let plus = x y -> x + y - from db.a + from a derive {b = (sum foo | plus_one | plus 2)} "# ) @@ -171,7 +174,7 @@ pub(super) mod test { r#" let add_one = x to:1 -> x + to - from db.foo_table + from foo_table derive { added = add_one bar to:3, added_default = add_one bar @@ -185,7 +188,7 @@ pub(super) mod test { fn test_frames_and_names() { assert_yaml_snapshot!(resolve_lineage( r#" - from db.orders + from orders select {customer_no, gross, tax, gross - tax} take 20 "# @@ -194,17 +197,16 @@ pub(super) mod test { assert_yaml_snapshot!(resolve_lineage( r#" - from db.table_1 - join db.customers(==customer_no) + from table_1 + join customers (==customer_no) "# ) .unwrap()); assert_yaml_snapshot!(resolve_lineage( r#" - from db.employees - select {e = this} - join db.salaries(==emp_no) + from e = employees + join salaries (==emp_no) group {e.emp_no, e.gender} ( aggregate { emp_salary = average salaries.salary diff --git a/prqlc/prqlc/src/semantic/resolver/names.rs b/prqlc/prqlc/src/semantic/resolver/names.rs index b15da963ddb9..44263016da08 100644 --- a/prqlc/prqlc/src/semantic/resolver/names.rs +++ b/prqlc/prqlc/src/semantic/resolver/names.rs @@ -16,16 +16,21 @@ use super::Resolver; impl Resolver<'_> { pub(super) fn resolve_ident(&mut self, ident: &Ident) -> Result { - let mut ident = ident.clone().prepend(self.current_module_path.clone()); - - let mut res = self.resolve_ident_core(&ident); - for _ in 0..self.current_module_path.len() { - if res.is_ok() { - break; + let mut res = if let Some(default_namespace) = self.default_namespace.clone() { + self.resolve_ident_core(ident, Some(&default_namespace)) + } else { + let mut ident = ident.clone().prepend(self.current_module_path.clone()); + + let mut res = self.resolve_ident_core(&ident, None); + for _ in 0..self.current_module_path.len() { + if res.is_ok() { + break; + } + ident = ident.pop_front().1.unwrap(); + res = self.resolve_ident_core(&ident, None); } - ident = ident.pop_front().1.unwrap(); - res = self.resolve_ident_core(&ident); - } + res + }; match &res { Ok(fq_ident) => { @@ -73,7 +78,11 @@ impl Resolver<'_> { cols } - pub(super) fn resolve_ident_core(&mut self, ident: &Ident) -> Result { + pub(super) fn resolve_ident_core( + &mut self, + ident: &Ident, + default_namespace: Option<&String>, + ) -> Result { // special case: wildcard if ident.name == "*" { // TODO: we may want to raise an error if someone has passed `download*` in @@ -103,7 +112,23 @@ impl Resolver<'_> { _ => return Err(ambiguous_error(decls, None)), } - let ident = ident.clone(); + let ident = if let Some(default_namespace) = default_namespace { + let ident = ident.clone().prepend(vec![default_namespace.clone()]); + + let decls = self.root_mod.module.lookup(&ident); + match decls.len() { + // no match: try match * + 0 => ident, + + // single match, great! + 1 => return Ok(decls.into_iter().next().unwrap()), + + // ambiguous + _ => return Err(ambiguous_error(decls, None)), + } + } else { + ident.clone() + }; // fallback case: try to match with NS_INFER and infer the declaration // from the original ident. diff --git a/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__test__frames_and_names-2.snap b/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__test__frames_and_names-2.snap index 7e04ae54dd48..8873df147d3b 100644 --- a/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__test__frames_and_names-2.snap +++ b/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__test__frames_and_names-2.snap @@ -1,6 +1,6 @@ --- source: prqlc/prqlc/src/semantic/resolver/mod.rs -expression: "resolve_lineage(r#\"\n from db.table_1\n join db.customers(==customer_no)\n \"#).unwrap()" +expression: "resolve_lineage(r#\"\n from table_1\n join customers (==customer_no)\n \"#).unwrap()" --- columns: - All: @@ -13,11 +13,11 @@ inputs: - id: 119 name: table_1 table: - - db + - default_db - table_1 - id: 116 name: customers table: - - db + - default_db - customers diff --git a/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__test__frames_and_names-3.snap b/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__test__frames_and_names-3.snap index b4f56806cf0e..aacec8fd904f 100644 --- a/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__test__frames_and_names-3.snap +++ b/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__test__frames_and_names-3.snap @@ -1,34 +1,34 @@ --- source: prqlc/prqlc/src/semantic/resolver/mod.rs -expression: "resolve_lineage(r#\"\n from db.employees\n select {e = this}\n join db.salaries(==emp_no)\n group {e.emp_no, e.gender} (\n aggregate {\n emp_salary = average salaries.salary\n }\n )\n \"#).unwrap()" +expression: "resolve_lineage(r#\"\n from e = employees\n join salaries (==emp_no)\n group {e.emp_no, e.gender} (\n aggregate {\n emp_salary = average salaries.salary\n }\n )\n \"#).unwrap()" --- columns: - Single: name: - e - emp_no - target_id: 137 + target_id: 129 target_name: ~ - Single: name: - e - gender - target_id: 138 + target_id: 130 target_name: ~ - Single: name: - emp_salary - target_id: 156 + target_id: 148 target_name: ~ inputs: - - id: 125 + - id: 122 name: e table: - - db + - default_db - employees - id: 119 name: salaries table: - - db + - default_db - salaries diff --git a/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__test__frames_and_names.snap b/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__test__frames_and_names.snap index e56f256d361d..675179623679 100644 --- a/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__test__frames_and_names.snap +++ b/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__test__frames_and_names.snap @@ -1,6 +1,6 @@ --- source: prqlc/prqlc/src/semantic/resolver/mod.rs -expression: "resolve_lineage(r#\"\n from db.orders\n select {customer_no, gross, tax, gross - tax}\n take 20\n \"#).unwrap()" +expression: "resolve_lineage(r#\"\n from orders\n select {customer_no, gross, tax, gross - tax}\n take 20\n \"#).unwrap()" --- columns: - Single: @@ -29,6 +29,6 @@ inputs: - id: 121 name: orders table: - - db + - default_db - orders diff --git a/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__test__functions_pipeline-2.snap b/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__test__functions_pipeline-2.snap index a4a2435a6848..211b04a491b1 100644 --- a/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__test__functions_pipeline-2.snap +++ b/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__test__functions_pipeline-2.snap @@ -1,6 +1,6 @@ --- source: prqlc/prqlc/src/semantic/resolver/mod.rs -expression: "resolve_derive(r#\"\n let plus_one = x -> x + 1\n let plus = x y -> x + y\n\n from db.a\n derive {b = (sum foo | plus_one | plus 2)}\n \"#).unwrap()" +expression: "resolve_derive(r#\"\n let plus_one = x -> x + 1\n let plus = x y -> x + y\n\n from a\n derive {b = (sum foo | plus_one | plus 2)}\n \"#).unwrap()" --- - RqOperator: name: std.add @@ -36,14 +36,14 @@ expression: "resolve_derive(r#\"\n let plus_one = x -> x + 1\n - - ~ - kind: Primitive: Int - span: "0:4052-4055" + span: "0:4123-4126" name: ~ - - ~ - kind: Primitive: Float - span: "0:4059-4064" + span: "0:4130-4135" name: ~ - span: "0:4052-4064" + span: "0:4123-4135" name: ~ - Literal: Integer: 1 @@ -103,4 +103,3 @@ expression: "resolve_derive(r#\"\n let plus_one = x -> x + 1\n name: ~ span: "0:893-926" name: ~ - diff --git a/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__test__functions_pipeline.snap b/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__test__functions_pipeline.snap index 79229a47473d..e5b50d4f0007 100644 --- a/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__test__functions_pipeline.snap +++ b/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__test__functions_pipeline.snap @@ -1,6 +1,6 @@ --- source: prqlc/prqlc/src/semantic/resolver/mod.rs -expression: "resolve_derive(r#\"\n from db.a\n derive one = (foo | sum)\n \"#).unwrap()" +expression: "resolve_derive(r#\"\n from a\n derive one = (foo | sum)\n \"#).unwrap()" --- - RqOperator: name: std.sum @@ -24,13 +24,12 @@ expression: "resolve_derive(r#\"\n from db.a\n derive one - - ~ - kind: Primitive: Int - span: "0:4052-4055" + span: "0:4123-4126" name: ~ - - ~ - kind: Primitive: Float - span: "0:4059-4064" + span: "0:4130-4135" name: ~ - span: "0:4052-4064" + span: "0:4123-4135" name: ~ - diff --git a/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__transforms__tests__aggregate_positional_arg-2.snap b/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__transforms__tests__aggregate_positional_arg-2.snap index d34a0a105a80..dc8ed16c5a1e 100644 --- a/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__transforms__tests__aggregate_positional_arg-2.snap +++ b/prqlc/prqlc/src/semantic/resolver/snapshots/prqlc__semantic__resolver__transforms__tests__aggregate_positional_arg-2.snap @@ -5,7 +5,7 @@ expression: expr TransformCall: input: Ident: - - db + - default_db - c_invoice ty: kind: @@ -29,7 +29,7 @@ TransformCall: - id: 118 name: c_invoice table: - - db + - default_db - c_invoice kind: Aggregate: @@ -56,14 +56,14 @@ TransformCall: - - ~ - kind: Primitive: Float - span: "0:4117-4122" + span: "0:4188-4193" name: ~ - - ~ - kind: Singleton: "Null" - span: "0:4126-4130" + span: "0:4197-4201" name: ~ - span: "0:4117-4130" + span: "0:4188-4201" name: ~ ty: kind: @@ -75,14 +75,14 @@ TransformCall: - - ~ - kind: Primitive: Float - span: "0:4117-4122" + span: "0:4188-4193" name: ~ - - ~ - kind: Singleton: "Null" - span: "0:4126-4130" + span: "0:4197-4201" name: ~ - span: "0:4117-4130" + span: "0:4188-4201" name: ~ span: ~ name: ~ @@ -149,7 +149,7 @@ TransformCall: name: ~ span: "0:2042-2053" name: tuple - span: "0:2981-2996" + span: "0:3013-3028" name: ~ ty: kind: @@ -212,7 +212,7 @@ TransformCall: name: ~ span: "0:2042-2053" name: tuple - span: "0:2981-2996" + span: "0:3013-3028" name: ~ span: ~ name: ~ @@ -279,7 +279,7 @@ ty: name: ~ span: "0:2042-2053" name: tuple - span: "0:2981-2996" + span: "0:3013-3028" name: ~ - Single: - ~ @@ -288,14 +288,14 @@ ty: - - ~ - kind: Primitive: Float - span: "0:4117-4122" + span: "0:4188-4193" name: ~ - - ~ - kind: Singleton: "Null" - span: "0:4126-4130" + span: "0:4197-4201" name: ~ - span: "0:4117-4130" + span: "0:4188-4201" name: ~ span: ~ name: ~ @@ -317,6 +317,5 @@ lineage: - id: 118 name: c_invoice table: - - db + - default_db - c_invoice - diff --git a/prqlc/prqlc/src/semantic/resolver/transforms.rs b/prqlc/prqlc/src/semantic/resolver/transforms.rs index 66606b10c118..e35ea4fc3c3f 100644 --- a/prqlc/prqlc/src/semantic/resolver/transforms.rs +++ b/prqlc/prqlc/src/semantic/resolver/transforms.rs @@ -451,7 +451,7 @@ impl Resolver<'_> { return Err(Error::new(Reason::Unexpected { found: format!("assign to `{alias}`"), }) - .push_hint(format!("move assign into the tuple: `{{{alias} = ...}}`")) + .push_hint(format!("move assign into the tuple: `[{alias} = ...]`")) .with_span(expr.span)); } @@ -1079,7 +1079,7 @@ mod tests { // distinct query #292 assert_yaml_snapshot!(parse_resolve_and_lower(" - from db.c_invoice + from c_invoice select invoice_no group invoice_no ( take 1 @@ -1132,7 +1132,7 @@ mod tests { // oops, two arguments #339 let result = parse_resolve_and_lower( " - from db.c_invoice + from c_invoice aggregate average amount ", ); @@ -1141,7 +1141,7 @@ mod tests { // oops, two arguments let result = parse_resolve_and_lower( " - from db.c_invoice + from c_invoice group issued_at (aggregate average amount) ", ); @@ -1150,7 +1150,7 @@ mod tests { // correct function call let ctx = crate::semantic::test::parse_and_resolve( " - from db.c_invoice + from c_invoice group issued_at ( aggregate (average amount) ) @@ -1166,7 +1166,7 @@ mod tests { #[test] fn test_transform_sort() { assert_yaml_snapshot!(parse_resolve_and_lower(" - from db.invoices + from invoices sort {issued_at, -amount, +num_of_articles} sort issued_at sort (-issued_at) diff --git a/prqlc/prqlc/src/semantic/std.prql b/prqlc/prqlc/src/semantic/std.prql index 33629efefed2..a728af97f538 100644 --- a/prqlc/prqlc/src/semantic/std.prql +++ b/prqlc/prqlc/src/semantic/std.prql @@ -69,8 +69,8 @@ type transform = func relation -> relation ## Relational transforms let from = func - tbl - -> tbl + `default_db.source` + -> source let select = func columns @@ -103,7 +103,7 @@ let take = func -> internal take let join = func - with + `default_db.with` condition `noresolve.side`:inner tbl @@ -124,13 +124,13 @@ let window = func tbl -> internal window -let append = bottom top -> internal append -let intersect = bottom top -> ( +let append = `default_db.bottom` top -> internal append +let intersect = `default_db.bottom` top -> ( t = top join (b = bottom) (tuple_every (tuple_map _eq (tuple_zip t.* b.*))) select t.* ) -let remove = bottom top -> ( +let remove = `default_db.bottom` top -> ( t = top join side:left (b = bottom) (tuple_every (tuple_map _eq (tuple_zip t.* b.*))) filter (tuple_every (tuple_map _is_null b.*)) diff --git a/prqlc/prqlc/src/sql/gen_projection.rs b/prqlc/prqlc/src/sql/gen_projection.rs index 6b1ff59af5be..b8e9f7821a09 100644 --- a/prqlc/prqlc/src/sql/gen_projection.rs +++ b/prqlc/prqlc/src/sql/gen_projection.rs @@ -65,7 +65,7 @@ pub(super) fn translate_wildcards(ctx: &AnchorContext, cols: Vec) -> (Vec 3 "#; diff --git a/prqlc/prqlc/src/sql/mod.rs b/prqlc/prqlc/src/sql/mod.rs index 4dc0743d8550..47173ebdd961 100644 --- a/prqlc/prqlc/src/sql/mod.rs +++ b/prqlc/prqlc/src/sql/mod.rs @@ -165,7 +165,7 @@ mod test { #[test] fn test_end_with_new_line() { - let sql = compile("from db.a", &Options::default().no_signature()).unwrap(); + let sql = compile("from a", &Options::default().no_signature()).unwrap(); assert_eq!(sql, "SELECT\n *\nFROM\n a\n") } } diff --git a/prqlc/prqlc/src/sql/srq/mod.rs b/prqlc/prqlc/src/sql/srq/mod.rs index fce426bd4708..3d073a7575a3 100644 --- a/prqlc/prqlc/src/sql/srq/mod.rs +++ b/prqlc/prqlc/src/sql/srq/mod.rs @@ -43,7 +43,7 @@ mod test { fn test_ctes_of_pipeline() { // One aggregate, take at the end let prql: &str = r#" - from db.employees + from employees filter country == "USA" aggregate {sal = average salary} sort sal @@ -54,7 +54,7 @@ mod test { // One aggregate, but take at the top let prql: &str = r#" - from db.employees + from employees take 20 filter country == "USA" aggregate {sal = average salary} @@ -65,7 +65,7 @@ mod test { // A take, then two aggregates let prql: &str = r#" - from db.employees + from employees take 20 filter country == "USA" aggregate {sal = average salary} @@ -77,7 +77,7 @@ mod test { // A take, then a select let prql: &str = r###" - from db.employees + from employees take 20 select first_name "###; diff --git a/prqlc/prqlc/tests/integration/bad_error_messages.rs b/prqlc/prqlc/tests/integration/bad_error_messages.rs index 5099963b7053..8242ec446aae 100644 --- a/prqlc/prqlc/tests/integration/bad_error_messages.rs +++ b/prqlc/prqlc/tests/integration/bad_error_messages.rs @@ -4,7 +4,7 @@ //! experienced contributors who would like a quick issue to fix: //! - Find where the error is being raised now, generally just search for a part //! of the message. -//! - Add `dbg` macros to the code to see what's going on. +//! - Add `` macros to the code to see what's going on. //! - Write a better message / find a better place to raise a message. //! - Run `cargo insta test --accept`, and move the test out of this file into //! `test_error_messages.rs`. If it's only partially solved, add a TODO and @@ -21,7 +21,7 @@ use insta::assert_snapshot; #[test] fn test_bad_error_messages() { assert_snapshot!(compile(r###" - from db.film + from film group "###).unwrap_err(), @r###" Error: @@ -41,7 +41,7 @@ fn test_bad_error_messages() { assert_snapshot!(compile(r#" let f = country -> country == "Canada" - from db.employees + from employees filter f location "#).unwrap_err(), @r###" Error: @@ -56,20 +56,20 @@ fn test_bad_error_messages() { // Really complicated error message for something so fundamental assert_snapshot!(compile(r###" select tracks - from db.artists + from artists "###).unwrap_err(), @r###" Error: ╭─[:3:5] │ - 3 │ from db.artists - │ ───────┬─────── - │ ╰───────── expected a function, but found `db.artists` + 3 │ from artists + │ ──────┬───── + │ ╰─────── expected a function, but found `default_db.artists` ───╯ "###); // It's better if we can tell them to put in {} braces assert_snapshot!(compile(r###" - from db.artists + from artists sort -name "###).unwrap_err(), @r###" Error: expected a pipeline that resolves to a table, but found `internal std.sub` @@ -80,7 +80,7 @@ fn test_bad_error_messages() { #[test] fn empty_interpolations() { assert_snapshot!(compile(r#" - from db.x + from x select f"{}" "#).unwrap_err(), @r###" Error: @@ -97,7 +97,7 @@ fn empty_interpolations() { fn select_with_extra_fstr() { // Should complain in the same way as `select lower "mooo"` assert_snapshot!(compile(r#" - from db.foo + from foo select lower f"{x}/{y}" "#).unwrap_err(), @r###" Error: @@ -117,7 +117,7 @@ fn misplaced_type_error() { // (preferably in addition to the error that is currently generated) assert_snapshot!(compile(r###" let foo = 123 - from db.t + from t select (true && foo) "###).unwrap_err(), @r###" Error: @@ -133,7 +133,7 @@ fn misplaced_type_error() { #[test] fn invalid_lineage_in_transform() { assert_snapshot!(compile(r###" - from db.tbl + from tbl group id ( sort -val ) @@ -146,7 +146,7 @@ fn invalid_lineage_in_transform() { #[test] fn test_hint_missing_args() { assert_snapshot!(compile(r###" - from db.film + from film select {film_id, lag film_id} "###).unwrap_err(), @r###" Error: @@ -180,9 +180,9 @@ fn test_relation_literal_contains_literals() { fn nested_groups() { // Nested `group` gives a very abstract & internally-focused error message assert_snapshot!(compile(r###" - from db.invoices + from invoices select {inv = this} - join item = db.invoice_items (==invoice_id) + join item = invoice_items (==invoice_id) group { inv.billing_city } ( @@ -196,7 +196,7 @@ fn nested_groups() { Error: ╭─[:2:5] │ - 2 │ ╭─▶ from db.invoices + 2 │ ╭─▶ from invoices ┆ ┆ 13 │ ├─▶ ) │ │ diff --git a/prqlc/prqlc/tests/integration/cli.rs b/prqlc/prqlc/tests/integration/cli.rs index 64ccbbb30815..f2174ffdf511 100644 --- a/prqlc/prqlc/tests/integration/cli.rs +++ b/prqlc/prqlc/tests/integration/cli.rs @@ -67,7 +67,7 @@ fn get_targets() { fn compile() { assert_cmd_snapshot!(prqlc_command() .args(["compile", "--hide-signature-comment"]) - .pass_stdin("from db.tracks"), @r###" + .pass_stdin("from tracks"), @r###" success: true exit_code: 0 ----- stdout ----- @@ -135,7 +135,7 @@ fn long_query() { .args(["compile", "--hide-signature-comment"]) .pass_stdin(r#" let long_query = ( - from db.employees + from employees filter gross_cost > 0 group {title} ( aggregate { @@ -155,7 +155,7 @@ let long_query = ( filter ct > 200 take 20 ) -long_query +from long_query "#), @r###" success: true exit_code: 0 @@ -314,11 +314,11 @@ fn compile_project() { #[test] fn format() { // stdin - assert_cmd_snapshot!(prqlc_command().args(["fmt"]).pass_stdin("from db.tracks | take 20"), @r###" + assert_cmd_snapshot!(prqlc_command().args(["fmt"]).pass_stdin("from tracks | take 20"), @r###" success: true exit_code: 0 ----- stdout ----- - from db.tracks + from tracks take 20 ----- stderr ----- @@ -352,15 +352,15 @@ fn format() { fn debug() { assert_cmd_snapshot!(prqlc_command() .args(["debug", "resolve"]) - .pass_stdin("from db.tracks")); + .pass_stdin("from tracks")); assert_cmd_snapshot!(prqlc_command() .args(["debug", "expand-pl"]) - .pass_stdin("from db.tracks"), @r###" + .pass_stdin("from tracks"), @r###" success: true exit_code: 0 ----- stdout ----- - let main = from db.tracks + let main = from tracks ----- stderr ----- "###); @@ -381,7 +381,7 @@ fn debug() { #[test] fn preprocess() { - assert_cmd_snapshot!(prqlc_command().args(["sql:preprocess"]).pass_stdin("from db.tracks | take 20"), @r###" + assert_cmd_snapshot!(prqlc_command().args(["sql:preprocess"]).pass_stdin("from tracks | take 20"), @r###" success: true exit_code: 0 ----- stdout ----- diff --git a/prqlc/prqlc/tests/integration/dbs/README.md b/prqlc/prqlc/tests/integration/dbs/README.md index 13dc8eb9d5cb..30b0e025eb8d 100644 --- a/prqlc/prqlc/tests/integration/dbs/README.md +++ b/prqlc/prqlc/tests/integration/dbs/README.md @@ -68,13 +68,13 @@ use `sort` for test queries to to guarantee the order of rows across DBs. For example, instead of the following query: ```elm -from db.albums +from albums ``` Use a query including `sort`: ```elm -from db.albums +from albums sort album_id ``` diff --git a/prqlc/prqlc/tests/integration/error_messages.rs b/prqlc/prqlc/tests/integration/error_messages.rs index 210efccf414d..259529018d53 100644 --- a/prqlc/prqlc/tests/integration/error_messages.rs +++ b/prqlc/prqlc/tests/integration/error_messages.rs @@ -10,7 +10,7 @@ fn test_errors() { assert_snapshot!(compile(r###" let addadd = a b -> a + b - from db.x + from x derive y = (addadd 4 5 6) "###).unwrap_err(), @r###" @@ -24,20 +24,20 @@ fn test_errors() { "###); assert_snapshot!(compile(r###" - from db.a select b + from a select b "###).unwrap_err(), @r###" Error: ╭─[:2:5] │ - 2 │ from db.a select b - │ ─────────┬──────── - │ ╰────────── Too many arguments to function `from` + 2 │ from a select b + │ ───────┬─────── + │ ╰───────── Too many arguments to function `from` ───╯ "###); assert_snapshot!(compile(r###" - from db.x + from x select a select b "###).unwrap_err(), @@ -54,7 +54,7 @@ fn test_errors() { "###); assert_snapshot!(compile(r###" - from db.employees + from employees take 1.8 "###).unwrap_err(), @r###" @@ -105,7 +105,7 @@ fn test_errors() { #[test] fn array_instead_of_tuple() { assert_snapshot!(compile(r###" - from db.employees + from employees select {e = this} select [e.first_name, e.last_name] "###).unwrap_err(), @r###" @@ -125,8 +125,8 @@ fn test_union_all_sqlite() { assert_snapshot!(compile(r###" prql target:sql.sqlite - from db.film - remove db.film2 + from film + remove film2 "###).unwrap_err(), @r###" Error: The dialect SQLiteDialect does not support EXCEPT ALL ↳ Hint: providing more column information will allow the query to be translated to an anti-join. @@ -137,7 +137,7 @@ fn test_union_all_sqlite() { fn test_regex_dialect() { assert_snapshot!(compile(r###" prql target:sql.mssql - from db.foo + from foo filter bar ~= 'love' "###).unwrap_err(), @r###" Error: @@ -153,7 +153,7 @@ fn test_regex_dialect() { #[test] fn test_bad_function_type() { assert_snapshot!(compile(r###" - from db.tracks + from tracks group foo (take) "###, ) @@ -176,7 +176,7 @@ fn test_bad_function_type() { // See https://github.com/PRQL/prql/issues/3127#issuecomment-1849032396 fn test_basic_type_checking() { assert_snapshot!(compile(r#" - from db.foo + from foo select (a && b) + c "#) .unwrap_err(), @r###" @@ -196,7 +196,7 @@ fn test_basic_type_checking() { fn test_type_error_placement() { assert_snapshot!(compile(r###" let foo = x -> (x | as integer) - from db.t + from t select (true && (foo y)) "###).unwrap_err(), @r###" Error: @@ -212,7 +212,7 @@ fn test_type_error_placement() { #[test] fn test_ambiguous() { assert_snapshot!(compile(r#" - from db.a + from a derive date = x select date "#) @@ -234,9 +234,9 @@ fn test_ambiguous() { #[test] fn test_ambiguous_join() { assert_snapshot!(compile(r#" - from db.a + from a select x - join (db.b | select {x}) true + join (from b | select {x}) true select x "#) .unwrap_err(), @r###" @@ -257,8 +257,8 @@ fn test_ambiguous_join() { #[test] fn test_ambiguous_inference() { assert_snapshot!(compile(r#" - from db.a - join db.b(==b_id) + from a + join b(==b_id) select x "#) .unwrap_err(), @r###" @@ -296,7 +296,7 @@ fn date_to_text_not_supported_dialect() { assert_snapshot!(compile(r#" prql target:sql.bigquery - [{d = @2021-01-01}] + from [{d = @2021-01-01}] derive { d_str = d | date.to_text "%Y/%m/%d" }"#).unwrap_err(), @r###" @@ -313,7 +313,7 @@ fn date_to_text_not_supported_dialect() { #[test] fn date_to_text_with_column_format() { assert_snapshot!(compile(r#" - from db.dates_to_display + from dates_to_display select {my_date, my_format} select {std.date.to_text my_date my_format} "#).unwrap_err(), @r###" @@ -332,7 +332,7 @@ fn date_to_text_unsupported_chrono_item() { assert_snapshot!(compile(r#" prql target:sql.duckdb - [{d = @2021-01-01}] + from [{d = @2021-01-01}] derive { d_str = d | date.to_text "%_j" }"#).unwrap_err(), @r###" @@ -349,7 +349,7 @@ fn date_to_text_unsupported_chrono_item() { #[test] fn available_columns() { assert_snapshot!(compile(r#" - from db.invoices + from invoices select foo select bar "#).unwrap_err(), @r###" diff --git a/prqlc/prqlc/tests/integration/queries/aggregation.prql b/prqlc/prqlc/tests/integration/queries/aggregation.prql index 19254a6b70a5..fc79a79ad77a 100644 --- a/prqlc/prqlc/tests/integration/queries/aggregation.prql +++ b/prqlc/prqlc/tests/integration/queries/aggregation.prql @@ -2,7 +2,7 @@ # mysql:skip # clickhouse:skip # glaredb:skip (the string_agg function is not supported) -from db.tracks +from tracks filter genre_id == 100 derive empty_name = name == '' aggregate {sum track_id, concat_array name, all empty_name, any empty_name} diff --git a/prqlc/prqlc/tests/integration/queries/arithmetic.prql b/prqlc/prqlc/tests/integration/queries/arithmetic.prql index e227aa0040dc..32e2bb8331b7 100644 --- a/prqlc/prqlc/tests/integration/queries/arithmetic.prql +++ b/prqlc/prqlc/tests/integration/queries/arithmetic.prql @@ -1,5 +1,5 @@ # mssql:test -[ +from [ { id = 1, x_int = 13, x_float = 13.0, k_int = 5, k_float = 5.0 }, { id = 2, x_int = -13, x_float = -13.0, k_int = 5, k_float = 5.0 }, { id = 3, x_int = 13, x_float = 13.0, k_int = -5, k_float = -5.0 }, diff --git a/prqlc/prqlc/tests/integration/queries/cast.prql b/prqlc/prqlc/tests/integration/queries/cast.prql index 606ba8c05777..d1737027a894 100644 --- a/prqlc/prqlc/tests/integration/queries/cast.prql +++ b/prqlc/prqlc/tests/integration/queries/cast.prql @@ -1,5 +1,5 @@ # mssql:test -from db.tracks +from tracks sort {-bytes} select { name, diff --git a/prqlc/prqlc/tests/integration/queries/constants_only.prql b/prqlc/prqlc/tests/integration/queries/constants_only.prql index f34a358dd05a..23269d39a6ce 100644 --- a/prqlc/prqlc/tests/integration/queries/constants_only.prql +++ b/prqlc/prqlc/tests/integration/queries/constants_only.prql @@ -1,4 +1,4 @@ -from db.genres +from genres take 10 filter true take 20 diff --git a/prqlc/prqlc/tests/integration/queries/date_to_text.prql b/prqlc/prqlc/tests/integration/queries/date_to_text.prql index 6e6d6d36dda4..010cf5f2f33b 100644 --- a/prqlc/prqlc/tests/integration/queries/date_to_text.prql +++ b/prqlc/prqlc/tests/integration/queries/date_to_text.prql @@ -2,7 +2,7 @@ # glaredb:skip # sqlite:skip # mssql:test -from db.invoices +from invoices take 20 select { d1 = (invoice_date | date.to_text "%Y/%m/%d"), diff --git a/prqlc/prqlc/tests/integration/queries/distinct.prql b/prqlc/prqlc/tests/integration/queries/distinct.prql index 444f380cb5a3..60bf46e60031 100644 --- a/prqlc/prqlc/tests/integration/queries/distinct.prql +++ b/prqlc/prqlc/tests/integration/queries/distinct.prql @@ -1,5 +1,5 @@ # mssql:test -from db.tracks +from tracks select {album_id, genre_id} group tracks.* (take 1) sort tracks.* diff --git a/prqlc/prqlc/tests/integration/queries/distinct_on.prql b/prqlc/prqlc/tests/integration/queries/distinct_on.prql index 8bbb9707e358..434e0b5ff08d 100644 --- a/prqlc/prqlc/tests/integration/queries/distinct_on.prql +++ b/prqlc/prqlc/tests/integration/queries/distinct_on.prql @@ -1,5 +1,5 @@ # mssql:test -from db.tracks +from tracks select {genre_id, media_type_id, album_id} group {genre_id, media_type_id} (sort {-album_id} | take 1) sort {-genre_id, media_type_id} diff --git a/prqlc/prqlc/tests/integration/queries/genre_counts.prql b/prqlc/prqlc/tests/integration/queries/genre_counts.prql index 5e72cc825b05..2fd5ba833c6d 100644 --- a/prqlc/prqlc/tests/integration/queries/genre_counts.prql +++ b/prqlc/prqlc/tests/integration/queries/genre_counts.prql @@ -1,10 +1,10 @@ # clickhouse:skip (ClickHouse prefers aliases to column names https://github.com/PRQL/prql/issues/2827) # mssql:test let genre_count = ( - from db.genres + from genres aggregate {a = count name} ) -genre_count +from genre_count filter a > 0 select a = -a diff --git a/prqlc/prqlc/tests/integration/queries/group_all.prql b/prqlc/prqlc/tests/integration/queries/group_all.prql index 0f3f0eda7660..e15c736f69d0 100644 --- a/prqlc/prqlc/tests/integration/queries/group_all.prql +++ b/prqlc/prqlc/tests/integration/queries/group_all.prql @@ -1,7 +1,6 @@ # mssql:test -from db.albums -select {a = this} +from a=albums take 10 -join db.tracks (==album_id) +join tracks (==album_id) group {a.album_id, a.title} (aggregate price = (sum tracks.unit_price | math.round 2)) sort album_id diff --git a/prqlc/prqlc/tests/integration/queries/group_sort.prql b/prqlc/prqlc/tests/integration/queries/group_sort.prql index 1f85849711e8..dbac5697d4d9 100644 --- a/prqlc/prqlc/tests/integration/queries/group_sort.prql +++ b/prqlc/prqlc/tests/integration/queries/group_sort.prql @@ -1,5 +1,5 @@ # mssql:test -from db.tracks +from tracks derive d = album_id + 1 group d ( aggregate { diff --git a/prqlc/prqlc/tests/integration/queries/group_sort_limit_take.prql b/prqlc/prqlc/tests/integration/queries/group_sort_limit_take.prql index a110065d5fd7..3a4197eaef6b 100644 --- a/prqlc/prqlc/tests/integration/queries/group_sort_limit_take.prql +++ b/prqlc/prqlc/tests/integration/queries/group_sort_limit_take.prql @@ -1,11 +1,11 @@ # Compute the 3 longest songs for each genre and sort by genre # mssql:test -from db.tracks +from tracks select {genre_id,milliseconds} group {genre_id} ( sort {-milliseconds} take 3 ) -join db.genres (==genre_id) +join genres (==genre_id) select {name, milliseconds} sort {+name,-milliseconds} diff --git a/prqlc/prqlc/tests/integration/queries/invoice_totals.prql b/prqlc/prqlc/tests/integration/queries/invoice_totals.prql index 78725ee941ea..c162be1c2a79 100644 --- a/prqlc/prqlc/tests/integration/queries/invoice_totals.prql +++ b/prqlc/prqlc/tests/integration/queries/invoice_totals.prql @@ -1,9 +1,8 @@ # clickhouse:skip (clickhouse doesn't have lag function) #! Calculate a number of metrics about the sales of tracks in each city. -from db.invoices -select {i = this} -join (db.invoice_items | select {ii = this}) (==invoice_id) +from i=invoices +join ii=invoice_items (==invoice_id) derive { city = i.billing_city, street = i.billing_address, diff --git a/prqlc/prqlc/tests/integration/queries/loop_01.prql b/prqlc/prqlc/tests/integration/queries/loop_01.prql index 31c7fed20a1e..c9e3b7156552 100644 --- a/prqlc/prqlc/tests/integration/queries/loop_01.prql +++ b/prqlc/prqlc/tests/integration/queries/loop_01.prql @@ -1,6 +1,6 @@ # clickhouse:skip (DB::Exception: Syntax error) # glaredb:skip (DataFusion does not support recursive CTEs https://github.com/apache/arrow-datafusion/issues/462) -[{n = 1}] +from [{n = 1}] select n = n - 2 loop (filter n < 4 | select n = n + 1) select n = n * 2 diff --git a/prqlc/prqlc/tests/integration/queries/math_module.prql b/prqlc/prqlc/tests/integration/queries/math_module.prql index 2bc9d8ebb6f6..ded806f1215b 100644 --- a/prqlc/prqlc/tests/integration/queries/math_module.prql +++ b/prqlc/prqlc/tests/integration/queries/math_module.prql @@ -1,6 +1,6 @@ # mssql:test # sqlite:skip (see https://github.com/rusqlite/rusqlite/issues/1211) -from db.invoices +from invoices take 5 select { total_original = total | math.round 2, diff --git a/prqlc/prqlc/tests/integration/queries/pipelines.prql b/prqlc/prqlc/tests/integration/queries/pipelines.prql index 20e80ce6cf2b..4a20c30f16ef 100644 --- a/prqlc/prqlc/tests/integration/queries/pipelines.prql +++ b/prqlc/prqlc/tests/integration/queries/pipelines.prql @@ -2,7 +2,7 @@ # installed # https://stackoverflow.com/questions/24037982/how-to-use-regexp-in-sqlite) -from db.tracks +from tracks filter (name ~= "Love") filter ((milliseconds / 1000 / 60) | in 3..4) diff --git a/prqlc/prqlc/tests/integration/queries/read_csv.prql b/prqlc/prqlc/tests/integration/queries/read_csv.prql index 46011c3a990d..a805272b3948 100644 --- a/prqlc/prqlc/tests/integration/queries/read_csv.prql +++ b/prqlc/prqlc/tests/integration/queries/read_csv.prql @@ -1,5 +1,5 @@ # sqlite:skip # postgres:skip # mysql:skip -read_csv "data_file_root/media_types.csv" +from (read_csv "data_file_root/media_types.csv") sort media_type_id diff --git a/prqlc/prqlc/tests/integration/queries/set_ops_remove.prql b/prqlc/prqlc/tests/integration/queries/set_ops_remove.prql index cf07d14f20ab..724741dc17e6 100644 --- a/prqlc/prqlc/tests/integration/queries/set_ops_remove.prql +++ b/prqlc/prqlc/tests/integration/queries/set_ops_remove.prql @@ -1,5 +1,5 @@ # mssql:test -let distinct = rel -> (rel | group this (take 1)) +let distinct = rel -> (from t = _param.rel | group {t.*} (take 1)) from_text format:json '{ "columns": ["a"], "data": [[1], [2], [2], [3]] }' distinct diff --git a/prqlc/prqlc/tests/integration/queries/sort.prql b/prqlc/prqlc/tests/integration/queries/sort.prql index 9655ac418558..3168ea3da913 100644 --- a/prqlc/prqlc/tests/integration/queries/sort.prql +++ b/prqlc/prqlc/tests/integration/queries/sort.prql @@ -1,10 +1,9 @@ # mssql:test -from db.employees -select {e = this} +from e=employees filter first_name != "Mitchell" sort {first_name, last_name} # joining may use HashMerge, which can undo ORDER BY -join (db.employees | select {manager = this}) side:left (e.reports_to == manager.employee_id) +join manager=employees side:left (e.reports_to == manager.employee_id) select {e.first_name, e.last_name, manager.first_name} diff --git a/prqlc/prqlc/tests/integration/queries/switch.prql b/prqlc/prqlc/tests/integration/queries/switch.prql index 3b1b48f82975..e017d1a2de8d 100644 --- a/prqlc/prqlc/tests/integration/queries/switch.prql +++ b/prqlc/prqlc/tests/integration/queries/switch.prql @@ -1,6 +1,6 @@ # glaredb:skip (May be a bag of String type conversion for Postgres Client) # mssql:test -from db.tracks +from tracks sort milliseconds select display = case [ composer != null => composer, diff --git a/prqlc/prqlc/tests/integration/queries/take.prql b/prqlc/prqlc/tests/integration/queries/take.prql index 1fa8048b7819..086b631f5b8b 100644 --- a/prqlc/prqlc/tests/integration/queries/take.prql +++ b/prqlc/prqlc/tests/integration/queries/take.prql @@ -1,4 +1,4 @@ # mssql:test -from db.tracks +from tracks sort {+track_id} take 3..5 diff --git a/prqlc/prqlc/tests/integration/queries/text_module.prql b/prqlc/prqlc/tests/integration/queries/text_module.prql index 0a51585bbd91..2b634fe4dcc0 100644 --- a/prqlc/prqlc/tests/integration/queries/text_module.prql +++ b/prqlc/prqlc/tests/integration/queries/text_module.prql @@ -1,5 +1,5 @@ # mssql:test -from db.albums +from albums select { title, title_and_spaces = f" {title} ", diff --git a/prqlc/prqlc/tests/integration/queries/window.prql b/prqlc/prqlc/tests/integration/queries/window.prql index ad653de751c1..23cf8bea66d0 100644 --- a/prqlc/prqlc/tests/integration/queries/window.prql +++ b/prqlc/prqlc/tests/integration/queries/window.prql @@ -2,7 +2,7 @@ # duckdb:skip problems with DISTINCT ON (duckdb internal error: [with INPUT_TYPE = int; RESULT_TYPE = unsigned char]: Assertion `min_val <= input' failed.) # clickhouse:skip problems with DISTINCT ON # postgres:skip problems with DISTINCT ON -from db.tracks +from tracks group genre_id ( sort milliseconds derive { diff --git a/prqlc/prqlc/tests/integration/resolving.rs b/prqlc/prqlc/tests/integration/resolving.rs index 364551d653dc..be1a36291534 100644 --- a/prqlc/prqlc/tests/integration/resolving.rs +++ b/prqlc/prqlc/tests/integration/resolving.rs @@ -11,7 +11,7 @@ fn resolve(prql_source: &str) -> Result { // resolved PL, restricted back into AST let mut root_module = prqlc::semantic::ast_expand::restrict_module(root_module.module); - drop_module_defs(&mut root_module.stmts, &["std", "db"]); + drop_module_defs(&mut root_module.stmts, &["std", "default_db"]); prqlc::pl_to_prql(&root_module) } @@ -27,7 +27,7 @@ fn drop_module_defs(stmts: &mut Vec, to_drop: &[&str]) { #[test] fn resolve_basic_01() { assert_snapshot!(resolve(r#" - from db.x + from x select {a, b} "#).unwrap(), @r###" let main <[{a = ?, b = ?}]> = `(Select ...)` diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__cli__debug.snap b/prqlc/prqlc/tests/integration/snapshots/integration__cli__debug.snap index 1107fae7c66d..0ca376af5a8b 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__cli__debug.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__cli__debug.snap @@ -8,10 +8,10 @@ info: - resolve env: CLICOLOR_FORCE: "" + NO_COLOR: "1" RUST_BACKTRACE: "" RUST_LOG: "" - NO_COLOR: "1" - stdin: from db.tracks + stdin: from tracks --- success: true exit_code: 0 @@ -33,7 +33,7 @@ Module { order: 0, annotations: [], }, - "db": Decl { + "default_db": Decl { declared_at: None, kind: Module( Module { @@ -143,11 +143,11 @@ Module { ), expr: RelationVar( Expr { - span: 1:0-14, + span: 1:0-11, kind: Ident( Ident { path: [ - "db", + "default_db", ], name: "tracks", }, @@ -167,7 +167,7 @@ Module { name: "tracks", table: Ident { path: [ - "db", + "default_db", ], name: "tracks", }, @@ -199,11 +199,11 @@ Module { Info: ╭─[:1:1] │ - 1 │ from db.tracks -  │ ───────┬────── -  │ ╰──────── [db.tracks] table + 1 │ from tracks +  │ ─────┬───── +  │ ╰─────── [default_db.tracks] table ───╯ -module db { +module default_db { let _infer = internal infer let _infer_module = internal infer @@ -211,7 +211,7 @@ module db { let tracks <[{*..}]> = internal local_table } -let main <[{*..}]> = db.tracks +let main <[{*..}]> = default_db.tracks ----- stderr ----- diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__group_all.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__group_all.snap index f55b52eadab2..bb67d987675f 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__group_all.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__group_all.snap @@ -1,6 +1,6 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# mssql:test\nfrom.albums\nselect {a = this}\ntake 10\njoin from.tracks (==album_id)\ngroup {a.album_id, a.title} (aggregate price = (sum tracks.unit_price | math.round 2))\nsort album_id\n" +expression: "# mssql:test\nfrom a=albums\ntake 10\njoin tracks (==album_id)\ngroup {a.album_id, a.title} (aggregate price = (sum tracks.unit_price | math.round 2))\nsort album_id\n" input_file: prqlc/prqlc/tests/integration/queries/group_all.prql --- WITH table_0 AS ( @@ -8,7 +8,7 @@ WITH table_0 AS ( album_id, title FROM - albums + albums AS a LIMIT 10 ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__invoice_totals.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__invoice_totals.snap index 5fdece83c147..70b8af0cd077 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__invoice_totals.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__invoice_totals.snap @@ -1,26 +1,20 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# clickhouse:skip (clickhouse doesn't have lag function)\n\n#! Calculate a number of metrics about the sales of tracks in each city.\nfrom.invoices\nselect {i = this}\njoin (from.invoice_items | select {ii = this}) (==invoice_id)\nderive {\n city = i.billing_city,\n street = i.billing_address,\n}\ngroup {city, street} (\n derive total = ii.unit_price * ii.quantity\n aggregate {\n num_orders = count_distinct i.invoice_id,\n num_tracks = sum ii.quantity,\n total_price = sum total,\n }\n)\ngroup {city} (\n sort street\n window expanding:true (\n derive {running_total_num_tracks = sum num_tracks}\n )\n)\nsort {city, street}\nderive {num_tracks_last_week = lag 7 num_tracks}\nselect {\n city,\n street,\n num_orders,\n num_tracks,\n running_total_num_tracks,\n num_tracks_last_week\n}\ntake 20\n" +expression: "# clickhouse:skip (clickhouse doesn't have lag function)\n\n#! Calculate a number of metrics about the sales of tracks in each city.\nfrom i=invoices\njoin ii=invoice_items (==invoice_id)\nderive {\n city = i.billing_city,\n street = i.billing_address,\n}\ngroup {city, street} (\n derive total = ii.unit_price * ii.quantity\n aggregate {\n num_orders = count_distinct i.invoice_id,\n num_tracks = sum ii.quantity,\n total_price = sum total,\n }\n)\ngroup {city} (\n sort street\n window expanding:true (\n derive {running_total_num_tracks = sum num_tracks}\n )\n)\nsort {city, street}\nderive {num_tracks_last_week = lag 7 num_tracks}\nselect {\n city,\n street,\n num_orders,\n num_tracks,\n running_total_num_tracks,\n num_tracks_last_week\n}\ntake 20\n" input_file: prqlc/prqlc/tests/integration/queries/invoice_totals.prql --- WITH table_0 AS ( SELECT - * + i.billing_city AS city, + i.billing_address AS street, + COUNT(DISTINCT i.invoice_id) AS num_orders, + COALESCE(SUM(ii.quantity), 0) AS num_tracks FROM - invoice_items -), -table_1 AS ( - SELECT - invoices.billing_city AS city, - invoices.billing_address AS street, - COUNT(DISTINCT invoices.invoice_id) AS num_orders, - COALESCE(SUM(table_0.quantity), 0) AS num_tracks - FROM - invoices - JOIN table_0 ON invoices.invoice_id = table_0.invoice_id + invoices AS i + JOIN invoice_items AS ii ON i.invoice_id = ii.invoice_id GROUP BY - invoices.billing_city, - invoices.billing_address + i.billing_city, + i.billing_address ) SELECT city, @@ -38,7 +32,7 @@ SELECT street ) AS num_tracks_last_week FROM - table_1 + table_0 ORDER BY city, street diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__sort.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__sort.snap index 312d91008313..f67706ca3964 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__sort.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__sort.snap @@ -1,32 +1,26 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# mssql:test\nfrom.employees\nselect {e = this}\nfilter first_name != \"Mitchell\"\nsort {first_name, last_name}\n\n# joining may use HashMerge, which can undo ORDER BY\njoin (from.employees | select {manager = this}) side:left (e.reports_to == manager.employee_id)\n\nselect {e.first_name, e.last_name, manager.first_name}\n" +expression: "# mssql:test\nfrom e=employees\nfilter first_name != \"Mitchell\"\nsort {first_name, last_name}\n\n# joining may use HashMerge, which can undo ORDER BY\njoin manager=employees side:left (e.reports_to == manager.employee_id)\n\nselect {e.first_name, e.last_name, manager.first_name}\n" input_file: prqlc/prqlc/tests/integration/queries/sort.prql --- -WITH table_1 AS ( +WITH table_0 AS ( SELECT first_name, last_name, reports_to FROM - employees + employees AS e WHERE first_name <> 'Mitchell' -), -table_0 AS ( - SELECT - * - FROM - employees ) SELECT - table_1.first_name, - table_1.last_name, - table_0.first_name + table_0.first_name, + table_0.last_name, + manager.first_name FROM - table_1 - LEFT JOIN table_0 ON table_1.reports_to = table_0.employee_id + table_0 + LEFT JOIN employees AS manager ON table_0.reports_to = manager.employee_id ORDER BY - table_1.first_name, - table_1.last_name + table_0.first_name, + table_0.last_name diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__aggregation.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__aggregation.snap index 7798c9bbccbf..d50e2057a843 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__aggregation.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__aggregation.snap @@ -1,9 +1,9 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# mssql:skip\n# mysql:skip\n# clickhouse:skip\n# glaredb:skip (the string_agg function is not supported)\nfrom db.tracks\nfilter genre_id == 100\nderive empty_name = name == ''\naggregate {sum track_id, concat_array name, all empty_name, any empty_name}\n" +expression: "# mssql:skip\n# mysql:skip\n# clickhouse:skip\n# glaredb:skip (the string_agg function is not supported)\nfrom tracks\nfilter genre_id == 100\nderive empty_name = name == ''\naggregate {sum track_id, concat_array name, all empty_name, any empty_name}\n" input_file: prqlc/prqlc/tests/integration/queries/aggregation.prql --- -from db.tracks +from tracks filter genre_id == 100 derive empty_name = name == "" aggregate { diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__arithmetic.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__arithmetic.snap index 732257fa1bd8..6be21fc08eff 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__arithmetic.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__arithmetic.snap @@ -1,9 +1,9 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# mssql:test\n[\n { id = 1, x_int = 13, x_float = 13.0, k_int = 5, k_float = 5.0 },\n { id = 2, x_int = -13, x_float = -13.0, k_int = 5, k_float = 5.0 },\n { id = 3, x_int = 13, x_float = 13.0, k_int = -5, k_float = -5.0 },\n { id = 4, x_int = -13, x_float = -13.0, k_int = -5, k_float = -5.0 },\n]\nselect {\n id,\n\n x_int / k_int,\n x_int / k_float,\n x_float / k_int,\n x_float / k_float,\n\n q_ii = x_int // k_int,\n q_if = x_int // k_float,\n q_fi = x_float // k_int,\n q_ff = x_float // k_float,\n\n r_ii = x_int % k_int,\n r_if = x_int % k_float,\n r_fi = x_float % k_int,\n r_ff = x_float % k_float,\n\n (q_ii * k_int + r_ii | math.round 0),\n (q_if * k_float + r_if | math.round 0),\n (q_fi * k_int + r_fi | math.round 0),\n (q_ff * k_float + r_ff | math.round 0),\n}\nsort id\n" +expression: "# mssql:test\nfrom [\n { id = 1, x_int = 13, x_float = 13.0, k_int = 5, k_float = 5.0 },\n { id = 2, x_int = -13, x_float = -13.0, k_int = 5, k_float = 5.0 },\n { id = 3, x_int = 13, x_float = 13.0, k_int = -5, k_float = -5.0 },\n { id = 4, x_int = -13, x_float = -13.0, k_int = -5, k_float = -5.0 },\n]\nselect {\n id,\n\n x_int / k_int,\n x_int / k_float,\n x_float / k_int,\n x_float / k_float,\n\n q_ii = x_int // k_int,\n q_if = x_int // k_float,\n q_fi = x_float // k_int,\n q_ff = x_float // k_float,\n\n r_ii = x_int % k_int,\n r_if = x_int % k_float,\n r_fi = x_float % k_int,\n r_ff = x_float % k_float,\n\n (q_ii * k_int + r_ii | math.round 0),\n (q_if * k_float + r_if | math.round 0),\n (q_fi * k_int + r_fi | math.round 0),\n (q_ff * k_float + r_ff | math.round 0),\n}\nsort id\n" input_file: prqlc/prqlc/tests/integration/queries/arithmetic.prql --- -[ +from [ { id = 1, x_int = 13, diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__cast.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__cast.snap index 665a2c4eaca1..1f5eed50818b 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__cast.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__cast.snap @@ -1,9 +1,9 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# mssql:test\nfrom db.tracks\nsort {-bytes}\nselect {\n name,\n bin = ((album_id | as REAL) * 99)\n}\ntake 20\n" +expression: "# mssql:test\nfrom tracks\nsort {-bytes}\nselect {\n name,\n bin = ((album_id | as REAL) * 99)\n}\ntake 20\n" input_file: prqlc/prqlc/tests/integration/queries/cast.prql --- -from db.tracks +from tracks sort {-bytes} select {name, bin = (album_id | as REAL) * 99} take 20 diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__constants_only.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__constants_only.snap index 71c474b6d2d0..79dccd1dc029 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__constants_only.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__constants_only.snap @@ -1,9 +1,9 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "from db.genres\ntake 10\nfilter true\ntake 20\nfilter true\nselect d = 10\n" +expression: "from genres\ntake 10\nfilter true\ntake 20\nfilter true\nselect d = 10\n" input_file: prqlc/prqlc/tests/integration/queries/constants_only.prql --- -from db.genres +from genres take 10 filter true take 20 diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__date_to_text.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__date_to_text.snap index 8865d5fa139c..e558891fddce 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__date_to_text.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__date_to_text.snap @@ -1,9 +1,9 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# generic:skip\n# glaredb:skip\n# sqlite:skip\n# mssql:test\nfrom db.invoices\ntake 20\nselect {\n d1 = (invoice_date | date.to_text \"%Y/%m/%d\"),\n d2 = (invoice_date | date.to_text \"%F\"),\n d3 = (invoice_date | date.to_text \"%D\"),\n d4 = (invoice_date | date.to_text \"%H:%M:%S.%f\"),\n d5 = (invoice_date | date.to_text \"%r\"),\n d6 = (invoice_date | date.to_text \"%A %B %-d %Y\"),\n d7 = (invoice_date | date.to_text \"%a, %-d %b %Y at %I:%M:%S %p\"),\n d8 = (invoice_date | date.to_text \"%+\"),\n d9 = (invoice_date | date.to_text \"%-d/%-m/%y\"),\n d10 = (invoice_date | date.to_text \"%-Hh %Mmin\"),\n d11 = (invoice_date | date.to_text \"%M'%S\\\"\"),\n d12 = (invoice_date | date.to_text \"100%% in %d days\"),\n}\n" +expression: "# generic:skip\n# glaredb:skip\n# sqlite:skip\n# mssql:test\nfrom invoices\ntake 20\nselect {\n d1 = (invoice_date | date.to_text \"%Y/%m/%d\"),\n d2 = (invoice_date | date.to_text \"%F\"),\n d3 = (invoice_date | date.to_text \"%D\"),\n d4 = (invoice_date | date.to_text \"%H:%M:%S.%f\"),\n d5 = (invoice_date | date.to_text \"%r\"),\n d6 = (invoice_date | date.to_text \"%A %B %-d %Y\"),\n d7 = (invoice_date | date.to_text \"%a, %-d %b %Y at %I:%M:%S %p\"),\n d8 = (invoice_date | date.to_text \"%+\"),\n d9 = (invoice_date | date.to_text \"%-d/%-m/%y\"),\n d10 = (invoice_date | date.to_text \"%-Hh %Mmin\"),\n d11 = (invoice_date | date.to_text \"%M'%S\\\"\"),\n d12 = (invoice_date | date.to_text \"100%% in %d days\"),\n}\n" input_file: prqlc/prqlc/tests/integration/queries/date_to_text.prql --- -from db.invoices +from invoices take 20 select { d1 = (invoice_date | date.to_text "%Y/%m/%d"), diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__distinct.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__distinct.snap index 65e2bae38ceb..7999ae327cbb 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__distinct.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__distinct.snap @@ -1,9 +1,9 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# mssql:test\nfrom db.tracks\nselect {album_id, genre_id}\ngroup tracks.* (take 1)\nsort tracks.*\n" +expression: "# mssql:test\nfrom tracks\nselect {album_id, genre_id}\ngroup tracks.* (take 1)\nsort tracks.*\n" input_file: prqlc/prqlc/tests/integration/queries/distinct.prql --- -from db.tracks +from tracks select {album_id, genre_id} group tracks.* (take 1) sort tracks.* diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__distinct_on.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__distinct_on.snap index 6961b76cf60d..470cff0620da 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__distinct_on.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__distinct_on.snap @@ -1,9 +1,9 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# mssql:test\nfrom db.tracks\nselect {genre_id, media_type_id, album_id}\ngroup {genre_id, media_type_id} (sort {-album_id} | take 1)\nsort {-genre_id, media_type_id}\n" +expression: "# mssql:test\nfrom tracks\nselect {genre_id, media_type_id, album_id}\ngroup {genre_id, media_type_id} (sort {-album_id} | take 1)\nsort {-genre_id, media_type_id}\n" input_file: prqlc/prqlc/tests/integration/queries/distinct_on.prql --- -from db.tracks +from tracks select {genre_id, media_type_id, album_id} group {genre_id, media_type_id} ( sort {-album_id} diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__genre_counts.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__genre_counts.snap index 7475ed148767..fb73ace8a03a 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__genre_counts.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__genre_counts.snap @@ -1,14 +1,14 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# clickhouse:skip (ClickHouse prefers aliases to column names https://github.com/PRQL/prql/issues/2827)\n# mssql:test\nlet genre_count = (\n from db.genres\n aggregate {a = count name}\n)\n\ngenre_count\nfilter a > 0\nselect a = -a\n" +expression: "# clickhouse:skip (ClickHouse prefers aliases to column names https://github.com/PRQL/prql/issues/2827)\n# mssql:test\nlet genre_count = (\n from genres\n aggregate {a = count name}\n)\n\nfrom genre_count\nfilter a > 0\nselect a = -a\n" input_file: prqlc/prqlc/tests/integration/queries/genre_counts.prql --- let genre_count = ( - from db.genres + from genres aggregate {a = count name} ) -genre_count +from genre_count filter a > 0 select a = -a diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__group_all.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__group_all.snap index ae4980264b7b..933d8efda9a2 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__group_all.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__group_all.snap @@ -1,12 +1,11 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# mssql:test\nfrom db.albums\nselect {a = this}\ntake 10\njoin db.tracks (==album_id)\ngroup {a.album_id, a.title} (aggregate price = (sum tracks.unit_price | math.round 2))\nsort album_id\n" +expression: "# mssql:test\nfrom a=albums\ntake 10\njoin tracks (==album_id)\ngroup {a.album_id, a.title} (aggregate price = (sum tracks.unit_price | math.round 2))\nsort album_id\n" input_file: prqlc/prqlc/tests/integration/queries/group_all.prql --- -from db.albums -select {a = this} +from a = albums take 10 -join db.tracks (==album_id) +join tracks (==album_id) group {a.album_id, a.title} (aggregate price = ( sum tracks.unit_price math.round 2 diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__group_sort.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__group_sort.snap index 55cdfe6a4a07..f1013da6e4a5 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__group_sort.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__group_sort.snap @@ -1,9 +1,9 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# mssql:test\nfrom db.tracks\nderive d = album_id + 1\ngroup d (\n aggregate {\n n1 = (track_id | sum),\n }\n)\nsort d\ntake 10\nselect { d1 = d, n1 }\n" +expression: "# mssql:test\nfrom tracks\nderive d = album_id + 1\ngroup d (\n aggregate {\n n1 = (track_id | sum),\n }\n)\nsort d\ntake 10\nselect { d1 = d, n1 }\n" input_file: prqlc/prqlc/tests/integration/queries/group_sort.prql --- -from db.tracks +from tracks derive d = album_id + 1 group d (aggregate {n1 = (track_id | sum)}) sort d diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__group_sort_limit_take.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__group_sort_limit_take.snap index ad2edd987b51..a1b6d593281e 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__group_sort_limit_take.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__group_sort_limit_take.snap @@ -1,12 +1,12 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# Compute the 3 longest songs for each genre and sort by genre\n# mssql:test\nfrom db.tracks\nselect {genre_id,milliseconds}\ngroup {genre_id} (\n sort {-milliseconds}\n take 3\n)\njoin db.genres (==genre_id)\nselect {name, milliseconds}\nsort {+name,-milliseconds}\n" +expression: "# Compute the 3 longest songs for each genre and sort by genre\n# mssql:test\nfrom tracks\nselect {genre_id,milliseconds}\ngroup {genre_id} (\n sort {-milliseconds}\n take 3\n)\njoin genres (==genre_id)\nselect {name, milliseconds}\nsort {+name,-milliseconds}\n" input_file: prqlc/prqlc/tests/integration/queries/group_sort_limit_take.prql --- -from db.tracks +from tracks select {genre_id, milliseconds} group {genre_id} (sort {-milliseconds} | take 3) -join db.genres (==genre_id) +join genres (==genre_id) select {name, milliseconds} sort {+name, -milliseconds} diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__invoice_totals.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__invoice_totals.snap index efa65a4a9282..7793d0d10f29 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__invoice_totals.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__invoice_totals.snap @@ -1,13 +1,10 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# clickhouse:skip (clickhouse doesn't have lag function)\n\n#! Calculate a number of metrics about the sales of tracks in each city.\nfrom db.invoices\nselect {i = this}\njoin (db.invoice_items | select {ii = this}) (==invoice_id)\nderive {\n city = i.billing_city,\n street = i.billing_address,\n}\ngroup {city, street} (\n derive total = ii.unit_price * ii.quantity\n aggregate {\n num_orders = count_distinct i.invoice_id,\n num_tracks = sum ii.quantity,\n total_price = sum total,\n }\n)\ngroup {city} (\n sort street\n window expanding:true (\n derive {running_total_num_tracks = sum num_tracks}\n )\n)\nsort {city, street}\nderive {num_tracks_last_week = lag 7 num_tracks}\nselect {\n city,\n street,\n num_orders,\n num_tracks,\n running_total_num_tracks,\n num_tracks_last_week\n}\ntake 20\n" +expression: "# clickhouse:skip (clickhouse doesn't have lag function)\n\n#! Calculate a number of metrics about the sales of tracks in each city.\nfrom i=invoices\njoin ii=invoice_items (==invoice_id)\nderive {\n city = i.billing_city,\n street = i.billing_address,\n}\ngroup {city, street} (\n derive total = ii.unit_price * ii.quantity\n aggregate {\n num_orders = count_distinct i.invoice_id,\n num_tracks = sum ii.quantity,\n total_price = sum total,\n }\n)\ngroup {city} (\n sort street\n window expanding:true (\n derive {running_total_num_tracks = sum num_tracks}\n )\n)\nsort {city, street}\nderive {num_tracks_last_week = lag 7 num_tracks}\nselect {\n city,\n street,\n num_orders,\n num_tracks,\n running_total_num_tracks,\n num_tracks_last_week\n}\ntake 20\n" input_file: prqlc/prqlc/tests/integration/queries/invoice_totals.prql --- -from db.invoices -select {i = this} -join (db.invoice_items | select {ii = this}) ( - ==invoice_id -) +from i = invoices +join ii = invoice_items (==invoice_id) derive { city = i.billing_city, street = i.billing_address, diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__loop_01.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__loop_01.snap index a8c8ab38d022..8e9776e19d6d 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__loop_01.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__loop_01.snap @@ -1,9 +1,9 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# clickhouse:skip (DB::Exception: Syntax error)\n# glaredb:skip (DataFusion does not support recursive CTEs https://github.com/apache/arrow-datafusion/issues/462)\n[{n = 1}]\nselect n = n - 2\nloop (filter n < 4 | select n = n + 1)\nselect n = n * 2\nsort n\n" +expression: "# clickhouse:skip (DB::Exception: Syntax error)\n# glaredb:skip (DataFusion does not support recursive CTEs https://github.com/apache/arrow-datafusion/issues/462)\nfrom [{n = 1}]\nselect n = n - 2\nloop (filter n < 4 | select n = n + 1)\nselect n = n * 2\nsort n\n" input_file: prqlc/prqlc/tests/integration/queries/loop_01.prql --- -[{n = 1}] +from [{n = 1}] select n = n - 2 loop (filter n < 4 | select n = n + 1) select n = n * 2 diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__math_module.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__math_module.snap index e8df7d88ae5f..930981b0aa6f 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__math_module.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__math_module.snap @@ -1,9 +1,9 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# mssql:test\n# sqlite:skip (see https://github.com/rusqlite/rusqlite/issues/1211)\nfrom db.invoices\ntake 5\nselect {\n total_original = total | math.round 2,\n total_x = math.pi - total | math.round 2 | math.abs,\n total_floor = math.floor total,\n total_ceil = math.ceil total,\n total_log10 = math.log10 total | math.round 3,\n total_log2 = math.log 2 total | math.round 3,\n total_sqrt = math.sqrt total | math.round 3,\n total_ln = math.ln total | math.exp | math.round 2,\n total_cos = math.cos total | math.acos | math.round 2,\n total_sin = math.sin total | math.asin | math.round 2,\n total_tan = math.tan total | math.atan | math.round 2,\n total_deg = total | math.degrees | math.radians | math.round 2,\n total_square = total | math.pow 2| math.round 2,\n}\n" +expression: "# mssql:test\n# sqlite:skip (see https://github.com/rusqlite/rusqlite/issues/1211)\nfrom invoices\ntake 5\nselect {\n total_original = total | math.round 2,\n total_x = math.pi - total | math.round 2 | math.abs,\n total_floor = math.floor total,\n total_ceil = math.ceil total,\n total_log10 = math.log10 total | math.round 3,\n total_log2 = math.log 2 total | math.round 3,\n total_sqrt = math.sqrt total | math.round 3,\n total_ln = math.ln total | math.exp | math.round 2,\n total_cos = math.cos total | math.acos | math.round 2,\n total_sin = math.sin total | math.asin | math.round 2,\n total_tan = math.tan total | math.atan | math.round 2,\n total_deg = total | math.degrees | math.radians | math.round 2,\n total_square = total | math.pow 2| math.round 2,\n}\n" input_file: prqlc/prqlc/tests/integration/queries/math_module.prql --- -from db.invoices +from invoices take 5 select { total_original = (total | math.round 2), diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__pipelines.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__pipelines.snap index be5aad927242..9dc0af848c12 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__pipelines.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__pipelines.snap @@ -1,9 +1,9 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# sqlite:skip (Only works on Sqlite implementations which have the extension\n# installed\n# https://stackoverflow.com/questions/24037982/how-to-use-regexp-in-sqlite)\n\nfrom db.tracks\n\nfilter (name ~= \"Love\")\nfilter ((milliseconds / 1000 / 60) | in 3..4)\nsort track_id\ntake 1..15\nselect {name, composer}\n" +expression: "# sqlite:skip (Only works on Sqlite implementations which have the extension\n# installed\n# https://stackoverflow.com/questions/24037982/how-to-use-regexp-in-sqlite)\n\nfrom tracks\n\nfilter (name ~= \"Love\")\nfilter ((milliseconds / 1000 / 60) | in 3..4)\nsort track_id\ntake 1..15\nselect {name, composer}\n" input_file: prqlc/prqlc/tests/integration/queries/pipelines.prql --- -from db.tracks +from tracks filter name ~= "Love" filter ((milliseconds / 1000) / 60 | in 3..4) sort track_id diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__read_csv.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__read_csv.snap index 2d610153ce85..de85a44f9d05 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__read_csv.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__read_csv.snap @@ -1,8 +1,8 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# sqlite:skip\n# postgres:skip\n# mysql:skip\nread_csv \"data_file_root/media_types.csv\"\nsort media_type_id\n" +expression: "# sqlite:skip\n# postgres:skip\n# mysql:skip\nfrom (read_csv \"data_file_root/media_types.csv\")\nsort media_type_id\n" input_file: prqlc/prqlc/tests/integration/queries/read_csv.prql --- -read_csv "data_file_root/media_types.csv" +from (read_csv "data_file_root/media_types.csv") sort media_type_id diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__set_ops_remove.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__set_ops_remove.snap index 387843ecf78d..47efa07907e9 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__set_ops_remove.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__set_ops_remove.snap @@ -1,9 +1,12 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# mssql:test\nlet distinct = rel -> (rel | group this (take 1))\n\nfrom_text format:json '{ \"columns\": [\"a\"], \"data\": [[1], [2], [2], [3]] }'\ndistinct\nremove (from_text format:json '{ \"columns\": [\"a\"], \"data\": [[1], [2]] }')\nsort a\n" +expression: "# mssql:test\nlet distinct = rel -> (from t = _param.rel | group {t.*} (take 1))\n\nfrom_text format:json '{ \"columns\": [\"a\"], \"data\": [[1], [2], [2], [3]] }'\ndistinct\nremove (from_text format:json '{ \"columns\": [\"a\"], \"data\": [[1], [2]] }')\nsort a\n" input_file: prqlc/prqlc/tests/integration/queries/set_ops_remove.prql --- -let distinct = func rel -> (rel | group this (take 1)) +let distinct = func rel -> ( + from t = _param.rel + group {t.*} (take 1) +) from_text format:json '{ "columns": ["a"], "data": [[1], [2], [2], [3]] }' distinct diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__sort.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__sort.snap index 19ecacf9c9c3..8bb61f7b6f0b 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__sort.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__sort.snap @@ -1,12 +1,11 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# mssql:test\nfrom db.employees\nselect {e = this}\nfilter first_name != \"Mitchell\"\nsort {first_name, last_name}\n\n# joining may use HashMerge, which can undo ORDER BY\njoin (db.employees | select {manager = this}) side:left (e.reports_to == manager.employee_id)\n\nselect {e.first_name, e.last_name, manager.first_name}\n" +expression: "# mssql:test\nfrom e=employees\nfilter first_name != \"Mitchell\"\nsort {first_name, last_name}\n\n# joining may use HashMerge, which can undo ORDER BY\njoin manager=employees side:left (e.reports_to == manager.employee_id)\n\nselect {e.first_name, e.last_name, manager.first_name}\n" input_file: prqlc/prqlc/tests/integration/queries/sort.prql --- -from db.employees -select {e = this} +from e = employees filter first_name != "Mitchell" sort {first_name, last_name} -join side:left (db.employees | select {manager = this}) e.reports_to == manager.employee_id +join side:left manager = employees e.reports_to == manager.employee_id select {e.first_name, e.last_name, manager.first_name} diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__switch.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__switch.snap index 2a8e8c803b88..83daf4d25cc8 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__switch.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__switch.snap @@ -1,9 +1,9 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# glaredb:skip (May be a bag of String type conversion for Postgres Client)\n# mssql:test\nfrom db.tracks\nsort milliseconds\nselect display = case [\n composer != null => composer,\n genre_id < 17 => 'no composer',\n true => f'unknown composer'\n]\ntake 10\n" +expression: "# glaredb:skip (May be a bag of String type conversion for Postgres Client)\n# mssql:test\nfrom tracks\nsort milliseconds\nselect display = case [\n composer != null => composer,\n genre_id < 17 => 'no composer',\n true => f'unknown composer'\n]\ntake 10\n" input_file: prqlc/prqlc/tests/integration/queries/switch.prql --- -from db.tracks +from tracks sort milliseconds select display = case [ composer != null => composer, diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__take.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__take.snap index 444cb45fcd71..5a20efe62d05 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__take.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__take.snap @@ -1,9 +1,9 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# mssql:test\nfrom db.tracks\nsort {+track_id}\ntake 3..5\n" +expression: "# mssql:test\nfrom tracks\nsort {+track_id}\ntake 3..5\n" input_file: prqlc/prqlc/tests/integration/queries/take.prql --- -from db.tracks +from tracks sort {+track_id} take 3..5 diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__text_module.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__text_module.snap index c57963a264b0..8bb2b5b6d43f 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__text_module.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__text_module.snap @@ -1,9 +1,9 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# mssql:test\nfrom db.albums\nselect {\n title,\n title_and_spaces = f\" {title} \",\n low = title | text.lower,\n up = title | text.upper,\n ltrimmed = title | text.ltrim,\n rtrimmed = title | text.rtrim,\n trimmed = title | text.trim,\n len = title | text.length,\n subs = title | text.extract 2 5,\n replace = title | text.replace \"al\" \"PIKA\",\n}\nsort {title}\nfilter (title | text.starts_with \"Black\") || (title | text.contains \"Sabbath\") || (title | text.ends_with \"os\")\n" +expression: "# mssql:test\nfrom albums\nselect {\n title,\n title_and_spaces = f\" {title} \",\n low = title | text.lower,\n up = title | text.upper,\n ltrimmed = title | text.ltrim,\n rtrimmed = title | text.rtrim,\n trimmed = title | text.trim,\n len = title | text.length,\n subs = title | text.extract 2 5,\n replace = title | text.replace \"al\" \"PIKA\",\n}\nsort {title}\nfilter (title | text.starts_with \"Black\") || (title | text.contains \"Sabbath\") || (title | text.ends_with \"os\")\n" input_file: prqlc/prqlc/tests/integration/queries/text_module.prql --- -from db.albums +from albums select { title, title_and_spaces = f" {title} ", diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__window.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__window.snap index 810cc89cbbf5..b062e5c5bbda 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__window.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__window.snap @@ -1,9 +1,9 @@ --- source: prqlc/prqlc/tests/integration/queries.rs -expression: "# mssql:skip Conversion(\"cannot interpret I64(Some(1)) as an i32 value\")', connection.rs:200:34\n# duckdb:skip problems with DISTINCT ON (duckdb internal error: [with INPUT_TYPE = int; RESULT_TYPE = unsigned char]: Assertion `min_val <= input' failed.)\n# clickhouse:skip problems with DISTINCT ON\n# postgres:skip problems with DISTINCT ON\nfrom db.tracks\ngroup genre_id (\n sort milliseconds\n derive {\n num = row_number this,\n total = count this,\n last_val = last track_id,\n }\n take 10\n)\nsort {genre_id, milliseconds}\nselect {track_id, genre_id, num, total, last_val}\nfilter genre_id >= 22\n" +expression: "# mssql:skip Conversion(\"cannot interpret I64(Some(1)) as an i32 value\")', connection.rs:200:34\n# duckdb:skip problems with DISTINCT ON (duckdb internal error: [with INPUT_TYPE = int; RESULT_TYPE = unsigned char]: Assertion `min_val <= input' failed.)\n# clickhouse:skip problems with DISTINCT ON\n# postgres:skip problems with DISTINCT ON\nfrom tracks\ngroup genre_id (\n sort milliseconds\n derive {\n num = row_number this,\n total = count this,\n last_val = last track_id,\n }\n take 10\n)\nsort {genre_id, milliseconds}\nselect {track_id, genre_id, num, total, last_val}\nfilter genre_id >= 22\n" input_file: prqlc/prqlc/tests/integration/queries/window.prql --- -from db.tracks +from tracks group genre_id ( sort milliseconds derive { diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__aggregation.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__aggregation.snap index 09305ac1eba2..f2418a549028 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__aggregation.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__aggregation.snap @@ -13,35 +13,33 @@ TokenVec ( 44..101: Comment(" glaredb:skip (the string_agg function is not supported)"), 101..102: NewLine, 102..106: Ident("from"), - 107..109: Ident("db"), - 109..110: Control('.'), - 110..116: Ident("tracks"), - 116..117: NewLine, - 117..123: Ident("filter"), - 124..132: Ident("genre_id"), - 133..135: Eq, - 136..139: Literal(Integer(100)), - 139..140: NewLine, - 140..146: Ident("derive"), - 147..157: Ident("empty_name"), - 158..159: Control('='), - 160..164: Ident("name"), - 165..167: Eq, - 168..170: Literal(String("")), - 170..171: NewLine, - 171..180: Ident("aggregate"), - 181..182: Control('{'), - 182..185: Ident("sum"), - 186..194: Ident("track_id"), - 194..195: Control(','), - 196..208: Ident("concat_array"), - 209..213: Ident("name"), - 213..214: Control(','), - 215..218: Ident("all"), - 219..229: Ident("empty_name"), - 229..230: Control(','), - 231..234: Ident("any"), - 235..245: Ident("empty_name"), - 245..246: Control('}'), - 246..247: NewLine, + 107..113: Ident("tracks"), + 113..114: NewLine, + 114..120: Ident("filter"), + 121..129: Ident("genre_id"), + 130..132: Eq, + 133..136: Literal(Integer(100)), + 136..137: NewLine, + 137..143: Ident("derive"), + 144..154: Ident("empty_name"), + 155..156: Control('='), + 157..161: Ident("name"), + 162..164: Eq, + 165..167: Literal(String("")), + 167..168: NewLine, + 168..177: Ident("aggregate"), + 178..179: Control('{'), + 179..182: Ident("sum"), + 183..191: Ident("track_id"), + 191..192: Control(','), + 193..205: Ident("concat_array"), + 206..210: Ident("name"), + 210..211: Control(','), + 212..215: Ident("all"), + 216..226: Ident("empty_name"), + 226..227: Control(','), + 228..231: Ident("any"), + 232..242: Ident("empty_name"), + 242..243: Control('}'), + 243..244: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__arithmetic.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__arithmetic.snap index 990870cdf69f..90d6c4cf6700 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__arithmetic.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__arithmetic.snap @@ -6,255 +6,256 @@ input_file: prqlc/prqlc/tests/integration/queries/arithmetic.prql TokenVec ( 0..12: Comment(" mssql:test"), 12..13: NewLine, - 13..14: Control('['), - 14..15: NewLine, - 19..20: Control('{'), - 21..23: Ident("id"), - 24..25: Control('='), - 26..27: Literal(Integer(1)), - 27..28: Control(','), - 29..34: Ident("x_int"), - 35..36: Control('='), - 38..40: Literal(Integer(13)), - 40..41: Control(','), - 42..49: Ident("x_float"), - 50..51: Control('='), - 53..57: Literal(Float(13.0)), - 57..58: Control(','), - 59..64: Ident("k_int"), - 65..66: Control('='), - 68..69: Literal(Integer(5)), - 69..70: Control(','), - 71..78: Ident("k_float"), - 79..80: Control('='), - 82..85: Literal(Float(5.0)), - 86..87: Control('}'), - 87..88: Control(','), - 88..89: NewLine, - 93..94: Control('{'), - 95..97: Ident("id"), - 98..99: Control('='), - 100..101: Literal(Integer(2)), - 101..102: Control(','), - 103..108: Ident("x_int"), - 109..110: Control('='), - 111..112: Control('-'), - 112..114: Literal(Integer(13)), - 114..115: Control(','), - 116..123: Ident("x_float"), - 124..125: Control('='), - 126..127: Control('-'), - 127..131: Literal(Float(13.0)), - 131..132: Control(','), - 133..138: Ident("k_int"), - 139..140: Control('='), - 142..143: Literal(Integer(5)), - 143..144: Control(','), - 145..152: Ident("k_float"), - 153..154: Control('='), - 156..159: Literal(Float(5.0)), - 160..161: Control('}'), - 161..162: Control(','), - 162..163: NewLine, - 167..168: Control('{'), - 169..171: Ident("id"), - 172..173: Control('='), - 174..175: Literal(Integer(3)), - 175..176: Control(','), - 177..182: Ident("x_int"), - 183..184: Control('='), - 186..188: Literal(Integer(13)), - 188..189: Control(','), - 190..197: Ident("x_float"), - 198..199: Control('='), - 201..205: Literal(Float(13.0)), - 205..206: Control(','), - 207..212: Ident("k_int"), - 213..214: Control('='), - 215..216: Control('-'), - 216..217: Literal(Integer(5)), - 217..218: Control(','), - 219..226: Ident("k_float"), - 227..228: Control('='), - 229..230: Control('-'), - 230..233: Literal(Float(5.0)), - 234..235: Control('}'), - 235..236: Control(','), - 236..237: NewLine, - 241..242: Control('{'), - 243..245: Ident("id"), - 246..247: Control('='), - 248..249: Literal(Integer(4)), - 249..250: Control(','), - 251..256: Ident("x_int"), - 257..258: Control('='), - 259..260: Control('-'), - 260..262: Literal(Integer(13)), - 262..263: Control(','), - 264..271: Ident("x_float"), - 272..273: Control('='), - 274..275: Control('-'), - 275..279: Literal(Float(13.0)), - 279..280: Control(','), - 281..286: Ident("k_int"), - 287..288: Control('='), - 289..290: Control('-'), - 290..291: Literal(Integer(5)), - 291..292: Control(','), - 293..300: Ident("k_float"), - 301..302: Control('='), - 303..304: Control('-'), - 304..307: Literal(Float(5.0)), - 308..309: Control('}'), - 309..310: Control(','), - 310..311: NewLine, - 311..312: Control(']'), - 312..313: NewLine, - 313..319: Ident("select"), - 320..321: Control('{'), - 321..322: NewLine, - 326..328: Ident("id"), - 328..329: Control(','), - 329..330: NewLine, - 330..331: NewLine, - 335..340: Ident("x_int"), - 341..342: Control('/'), - 343..348: Ident("k_int"), - 348..349: Control(','), - 349..350: NewLine, - 354..359: Ident("x_int"), - 360..361: Control('/'), - 362..369: Ident("k_float"), - 369..370: Control(','), - 370..371: NewLine, - 375..382: Ident("x_float"), - 383..384: Control('/'), - 385..390: Ident("k_int"), - 390..391: Control(','), - 391..392: NewLine, - 396..403: Ident("x_float"), - 404..405: Control('/'), - 406..413: Ident("k_float"), - 413..414: Control(','), - 414..415: NewLine, - 415..416: NewLine, - 420..424: Ident("q_ii"), - 425..426: Control('='), - 427..432: Ident("x_int"), - 433..435: DivInt, - 436..441: Ident("k_int"), - 441..442: Control(','), - 442..443: NewLine, - 447..451: Ident("q_if"), - 452..453: Control('='), - 454..459: Ident("x_int"), - 460..462: DivInt, - 463..470: Ident("k_float"), - 470..471: Control(','), - 471..472: NewLine, - 476..480: Ident("q_fi"), - 481..482: Control('='), - 483..490: Ident("x_float"), - 491..493: DivInt, - 494..499: Ident("k_int"), - 499..500: Control(','), - 500..501: NewLine, - 505..509: Ident("q_ff"), - 510..511: Control('='), - 512..519: Ident("x_float"), - 520..522: DivInt, - 523..530: Ident("k_float"), - 530..531: Control(','), - 531..532: NewLine, - 532..533: NewLine, - 537..541: Ident("r_ii"), - 542..543: Control('='), - 544..549: Ident("x_int"), - 550..551: Control('%'), - 552..557: Ident("k_int"), - 557..558: Control(','), - 558..559: NewLine, - 563..567: Ident("r_if"), - 568..569: Control('='), - 570..575: Ident("x_int"), - 576..577: Control('%'), - 578..585: Ident("k_float"), - 585..586: Control(','), - 586..587: NewLine, - 591..595: Ident("r_fi"), - 596..597: Control('='), - 598..605: Ident("x_float"), - 606..607: Control('%'), - 608..613: Ident("k_int"), - 613..614: Control(','), - 614..615: NewLine, - 619..623: Ident("r_ff"), - 624..625: Control('='), - 626..633: Ident("x_float"), - 634..635: Control('%'), - 636..643: Ident("k_float"), - 643..644: Control(','), - 644..645: NewLine, - 645..646: NewLine, - 650..651: Control('('), - 651..655: Ident("q_ii"), - 656..657: Control('*'), - 658..663: Ident("k_int"), - 664..665: Control('+'), - 666..670: Ident("r_ii"), - 671..672: Control('|'), - 673..677: Ident("math"), - 677..678: Control('.'), - 678..683: Ident("round"), - 684..685: Literal(Integer(0)), - 685..686: Control(')'), - 686..687: Control(','), - 687..688: NewLine, - 692..693: Control('('), - 693..697: Ident("q_if"), - 698..699: Control('*'), - 700..707: Ident("k_float"), - 708..709: Control('+'), - 710..714: Ident("r_if"), - 715..716: Control('|'), - 717..721: Ident("math"), - 721..722: Control('.'), - 722..727: Ident("round"), - 728..729: Literal(Integer(0)), - 729..730: Control(')'), - 730..731: Control(','), - 731..732: NewLine, - 736..737: Control('('), - 737..741: Ident("q_fi"), - 742..743: Control('*'), - 744..749: Ident("k_int"), - 750..751: Control('+'), - 752..756: Ident("r_fi"), - 757..758: Control('|'), - 759..763: Ident("math"), - 763..764: Control('.'), - 764..769: Ident("round"), - 770..771: Literal(Integer(0)), - 771..772: Control(')'), - 772..773: Control(','), - 773..774: NewLine, - 778..779: Control('('), - 779..783: Ident("q_ff"), - 784..785: Control('*'), - 786..793: Ident("k_float"), - 794..795: Control('+'), - 796..800: Ident("r_ff"), - 801..802: Control('|'), - 803..807: Ident("math"), - 807..808: Control('.'), - 808..813: Ident("round"), - 814..815: Literal(Integer(0)), - 815..816: Control(')'), - 816..817: Control(','), - 817..818: NewLine, - 818..819: Control('}'), - 819..820: NewLine, - 820..824: Ident("sort"), - 825..827: Ident("id"), - 827..828: NewLine, + 13..17: Ident("from"), + 18..19: Control('['), + 19..20: NewLine, + 24..25: Control('{'), + 26..28: Ident("id"), + 29..30: Control('='), + 31..32: Literal(Integer(1)), + 32..33: Control(','), + 34..39: Ident("x_int"), + 40..41: Control('='), + 43..45: Literal(Integer(13)), + 45..46: Control(','), + 47..54: Ident("x_float"), + 55..56: Control('='), + 58..62: Literal(Float(13.0)), + 62..63: Control(','), + 64..69: Ident("k_int"), + 70..71: Control('='), + 73..74: Literal(Integer(5)), + 74..75: Control(','), + 76..83: Ident("k_float"), + 84..85: Control('='), + 87..90: Literal(Float(5.0)), + 91..92: Control('}'), + 92..93: Control(','), + 93..94: NewLine, + 98..99: Control('{'), + 100..102: Ident("id"), + 103..104: Control('='), + 105..106: Literal(Integer(2)), + 106..107: Control(','), + 108..113: Ident("x_int"), + 114..115: Control('='), + 116..117: Control('-'), + 117..119: Literal(Integer(13)), + 119..120: Control(','), + 121..128: Ident("x_float"), + 129..130: Control('='), + 131..132: Control('-'), + 132..136: Literal(Float(13.0)), + 136..137: Control(','), + 138..143: Ident("k_int"), + 144..145: Control('='), + 147..148: Literal(Integer(5)), + 148..149: Control(','), + 150..157: Ident("k_float"), + 158..159: Control('='), + 161..164: Literal(Float(5.0)), + 165..166: Control('}'), + 166..167: Control(','), + 167..168: NewLine, + 172..173: Control('{'), + 174..176: Ident("id"), + 177..178: Control('='), + 179..180: Literal(Integer(3)), + 180..181: Control(','), + 182..187: Ident("x_int"), + 188..189: Control('='), + 191..193: Literal(Integer(13)), + 193..194: Control(','), + 195..202: Ident("x_float"), + 203..204: Control('='), + 206..210: Literal(Float(13.0)), + 210..211: Control(','), + 212..217: Ident("k_int"), + 218..219: Control('='), + 220..221: Control('-'), + 221..222: Literal(Integer(5)), + 222..223: Control(','), + 224..231: Ident("k_float"), + 232..233: Control('='), + 234..235: Control('-'), + 235..238: Literal(Float(5.0)), + 239..240: Control('}'), + 240..241: Control(','), + 241..242: NewLine, + 246..247: Control('{'), + 248..250: Ident("id"), + 251..252: Control('='), + 253..254: Literal(Integer(4)), + 254..255: Control(','), + 256..261: Ident("x_int"), + 262..263: Control('='), + 264..265: Control('-'), + 265..267: Literal(Integer(13)), + 267..268: Control(','), + 269..276: Ident("x_float"), + 277..278: Control('='), + 279..280: Control('-'), + 280..284: Literal(Float(13.0)), + 284..285: Control(','), + 286..291: Ident("k_int"), + 292..293: Control('='), + 294..295: Control('-'), + 295..296: Literal(Integer(5)), + 296..297: Control(','), + 298..305: Ident("k_float"), + 306..307: Control('='), + 308..309: Control('-'), + 309..312: Literal(Float(5.0)), + 313..314: Control('}'), + 314..315: Control(','), + 315..316: NewLine, + 316..317: Control(']'), + 317..318: NewLine, + 318..324: Ident("select"), + 325..326: Control('{'), + 326..327: NewLine, + 331..333: Ident("id"), + 333..334: Control(','), + 334..335: NewLine, + 335..336: NewLine, + 340..345: Ident("x_int"), + 346..347: Control('/'), + 348..353: Ident("k_int"), + 353..354: Control(','), + 354..355: NewLine, + 359..364: Ident("x_int"), + 365..366: Control('/'), + 367..374: Ident("k_float"), + 374..375: Control(','), + 375..376: NewLine, + 380..387: Ident("x_float"), + 388..389: Control('/'), + 390..395: Ident("k_int"), + 395..396: Control(','), + 396..397: NewLine, + 401..408: Ident("x_float"), + 409..410: Control('/'), + 411..418: Ident("k_float"), + 418..419: Control(','), + 419..420: NewLine, + 420..421: NewLine, + 425..429: Ident("q_ii"), + 430..431: Control('='), + 432..437: Ident("x_int"), + 438..440: DivInt, + 441..446: Ident("k_int"), + 446..447: Control(','), + 447..448: NewLine, + 452..456: Ident("q_if"), + 457..458: Control('='), + 459..464: Ident("x_int"), + 465..467: DivInt, + 468..475: Ident("k_float"), + 475..476: Control(','), + 476..477: NewLine, + 481..485: Ident("q_fi"), + 486..487: Control('='), + 488..495: Ident("x_float"), + 496..498: DivInt, + 499..504: Ident("k_int"), + 504..505: Control(','), + 505..506: NewLine, + 510..514: Ident("q_ff"), + 515..516: Control('='), + 517..524: Ident("x_float"), + 525..527: DivInt, + 528..535: Ident("k_float"), + 535..536: Control(','), + 536..537: NewLine, + 537..538: NewLine, + 542..546: Ident("r_ii"), + 547..548: Control('='), + 549..554: Ident("x_int"), + 555..556: Control('%'), + 557..562: Ident("k_int"), + 562..563: Control(','), + 563..564: NewLine, + 568..572: Ident("r_if"), + 573..574: Control('='), + 575..580: Ident("x_int"), + 581..582: Control('%'), + 583..590: Ident("k_float"), + 590..591: Control(','), + 591..592: NewLine, + 596..600: Ident("r_fi"), + 601..602: Control('='), + 603..610: Ident("x_float"), + 611..612: Control('%'), + 613..618: Ident("k_int"), + 618..619: Control(','), + 619..620: NewLine, + 624..628: Ident("r_ff"), + 629..630: Control('='), + 631..638: Ident("x_float"), + 639..640: Control('%'), + 641..648: Ident("k_float"), + 648..649: Control(','), + 649..650: NewLine, + 650..651: NewLine, + 655..656: Control('('), + 656..660: Ident("q_ii"), + 661..662: Control('*'), + 663..668: Ident("k_int"), + 669..670: Control('+'), + 671..675: Ident("r_ii"), + 676..677: Control('|'), + 678..682: Ident("math"), + 682..683: Control('.'), + 683..688: Ident("round"), + 689..690: Literal(Integer(0)), + 690..691: Control(')'), + 691..692: Control(','), + 692..693: NewLine, + 697..698: Control('('), + 698..702: Ident("q_if"), + 703..704: Control('*'), + 705..712: Ident("k_float"), + 713..714: Control('+'), + 715..719: Ident("r_if"), + 720..721: Control('|'), + 722..726: Ident("math"), + 726..727: Control('.'), + 727..732: Ident("round"), + 733..734: Literal(Integer(0)), + 734..735: Control(')'), + 735..736: Control(','), + 736..737: NewLine, + 741..742: Control('('), + 742..746: Ident("q_fi"), + 747..748: Control('*'), + 749..754: Ident("k_int"), + 755..756: Control('+'), + 757..761: Ident("r_fi"), + 762..763: Control('|'), + 764..768: Ident("math"), + 768..769: Control('.'), + 769..774: Ident("round"), + 775..776: Literal(Integer(0)), + 776..777: Control(')'), + 777..778: Control(','), + 778..779: NewLine, + 783..784: Control('('), + 784..788: Ident("q_ff"), + 789..790: Control('*'), + 791..798: Ident("k_float"), + 799..800: Control('+'), + 801..805: Ident("r_ff"), + 806..807: Control('|'), + 808..812: Ident("math"), + 812..813: Control('.'), + 813..818: Ident("round"), + 819..820: Literal(Integer(0)), + 820..821: Control(')'), + 821..822: Control(','), + 822..823: NewLine, + 823..824: Control('}'), + 824..825: NewLine, + 825..829: Ident("sort"), + 830..832: Ident("id"), + 832..833: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__cast.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__cast.snap index 76a82dc79d09..f3bba36634ce 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__cast.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__cast.snap @@ -7,38 +7,36 @@ TokenVec ( 0..12: Comment(" mssql:test"), 12..13: NewLine, 13..17: Ident("from"), - 18..20: Ident("db"), - 20..21: Control('.'), - 21..27: Ident("tracks"), - 27..28: NewLine, - 28..32: Ident("sort"), - 33..34: Control('{'), - 34..35: Control('-'), - 35..40: Ident("bytes"), - 40..41: Control('}'), - 41..42: NewLine, - 42..48: Ident("select"), - 49..50: Control('{'), - 50..51: NewLine, - 55..59: Ident("name"), - 59..60: Control(','), - 60..61: NewLine, - 65..68: Ident("bin"), - 69..70: Control('='), - 71..72: Control('('), - 72..73: Control('('), - 73..81: Ident("album_id"), - 82..83: Control('|'), - 84..86: Ident("as"), - 87..91: Ident("REAL"), - 91..92: Control(')'), - 93..94: Control('*'), - 95..97: Literal(Integer(99)), - 97..98: Control(')'), - 98..99: NewLine, - 99..100: Control('}'), - 100..101: NewLine, - 101..105: Ident("take"), - 106..108: Literal(Integer(20)), - 108..109: NewLine, + 18..24: Ident("tracks"), + 24..25: NewLine, + 25..29: Ident("sort"), + 30..31: Control('{'), + 31..32: Control('-'), + 32..37: Ident("bytes"), + 37..38: Control('}'), + 38..39: NewLine, + 39..45: Ident("select"), + 46..47: Control('{'), + 47..48: NewLine, + 52..56: Ident("name"), + 56..57: Control(','), + 57..58: NewLine, + 62..65: Ident("bin"), + 66..67: Control('='), + 68..69: Control('('), + 69..70: Control('('), + 70..78: Ident("album_id"), + 79..80: Control('|'), + 81..83: Ident("as"), + 84..88: Ident("REAL"), + 88..89: Control(')'), + 90..91: Control('*'), + 92..94: Literal(Integer(99)), + 94..95: Control(')'), + 95..96: NewLine, + 96..97: Control('}'), + 97..98: NewLine, + 98..102: Ident("take"), + 103..105: Literal(Integer(20)), + 105..106: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__constants_only.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__constants_only.snap index b087e62e4b58..4237fc01c911 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__constants_only.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__constants_only.snap @@ -5,25 +5,23 @@ input_file: prqlc/prqlc/tests/integration/queries/constants_only.prql --- TokenVec ( 0..4: Ident("from"), - 5..7: Ident("db"), - 7..8: Control('.'), - 8..14: Ident("genres"), - 14..15: NewLine, - 15..19: Ident("take"), - 20..22: Literal(Integer(10)), - 22..23: NewLine, - 23..29: Ident("filter"), - 30..34: Literal(Boolean(true)), - 34..35: NewLine, - 35..39: Ident("take"), - 40..42: Literal(Integer(20)), - 42..43: NewLine, - 43..49: Ident("filter"), - 50..54: Literal(Boolean(true)), - 54..55: NewLine, - 55..61: Ident("select"), - 62..63: Ident("d"), - 64..65: Control('='), - 66..68: Literal(Integer(10)), - 68..69: NewLine, + 5..11: Ident("genres"), + 11..12: NewLine, + 12..16: Ident("take"), + 17..19: Literal(Integer(10)), + 19..20: NewLine, + 20..26: Ident("filter"), + 27..31: Literal(Boolean(true)), + 31..32: NewLine, + 32..36: Ident("take"), + 37..39: Literal(Integer(20)), + 39..40: NewLine, + 40..46: Ident("filter"), + 47..51: Literal(Boolean(true)), + 51..52: NewLine, + 52..58: Ident("select"), + 59..60: Ident("d"), + 61..62: Control('='), + 63..65: Literal(Integer(10)), + 65..66: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__date_to_text.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__date_to_text.snap index bdbe062eddd0..31178d57118d 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__date_to_text.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__date_to_text.snap @@ -13,160 +13,158 @@ TokenVec ( 44..56: Comment(" mssql:test"), 56..57: NewLine, 57..61: Ident("from"), - 62..64: Ident("db"), - 64..65: Control('.'), - 65..73: Ident("invoices"), - 73..74: NewLine, - 74..78: Ident("take"), - 79..81: Literal(Integer(20)), - 81..82: NewLine, - 82..88: Ident("select"), - 89..90: Control('{'), - 90..91: NewLine, - 95..97: Ident("d1"), - 98..99: Control('='), - 100..101: Control('('), - 101..113: Ident("invoice_date"), - 114..115: Control('|'), - 116..120: Ident("date"), - 120..121: Control('.'), - 121..128: Ident("to_text"), - 129..139: Literal(String("%Y/%m/%d")), - 139..140: Control(')'), - 140..141: Control(','), - 141..142: NewLine, - 146..148: Ident("d2"), - 149..150: Control('='), - 151..152: Control('('), - 152..164: Ident("invoice_date"), - 165..166: Control('|'), - 167..171: Ident("date"), - 171..172: Control('.'), - 172..179: Ident("to_text"), - 180..184: Literal(String("%F")), - 184..185: Control(')'), - 185..186: Control(','), - 186..187: NewLine, - 191..193: Ident("d3"), - 194..195: Control('='), - 196..197: Control('('), - 197..209: Ident("invoice_date"), - 210..211: Control('|'), - 212..216: Ident("date"), - 216..217: Control('.'), - 217..224: Ident("to_text"), - 225..229: Literal(String("%D")), - 229..230: Control(')'), - 230..231: Control(','), - 231..232: NewLine, - 236..238: Ident("d4"), - 239..240: Control('='), - 241..242: Control('('), - 242..254: Ident("invoice_date"), - 255..256: Control('|'), - 257..261: Ident("date"), - 261..262: Control('.'), - 262..269: Ident("to_text"), - 270..283: Literal(String("%H:%M:%S.%f")), - 283..284: Control(')'), - 284..285: Control(','), - 285..286: NewLine, - 290..292: Ident("d5"), - 293..294: Control('='), - 295..296: Control('('), - 296..308: Ident("invoice_date"), - 309..310: Control('|'), - 311..315: Ident("date"), - 315..316: Control('.'), - 316..323: Ident("to_text"), - 324..328: Literal(String("%r")), - 328..329: Control(')'), - 329..330: Control(','), - 330..331: NewLine, - 335..337: Ident("d6"), - 338..339: Control('='), - 340..341: Control('('), - 341..353: Ident("invoice_date"), - 354..355: Control('|'), - 356..360: Ident("date"), - 360..361: Control('.'), - 361..368: Ident("to_text"), - 369..383: Literal(String("%A %B %-d %Y")), - 383..384: Control(')'), - 384..385: Control(','), - 385..386: NewLine, - 390..392: Ident("d7"), - 393..394: Control('='), - 395..396: Control('('), - 396..408: Ident("invoice_date"), - 409..410: Control('|'), - 411..415: Ident("date"), - 415..416: Control('.'), - 416..423: Ident("to_text"), - 424..454: Literal(String("%a, %-d %b %Y at %I:%M:%S %p")), - 454..455: Control(')'), - 455..456: Control(','), - 456..457: NewLine, - 461..463: Ident("d8"), - 464..465: Control('='), - 466..467: Control('('), - 467..479: Ident("invoice_date"), - 480..481: Control('|'), - 482..486: Ident("date"), - 486..487: Control('.'), - 487..494: Ident("to_text"), - 495..499: Literal(String("%+")), - 499..500: Control(')'), - 500..501: Control(','), - 501..502: NewLine, - 506..508: Ident("d9"), - 509..510: Control('='), - 511..512: Control('('), - 512..524: Ident("invoice_date"), - 525..526: Control('|'), - 527..531: Ident("date"), - 531..532: Control('.'), - 532..539: Ident("to_text"), - 540..552: Literal(String("%-d/%-m/%y")), - 552..553: Control(')'), - 553..554: Control(','), - 554..555: NewLine, - 559..562: Ident("d10"), - 563..564: Control('='), - 565..566: Control('('), - 566..578: Ident("invoice_date"), - 579..580: Control('|'), - 581..585: Ident("date"), - 585..586: Control('.'), - 586..593: Ident("to_text"), - 594..606: Literal(String("%-Hh %Mmin")), - 606..607: Control(')'), - 607..608: Control(','), - 608..609: NewLine, - 613..616: Ident("d11"), - 617..618: Control('='), - 619..620: Control('('), - 620..632: Ident("invoice_date"), - 633..634: Control('|'), - 635..639: Ident("date"), - 639..640: Control('.'), - 640..647: Ident("to_text"), - 648..657: Literal(String("%M'%S\"")), - 657..658: Control(')'), - 658..659: Control(','), - 659..660: NewLine, - 664..667: Ident("d12"), - 668..669: Control('='), - 670..671: Control('('), - 671..683: Ident("invoice_date"), - 684..685: Control('|'), - 686..690: Ident("date"), - 690..691: Control('.'), - 691..698: Ident("to_text"), - 699..717: Literal(String("100%% in %d days")), - 717..718: Control(')'), - 718..719: Control(','), - 719..720: NewLine, - 720..721: Control('}'), - 721..722: NewLine, + 62..70: Ident("invoices"), + 70..71: NewLine, + 71..75: Ident("take"), + 76..78: Literal(Integer(20)), + 78..79: NewLine, + 79..85: Ident("select"), + 86..87: Control('{'), + 87..88: NewLine, + 92..94: Ident("d1"), + 95..96: Control('='), + 97..98: Control('('), + 98..110: Ident("invoice_date"), + 111..112: Control('|'), + 113..117: Ident("date"), + 117..118: Control('.'), + 118..125: Ident("to_text"), + 126..136: Literal(String("%Y/%m/%d")), + 136..137: Control(')'), + 137..138: Control(','), + 138..139: NewLine, + 143..145: Ident("d2"), + 146..147: Control('='), + 148..149: Control('('), + 149..161: Ident("invoice_date"), + 162..163: Control('|'), + 164..168: Ident("date"), + 168..169: Control('.'), + 169..176: Ident("to_text"), + 177..181: Literal(String("%F")), + 181..182: Control(')'), + 182..183: Control(','), + 183..184: NewLine, + 188..190: Ident("d3"), + 191..192: Control('='), + 193..194: Control('('), + 194..206: Ident("invoice_date"), + 207..208: Control('|'), + 209..213: Ident("date"), + 213..214: Control('.'), + 214..221: Ident("to_text"), + 222..226: Literal(String("%D")), + 226..227: Control(')'), + 227..228: Control(','), + 228..229: NewLine, + 233..235: Ident("d4"), + 236..237: Control('='), + 238..239: Control('('), + 239..251: Ident("invoice_date"), + 252..253: Control('|'), + 254..258: Ident("date"), + 258..259: Control('.'), + 259..266: Ident("to_text"), + 267..280: Literal(String("%H:%M:%S.%f")), + 280..281: Control(')'), + 281..282: Control(','), + 282..283: NewLine, + 287..289: Ident("d5"), + 290..291: Control('='), + 292..293: Control('('), + 293..305: Ident("invoice_date"), + 306..307: Control('|'), + 308..312: Ident("date"), + 312..313: Control('.'), + 313..320: Ident("to_text"), + 321..325: Literal(String("%r")), + 325..326: Control(')'), + 326..327: Control(','), + 327..328: NewLine, + 332..334: Ident("d6"), + 335..336: Control('='), + 337..338: Control('('), + 338..350: Ident("invoice_date"), + 351..352: Control('|'), + 353..357: Ident("date"), + 357..358: Control('.'), + 358..365: Ident("to_text"), + 366..380: Literal(String("%A %B %-d %Y")), + 380..381: Control(')'), + 381..382: Control(','), + 382..383: NewLine, + 387..389: Ident("d7"), + 390..391: Control('='), + 392..393: Control('('), + 393..405: Ident("invoice_date"), + 406..407: Control('|'), + 408..412: Ident("date"), + 412..413: Control('.'), + 413..420: Ident("to_text"), + 421..451: Literal(String("%a, %-d %b %Y at %I:%M:%S %p")), + 451..452: Control(')'), + 452..453: Control(','), + 453..454: NewLine, + 458..460: Ident("d8"), + 461..462: Control('='), + 463..464: Control('('), + 464..476: Ident("invoice_date"), + 477..478: Control('|'), + 479..483: Ident("date"), + 483..484: Control('.'), + 484..491: Ident("to_text"), + 492..496: Literal(String("%+")), + 496..497: Control(')'), + 497..498: Control(','), + 498..499: NewLine, + 503..505: Ident("d9"), + 506..507: Control('='), + 508..509: Control('('), + 509..521: Ident("invoice_date"), + 522..523: Control('|'), + 524..528: Ident("date"), + 528..529: Control('.'), + 529..536: Ident("to_text"), + 537..549: Literal(String("%-d/%-m/%y")), + 549..550: Control(')'), + 550..551: Control(','), + 551..552: NewLine, + 556..559: Ident("d10"), + 560..561: Control('='), + 562..563: Control('('), + 563..575: Ident("invoice_date"), + 576..577: Control('|'), + 578..582: Ident("date"), + 582..583: Control('.'), + 583..590: Ident("to_text"), + 591..603: Literal(String("%-Hh %Mmin")), + 603..604: Control(')'), + 604..605: Control(','), + 605..606: NewLine, + 610..613: Ident("d11"), + 614..615: Control('='), + 616..617: Control('('), + 617..629: Ident("invoice_date"), + 630..631: Control('|'), + 632..636: Ident("date"), + 636..637: Control('.'), + 637..644: Ident("to_text"), + 645..654: Literal(String("%M'%S\"")), + 654..655: Control(')'), + 655..656: Control(','), + 656..657: NewLine, + 661..664: Ident("d12"), + 665..666: Control('='), + 667..668: Control('('), + 668..680: Ident("invoice_date"), + 681..682: Control('|'), + 683..687: Ident("date"), + 687..688: Control('.'), + 688..695: Ident("to_text"), + 696..714: Literal(String("100%% in %d days")), + 714..715: Control(')'), + 715..716: Control(','), + 716..717: NewLine, + 717..718: Control('}'), + 718..719: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__distinct.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__distinct.snap index 2bb30abda1e9..fd1049b2f6fd 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__distinct.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__distinct.snap @@ -7,29 +7,27 @@ TokenVec ( 0..12: Comment(" mssql:test"), 12..13: NewLine, 13..17: Ident("from"), - 18..20: Ident("db"), - 20..21: Control('.'), - 21..27: Ident("tracks"), - 27..28: NewLine, - 28..34: Ident("select"), - 35..36: Control('{'), - 36..44: Ident("album_id"), - 44..45: Control(','), - 46..54: Ident("genre_id"), - 54..55: Control('}'), - 55..56: NewLine, - 56..61: Ident("group"), - 62..68: Ident("tracks"), - 68..69: Control('.'), - 69..70: Control('*'), - 71..72: Control('('), - 72..76: Ident("take"), - 77..78: Literal(Integer(1)), - 78..79: Control(')'), - 79..80: NewLine, - 80..84: Ident("sort"), - 85..91: Ident("tracks"), - 91..92: Control('.'), - 92..93: Control('*'), - 93..94: NewLine, + 18..24: Ident("tracks"), + 24..25: NewLine, + 25..31: Ident("select"), + 32..33: Control('{'), + 33..41: Ident("album_id"), + 41..42: Control(','), + 43..51: Ident("genre_id"), + 51..52: Control('}'), + 52..53: NewLine, + 53..58: Ident("group"), + 59..65: Ident("tracks"), + 65..66: Control('.'), + 66..67: Control('*'), + 68..69: Control('('), + 69..73: Ident("take"), + 74..75: Literal(Integer(1)), + 75..76: Control(')'), + 76..77: NewLine, + 77..81: Ident("sort"), + 82..88: Ident("tracks"), + 88..89: Control('.'), + 89..90: Control('*'), + 90..91: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__distinct_on.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__distinct_on.snap index a5d6d66e5514..16803e327c04 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__distinct_on.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__distinct_on.snap @@ -7,42 +7,40 @@ TokenVec ( 0..12: Comment(" mssql:test"), 12..13: NewLine, 13..17: Ident("from"), - 18..20: Ident("db"), - 20..21: Control('.'), - 21..27: Ident("tracks"), - 27..28: NewLine, - 28..34: Ident("select"), - 35..36: Control('{'), - 36..44: Ident("genre_id"), - 44..45: Control(','), - 46..59: Ident("media_type_id"), - 59..60: Control(','), - 61..69: Ident("album_id"), - 69..70: Control('}'), - 70..71: NewLine, - 71..76: Ident("group"), - 77..78: Control('{'), - 78..86: Ident("genre_id"), - 86..87: Control(','), - 88..101: Ident("media_type_id"), - 101..102: Control('}'), - 103..104: Control('('), - 104..108: Ident("sort"), - 109..110: Control('{'), - 110..111: Control('-'), - 111..119: Ident("album_id"), - 119..120: Control('}'), - 121..122: Control('|'), - 123..127: Ident("take"), - 128..129: Literal(Integer(1)), - 129..130: Control(')'), - 130..131: NewLine, - 131..135: Ident("sort"), - 136..137: Control('{'), - 137..138: Control('-'), - 138..146: Ident("genre_id"), - 146..147: Control(','), - 148..161: Ident("media_type_id"), - 161..162: Control('}'), - 162..163: NewLine, + 18..24: Ident("tracks"), + 24..25: NewLine, + 25..31: Ident("select"), + 32..33: Control('{'), + 33..41: Ident("genre_id"), + 41..42: Control(','), + 43..56: Ident("media_type_id"), + 56..57: Control(','), + 58..66: Ident("album_id"), + 66..67: Control('}'), + 67..68: NewLine, + 68..73: Ident("group"), + 74..75: Control('{'), + 75..83: Ident("genre_id"), + 83..84: Control(','), + 85..98: Ident("media_type_id"), + 98..99: Control('}'), + 100..101: Control('('), + 101..105: Ident("sort"), + 106..107: Control('{'), + 107..108: Control('-'), + 108..116: Ident("album_id"), + 116..117: Control('}'), + 118..119: Control('|'), + 120..124: Ident("take"), + 125..126: Literal(Integer(1)), + 126..127: Control(')'), + 127..128: NewLine, + 128..132: Ident("sort"), + 133..134: Control('{'), + 134..135: Control('-'), + 135..143: Ident("genre_id"), + 143..144: Control(','), + 145..158: Ident("media_type_id"), + 158..159: Control('}'), + 159..160: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__genre_counts.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__genre_counts.snap index 88ee27c768e4..1ef6e90b147c 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__genre_counts.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__genre_counts.snap @@ -14,32 +14,31 @@ TokenVec ( 135..136: Control('('), 136..137: NewLine, 141..145: Ident("from"), - 146..148: Ident("db"), - 148..149: Control('.'), - 149..155: Ident("genres"), - 155..156: NewLine, - 160..169: Ident("aggregate"), - 170..171: Control('{'), - 171..172: Ident("a"), - 173..174: Control('='), - 175..180: Ident("count"), - 181..185: Ident("name"), - 185..186: Control('}'), + 146..152: Ident("genres"), + 152..153: NewLine, + 157..166: Ident("aggregate"), + 167..168: Control('{'), + 168..169: Ident("a"), + 170..171: Control('='), + 172..177: Ident("count"), + 178..182: Ident("name"), + 182..183: Control('}'), + 183..184: NewLine, + 184..185: Control(')'), + 185..186: NewLine, 186..187: NewLine, - 187..188: Control(')'), - 188..189: NewLine, - 189..190: NewLine, - 190..201: Ident("genre_count"), - 201..202: NewLine, - 202..208: Ident("filter"), - 209..210: Ident("a"), - 211..212: Control('>'), - 213..214: Literal(Integer(0)), - 214..215: NewLine, - 215..221: Ident("select"), - 222..223: Ident("a"), - 224..225: Control('='), - 226..227: Control('-'), - 227..228: Ident("a"), - 228..229: NewLine, + 187..191: Ident("from"), + 192..203: Ident("genre_count"), + 203..204: NewLine, + 204..210: Ident("filter"), + 211..212: Ident("a"), + 213..214: Control('>'), + 215..216: Literal(Integer(0)), + 216..217: NewLine, + 217..223: Ident("select"), + 224..225: Ident("a"), + 226..227: Control('='), + 228..229: Control('-'), + 229..230: Ident("a"), + 230..231: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__group_all.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__group_all.snap index 140d48ef546a..c406d25d358c 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__group_all.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__group_all.snap @@ -7,57 +7,48 @@ TokenVec ( 0..12: Comment(" mssql:test"), 12..13: NewLine, 13..17: Ident("from"), - 18..20: Ident("db"), - 20..21: Control('.'), - 21..27: Ident("albums"), - 27..28: NewLine, - 28..34: Ident("select"), - 35..36: Control('{'), - 36..37: Ident("a"), - 38..39: Control('='), - 40..44: Ident("this"), - 44..45: Control('}'), - 45..46: NewLine, - 46..50: Ident("take"), - 51..53: Literal(Integer(10)), - 53..54: NewLine, - 54..58: Ident("join"), - 59..61: Ident("db"), - 61..62: Control('.'), - 62..68: Ident("tracks"), - 69..70: Control('('), - 70..72: Eq, - 72..80: Ident("album_id"), - 80..81: Control(')'), - 81..82: NewLine, - 82..87: Ident("group"), - 88..89: Control('{'), - 89..90: Ident("a"), - 90..91: Control('.'), - 91..99: Ident("album_id"), - 99..100: Control(','), - 101..102: Ident("a"), - 102..103: Control('.'), - 103..108: Ident("title"), - 108..109: Control('}'), - 110..111: Control('('), - 111..120: Ident("aggregate"), - 121..126: Ident("price"), - 127..128: Control('='), - 129..130: Control('('), - 130..133: Ident("sum"), - 134..140: Ident("tracks"), - 140..141: Control('.'), - 141..151: Ident("unit_price"), - 152..153: Control('|'), - 154..158: Ident("math"), - 158..159: Control('.'), - 159..164: Ident("round"), - 165..166: Literal(Integer(2)), - 166..167: Control(')'), - 167..168: Control(')'), - 168..169: NewLine, - 169..173: Ident("sort"), - 174..182: Ident("album_id"), - 182..183: NewLine, + 18..19: Ident("a"), + 19..20: Control('='), + 20..26: Ident("albums"), + 26..27: NewLine, + 27..31: Ident("take"), + 32..34: Literal(Integer(10)), + 34..35: NewLine, + 35..39: Ident("join"), + 40..46: Ident("tracks"), + 47..48: Control('('), + 48..50: Eq, + 50..58: Ident("album_id"), + 58..59: Control(')'), + 59..60: NewLine, + 60..65: Ident("group"), + 66..67: Control('{'), + 67..68: Ident("a"), + 68..69: Control('.'), + 69..77: Ident("album_id"), + 77..78: Control(','), + 79..80: Ident("a"), + 80..81: Control('.'), + 81..86: Ident("title"), + 86..87: Control('}'), + 88..89: Control('('), + 89..98: Ident("aggregate"), + 99..104: Ident("price"), + 105..106: Control('='), + 107..108: Control('('), + 108..111: Ident("sum"), + 112..118: Ident("tracks"), + 118..119: Control('.'), + 119..129: Ident("unit_price"), + 130..131: Control('|'), + 132..136: Ident("math"), + 136..137: Control('.'), + 137..142: Ident("round"), + 143..144: Literal(Integer(2)), + 144..145: Control(')'), + 145..146: Control(')'), + 146..147: NewLine, + 147..151: Ident("sort"), + 152..160: Ident("album_id"), + 160..161: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__group_sort.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__group_sort.snap index fe37dc30c7c4..30c433ce65b8 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__group_sort.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__group_sort.snap @@ -7,50 +7,48 @@ TokenVec ( 0..12: Comment(" mssql:test"), 12..13: NewLine, 13..17: Ident("from"), - 18..20: Ident("db"), - 20..21: Control('.'), - 21..27: Ident("tracks"), - 27..28: NewLine, - 28..34: Ident("derive"), - 35..36: Ident("d"), - 37..38: Control('='), - 39..47: Ident("album_id"), - 48..49: Control('+'), - 50..51: Literal(Integer(1)), - 51..52: NewLine, - 52..57: Ident("group"), - 58..59: Ident("d"), - 60..61: Control('('), - 61..62: NewLine, - 66..75: Ident("aggregate"), - 76..77: Control('{'), - 77..78: NewLine, - 86..88: Ident("n1"), - 89..90: Control('='), - 91..92: Control('('), - 92..100: Ident("track_id"), - 101..102: Control('|'), - 103..106: Ident("sum"), - 106..107: Control(')'), - 107..108: Control(','), - 108..109: NewLine, - 113..114: Control('}'), - 114..115: NewLine, - 115..116: Control(')'), - 116..117: NewLine, - 117..121: Ident("sort"), - 122..123: Ident("d"), - 123..124: NewLine, - 124..128: Ident("take"), - 129..131: Literal(Integer(10)), - 131..132: NewLine, - 132..138: Ident("select"), - 139..140: Control('{'), - 141..143: Ident("d1"), - 144..145: Control('='), - 146..147: Ident("d"), - 147..148: Control(','), - 149..151: Ident("n1"), - 152..153: Control('}'), - 153..154: NewLine, + 18..24: Ident("tracks"), + 24..25: NewLine, + 25..31: Ident("derive"), + 32..33: Ident("d"), + 34..35: Control('='), + 36..44: Ident("album_id"), + 45..46: Control('+'), + 47..48: Literal(Integer(1)), + 48..49: NewLine, + 49..54: Ident("group"), + 55..56: Ident("d"), + 57..58: Control('('), + 58..59: NewLine, + 63..72: Ident("aggregate"), + 73..74: Control('{'), + 74..75: NewLine, + 83..85: Ident("n1"), + 86..87: Control('='), + 88..89: Control('('), + 89..97: Ident("track_id"), + 98..99: Control('|'), + 100..103: Ident("sum"), + 103..104: Control(')'), + 104..105: Control(','), + 105..106: NewLine, + 110..111: Control('}'), + 111..112: NewLine, + 112..113: Control(')'), + 113..114: NewLine, + 114..118: Ident("sort"), + 119..120: Ident("d"), + 120..121: NewLine, + 121..125: Ident("take"), + 126..128: Literal(Integer(10)), + 128..129: NewLine, + 129..135: Ident("select"), + 136..137: Control('{'), + 138..140: Ident("d1"), + 141..142: Control('='), + 143..144: Ident("d"), + 144..145: Control(','), + 146..148: Ident("n1"), + 149..150: Control('}'), + 150..151: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__group_sort_limit_take.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__group_sort_limit_take.snap index 0896555a350f..eab866c765fe 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__group_sort_limit_take.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__group_sort_limit_take.snap @@ -9,57 +9,53 @@ TokenVec ( 63..75: Comment(" mssql:test"), 75..76: NewLine, 76..80: Ident("from"), - 81..83: Ident("db"), - 83..84: Control('.'), - 84..90: Ident("tracks"), - 90..91: NewLine, - 91..97: Ident("select"), - 98..99: Control('{'), - 99..107: Ident("genre_id"), - 107..108: Control(','), - 108..120: Ident("milliseconds"), - 120..121: Control('}'), - 121..122: NewLine, - 122..127: Ident("group"), - 128..129: Control('{'), - 129..137: Ident("genre_id"), - 137..138: Control('}'), - 139..140: Control('('), - 140..141: NewLine, - 143..147: Ident("sort"), - 148..149: Control('{'), - 149..150: Control('-'), - 150..162: Ident("milliseconds"), - 162..163: Control('}'), - 163..164: NewLine, - 166..170: Ident("take"), - 171..172: Literal(Integer(3)), - 172..173: NewLine, - 173..174: Control(')'), - 174..175: NewLine, - 175..179: Ident("join"), - 180..182: Ident("db"), - 182..183: Control('.'), - 183..189: Ident("genres"), - 190..191: Control('('), - 191..193: Eq, - 193..201: Ident("genre_id"), - 201..202: Control(')'), - 202..203: NewLine, - 203..209: Ident("select"), - 210..211: Control('{'), - 211..215: Ident("name"), - 215..216: Control(','), - 217..229: Ident("milliseconds"), - 229..230: Control('}'), - 230..231: NewLine, - 231..235: Ident("sort"), - 236..237: Control('{'), - 237..238: Control('+'), - 238..242: Ident("name"), - 242..243: Control(','), - 243..244: Control('-'), - 244..256: Ident("milliseconds"), - 256..257: Control('}'), - 257..258: NewLine, + 81..87: Ident("tracks"), + 87..88: NewLine, + 88..94: Ident("select"), + 95..96: Control('{'), + 96..104: Ident("genre_id"), + 104..105: Control(','), + 105..117: Ident("milliseconds"), + 117..118: Control('}'), + 118..119: NewLine, + 119..124: Ident("group"), + 125..126: Control('{'), + 126..134: Ident("genre_id"), + 134..135: Control('}'), + 136..137: Control('('), + 137..138: NewLine, + 140..144: Ident("sort"), + 145..146: Control('{'), + 146..147: Control('-'), + 147..159: Ident("milliseconds"), + 159..160: Control('}'), + 160..161: NewLine, + 163..167: Ident("take"), + 168..169: Literal(Integer(3)), + 169..170: NewLine, + 170..171: Control(')'), + 171..172: NewLine, + 172..176: Ident("join"), + 177..183: Ident("genres"), + 184..185: Control('('), + 185..187: Eq, + 187..195: Ident("genre_id"), + 195..196: Control(')'), + 196..197: NewLine, + 197..203: Ident("select"), + 204..205: Control('{'), + 205..209: Ident("name"), + 209..210: Control(','), + 211..223: Ident("milliseconds"), + 223..224: Control('}'), + 224..225: NewLine, + 225..229: Ident("sort"), + 230..231: Control('{'), + 231..232: Control('+'), + 232..236: Ident("name"), + 236..237: Control(','), + 237..238: Control('-'), + 238..250: Ident("milliseconds"), + 250..251: Control('}'), + 251..252: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__invoice_totals.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__invoice_totals.snap index cf0da489b0ac..56934edb610c 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__invoice_totals.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__invoice_totals.snap @@ -10,168 +10,152 @@ TokenVec ( 58..130: DocComment(" Calculate a number of metrics about the sales of tracks in each city."), 130..131: NewLine, 131..135: Ident("from"), - 136..138: Ident("db"), - 138..139: Control('.'), - 139..147: Ident("invoices"), - 147..148: NewLine, - 148..154: Ident("select"), - 155..156: Control('{'), - 156..157: Ident("i"), - 158..159: Control('='), - 160..164: Ident("this"), - 164..165: Control('}'), - 165..166: NewLine, - 166..170: Ident("join"), - 171..172: Control('('), - 172..174: Ident("db"), - 174..175: Control('.'), - 175..188: Ident("invoice_items"), - 189..190: Control('|'), - 191..197: Ident("select"), - 198..199: Control('{'), - 199..201: Ident("ii"), + 136..137: Ident("i"), + 137..138: Control('='), + 138..146: Ident("invoices"), + 146..147: NewLine, + 147..151: Ident("join"), + 152..154: Ident("ii"), + 154..155: Control('='), + 155..168: Ident("invoice_items"), + 169..170: Control('('), + 170..172: Eq, + 172..182: Ident("invoice_id"), + 182..183: Control(')'), + 183..184: NewLine, + 184..190: Ident("derive"), + 191..192: Control('{'), + 192..193: NewLine, + 197..201: Ident("city"), 202..203: Control('='), - 204..208: Ident("this"), - 208..209: Control('}'), - 209..210: Control(')'), - 211..212: Control('('), - 212..214: Eq, - 214..224: Ident("invoice_id"), - 224..225: Control(')'), - 225..226: NewLine, - 226..232: Ident("derive"), - 233..234: Control('{'), - 234..235: NewLine, - 239..243: Ident("city"), - 244..245: Control('='), - 246..247: Ident("i"), - 247..248: Control('.'), - 248..260: Ident("billing_city"), - 260..261: Control(','), - 261..262: NewLine, - 266..272: Ident("street"), - 273..274: Control('='), - 275..276: Ident("i"), - 276..277: Control('.'), - 277..292: Ident("billing_address"), - 292..293: Control(','), - 293..294: NewLine, - 294..295: Control('}'), - 295..296: NewLine, - 296..301: Ident("group"), - 302..303: Control('{'), - 303..307: Ident("city"), - 307..308: Control(','), - 309..315: Ident("street"), - 315..316: Control('}'), - 317..318: Control('('), - 318..319: NewLine, - 323..329: Ident("derive"), - 330..335: Ident("total"), - 336..337: Control('='), - 338..340: Ident("ii"), - 340..341: Control('.'), - 341..351: Ident("unit_price"), - 352..353: Control('*'), - 354..356: Ident("ii"), - 356..357: Control('.'), - 357..365: Ident("quantity"), - 365..366: NewLine, - 370..379: Ident("aggregate"), - 380..381: Control('{'), - 381..382: NewLine, - 390..400: Ident("num_orders"), - 401..402: Control('='), - 403..417: Ident("count_distinct"), - 418..419: Ident("i"), - 419..420: Control('.'), - 420..430: Ident("invoice_id"), - 430..431: Control(','), - 431..432: NewLine, - 440..450: Ident("num_tracks"), - 451..452: Control('='), - 453..456: Ident("sum"), - 457..459: Ident("ii"), - 459..460: Control('.'), - 460..468: Ident("quantity"), - 468..469: Control(','), - 469..470: NewLine, - 478..489: Ident("total_price"), - 490..491: Control('='), - 492..495: Ident("sum"), - 496..501: Ident("total"), - 501..502: Control(','), - 502..503: NewLine, - 507..508: Control('}'), - 508..509: NewLine, - 509..510: Control(')'), - 510..511: NewLine, - 511..516: Ident("group"), - 517..518: Control('{'), - 518..522: Ident("city"), - 522..523: Control('}'), - 524..525: Control('('), - 525..526: NewLine, - 530..534: Ident("sort"), - 535..541: Ident("street"), - 541..542: NewLine, - 546..552: Ident("window"), - 553..562: Ident("expanding"), - 562..563: Control(':'), - 563..567: Literal(Boolean(true)), - 568..569: Control('('), - 569..570: NewLine, - 578..584: Ident("derive"), - 585..586: Control('{'), - 586..610: Ident("running_total_num_tracks"), - 611..612: Control('='), - 613..616: Ident("sum"), - 617..627: Ident("num_tracks"), - 627..628: Control('}'), - 628..629: NewLine, - 633..634: Control(')'), - 634..635: NewLine, - 635..636: Control(')'), - 636..637: NewLine, - 637..641: Ident("sort"), - 642..643: Control('{'), - 643..647: Ident("city"), - 647..648: Control(','), - 649..655: Ident("street"), - 655..656: Control('}'), - 656..657: NewLine, - 657..663: Ident("derive"), - 664..665: Control('{'), - 665..685: Ident("num_tracks_last_week"), - 686..687: Control('='), - 688..691: Ident("lag"), - 692..693: Literal(Integer(7)), - 694..704: Ident("num_tracks"), - 704..705: Control('}'), - 705..706: NewLine, - 706..712: Ident("select"), - 713..714: Control('{'), - 714..715: NewLine, - 719..723: Ident("city"), - 723..724: Control(','), - 724..725: NewLine, - 729..735: Ident("street"), - 735..736: Control(','), - 736..737: NewLine, - 741..751: Ident("num_orders"), - 751..752: Control(','), - 752..753: NewLine, - 757..767: Ident("num_tracks"), - 767..768: Control(','), - 768..769: NewLine, - 773..797: Ident("running_total_num_tracks"), - 797..798: Control(','), - 798..799: NewLine, - 803..823: Ident("num_tracks_last_week"), - 823..824: NewLine, - 824..825: Control('}'), - 825..826: NewLine, - 826..830: Ident("take"), - 831..833: Literal(Integer(20)), - 833..834: NewLine, + 204..205: Ident("i"), + 205..206: Control('.'), + 206..218: Ident("billing_city"), + 218..219: Control(','), + 219..220: NewLine, + 224..230: Ident("street"), + 231..232: Control('='), + 233..234: Ident("i"), + 234..235: Control('.'), + 235..250: Ident("billing_address"), + 250..251: Control(','), + 251..252: NewLine, + 252..253: Control('}'), + 253..254: NewLine, + 254..259: Ident("group"), + 260..261: Control('{'), + 261..265: Ident("city"), + 265..266: Control(','), + 267..273: Ident("street"), + 273..274: Control('}'), + 275..276: Control('('), + 276..277: NewLine, + 281..287: Ident("derive"), + 288..293: Ident("total"), + 294..295: Control('='), + 296..298: Ident("ii"), + 298..299: Control('.'), + 299..309: Ident("unit_price"), + 310..311: Control('*'), + 312..314: Ident("ii"), + 314..315: Control('.'), + 315..323: Ident("quantity"), + 323..324: NewLine, + 328..337: Ident("aggregate"), + 338..339: Control('{'), + 339..340: NewLine, + 348..358: Ident("num_orders"), + 359..360: Control('='), + 361..375: Ident("count_distinct"), + 376..377: Ident("i"), + 377..378: Control('.'), + 378..388: Ident("invoice_id"), + 388..389: Control(','), + 389..390: NewLine, + 398..408: Ident("num_tracks"), + 409..410: Control('='), + 411..414: Ident("sum"), + 415..417: Ident("ii"), + 417..418: Control('.'), + 418..426: Ident("quantity"), + 426..427: Control(','), + 427..428: NewLine, + 436..447: Ident("total_price"), + 448..449: Control('='), + 450..453: Ident("sum"), + 454..459: Ident("total"), + 459..460: Control(','), + 460..461: NewLine, + 465..466: Control('}'), + 466..467: NewLine, + 467..468: Control(')'), + 468..469: NewLine, + 469..474: Ident("group"), + 475..476: Control('{'), + 476..480: Ident("city"), + 480..481: Control('}'), + 482..483: Control('('), + 483..484: NewLine, + 488..492: Ident("sort"), + 493..499: Ident("street"), + 499..500: NewLine, + 504..510: Ident("window"), + 511..520: Ident("expanding"), + 520..521: Control(':'), + 521..525: Literal(Boolean(true)), + 526..527: Control('('), + 527..528: NewLine, + 536..542: Ident("derive"), + 543..544: Control('{'), + 544..568: Ident("running_total_num_tracks"), + 569..570: Control('='), + 571..574: Ident("sum"), + 575..585: Ident("num_tracks"), + 585..586: Control('}'), + 586..587: NewLine, + 591..592: Control(')'), + 592..593: NewLine, + 593..594: Control(')'), + 594..595: NewLine, + 595..599: Ident("sort"), + 600..601: Control('{'), + 601..605: Ident("city"), + 605..606: Control(','), + 607..613: Ident("street"), + 613..614: Control('}'), + 614..615: NewLine, + 615..621: Ident("derive"), + 622..623: Control('{'), + 623..643: Ident("num_tracks_last_week"), + 644..645: Control('='), + 646..649: Ident("lag"), + 650..651: Literal(Integer(7)), + 652..662: Ident("num_tracks"), + 662..663: Control('}'), + 663..664: NewLine, + 664..670: Ident("select"), + 671..672: Control('{'), + 672..673: NewLine, + 677..681: Ident("city"), + 681..682: Control(','), + 682..683: NewLine, + 687..693: Ident("street"), + 693..694: Control(','), + 694..695: NewLine, + 699..709: Ident("num_orders"), + 709..710: Control(','), + 710..711: NewLine, + 715..725: Ident("num_tracks"), + 725..726: Control(','), + 726..727: NewLine, + 731..755: Ident("running_total_num_tracks"), + 755..756: Control(','), + 756..757: NewLine, + 761..781: Ident("num_tracks_last_week"), + 781..782: NewLine, + 782..783: Control('}'), + 783..784: NewLine, + 784..788: Ident("take"), + 789..791: Literal(Integer(20)), + 791..792: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__loop_01.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__loop_01.snap index 320976bbaa0f..99ba45a3fea7 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__loop_01.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__loop_01.snap @@ -8,44 +8,45 @@ TokenVec ( 47..48: NewLine, 48..161: Comment(" glaredb:skip (DataFusion does not support recursive CTEs https://github.com/apache/arrow-datafusion/issues/462)"), 161..162: NewLine, - 162..163: Control('['), - 163..164: Control('{'), - 164..165: Ident("n"), - 166..167: Control('='), - 168..169: Literal(Integer(1)), - 169..170: Control('}'), - 170..171: Control(']'), - 171..172: NewLine, - 172..178: Ident("select"), - 179..180: Ident("n"), - 181..182: Control('='), - 183..184: Ident("n"), - 185..186: Control('-'), - 187..188: Literal(Integer(2)), - 188..189: NewLine, - 189..193: Ident("loop"), - 194..195: Control('('), - 195..201: Ident("filter"), - 202..203: Ident("n"), - 204..205: Control('<'), - 206..207: Literal(Integer(4)), - 208..209: Control('|'), - 210..216: Ident("select"), - 217..218: Ident("n"), - 219..220: Control('='), - 221..222: Ident("n"), - 223..224: Control('+'), - 225..226: Literal(Integer(1)), - 226..227: Control(')'), - 227..228: NewLine, - 228..234: Ident("select"), - 235..236: Ident("n"), - 237..238: Control('='), - 239..240: Ident("n"), - 241..242: Control('*'), - 243..244: Literal(Integer(2)), - 244..245: NewLine, - 245..249: Ident("sort"), - 250..251: Ident("n"), - 251..252: NewLine, + 162..166: Ident("from"), + 167..168: Control('['), + 168..169: Control('{'), + 169..170: Ident("n"), + 171..172: Control('='), + 173..174: Literal(Integer(1)), + 174..175: Control('}'), + 175..176: Control(']'), + 176..177: NewLine, + 177..183: Ident("select"), + 184..185: Ident("n"), + 186..187: Control('='), + 188..189: Ident("n"), + 190..191: Control('-'), + 192..193: Literal(Integer(2)), + 193..194: NewLine, + 194..198: Ident("loop"), + 199..200: Control('('), + 200..206: Ident("filter"), + 207..208: Ident("n"), + 209..210: Control('<'), + 211..212: Literal(Integer(4)), + 213..214: Control('|'), + 215..221: Ident("select"), + 222..223: Ident("n"), + 224..225: Control('='), + 226..227: Ident("n"), + 228..229: Control('+'), + 230..231: Literal(Integer(1)), + 231..232: Control(')'), + 232..233: NewLine, + 233..239: Ident("select"), + 240..241: Ident("n"), + 242..243: Control('='), + 244..245: Ident("n"), + 246..247: Control('*'), + 248..249: Literal(Integer(2)), + 249..250: NewLine, + 250..254: Ident("sort"), + 255..256: Ident("n"), + 256..257: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__math_module.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__math_module.snap index 04da9461d699..524cecd86b61 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__math_module.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__math_module.snap @@ -9,201 +9,199 @@ TokenVec ( 13..81: Comment(" sqlite:skip (see https://github.com/rusqlite/rusqlite/issues/1211)"), 81..82: NewLine, 82..86: Ident("from"), - 87..89: Ident("db"), - 89..90: Control('.'), - 90..98: Ident("invoices"), - 98..99: NewLine, - 99..103: Ident("take"), - 104..105: Literal(Integer(5)), - 105..106: NewLine, - 106..112: Ident("select"), - 113..114: Control('{'), - 114..115: NewLine, - 119..133: Ident("total_original"), - 134..135: Control('='), - 136..141: Ident("total"), - 142..143: Control('|'), - 144..148: Ident("math"), - 148..149: Control('.'), - 149..154: Ident("round"), - 155..156: Literal(Integer(2)), - 156..157: Control(','), - 157..158: NewLine, - 162..169: Ident("total_x"), - 170..171: Control('='), - 172..176: Ident("math"), - 176..177: Control('.'), - 177..179: Ident("pi"), - 180..181: Control('-'), - 182..187: Ident("total"), - 188..189: Control('|'), - 190..194: Ident("math"), - 194..195: Control('.'), - 195..200: Ident("round"), - 201..202: Literal(Integer(2)), - 203..204: Control('|'), - 205..209: Ident("math"), - 209..210: Control('.'), - 210..213: Ident("abs"), - 213..214: Control(','), - 214..215: NewLine, - 219..230: Ident("total_floor"), - 231..232: Control('='), - 233..237: Ident("math"), - 237..238: Control('.'), - 238..243: Ident("floor"), - 244..249: Ident("total"), - 249..250: Control(','), - 250..251: NewLine, - 255..265: Ident("total_ceil"), - 266..267: Control('='), - 268..272: Ident("math"), - 272..273: Control('.'), - 273..277: Ident("ceil"), - 278..283: Ident("total"), - 283..284: Control(','), - 284..285: NewLine, - 289..300: Ident("total_log10"), - 301..302: Control('='), - 303..307: Ident("math"), - 307..308: Control('.'), - 308..313: Ident("log10"), - 314..319: Ident("total"), - 320..321: Control('|'), - 322..326: Ident("math"), - 326..327: Control('.'), - 327..332: Ident("round"), - 333..334: Literal(Integer(3)), - 334..335: Control(','), - 335..336: NewLine, - 340..350: Ident("total_log2"), - 351..352: Control('='), - 353..357: Ident("math"), - 357..358: Control('.'), - 358..361: Ident("log"), - 362..363: Literal(Integer(2)), - 364..369: Ident("total"), - 370..371: Control('|'), - 372..376: Ident("math"), - 376..377: Control('.'), - 377..382: Ident("round"), - 383..384: Literal(Integer(3)), - 384..385: Control(','), - 385..386: NewLine, - 390..400: Ident("total_sqrt"), - 401..402: Control('='), - 403..407: Ident("math"), - 407..408: Control('.'), - 408..412: Ident("sqrt"), - 413..418: Ident("total"), - 419..420: Control('|'), - 421..425: Ident("math"), - 425..426: Control('.'), - 426..431: Ident("round"), - 432..433: Literal(Integer(3)), - 433..434: Control(','), - 434..435: NewLine, - 439..447: Ident("total_ln"), - 448..449: Control('='), - 450..454: Ident("math"), - 454..455: Control('.'), - 455..457: Ident("ln"), - 458..463: Ident("total"), - 464..465: Control('|'), - 466..470: Ident("math"), - 470..471: Control('.'), - 471..474: Ident("exp"), - 475..476: Control('|'), - 477..481: Ident("math"), - 481..482: Control('.'), - 482..487: Ident("round"), - 488..489: Literal(Integer(2)), - 489..490: Control(','), - 490..491: NewLine, - 495..504: Ident("total_cos"), - 505..506: Control('='), - 507..511: Ident("math"), - 511..512: Control('.'), - 512..515: Ident("cos"), - 516..521: Ident("total"), - 522..523: Control('|'), - 524..528: Ident("math"), - 528..529: Control('.'), - 529..533: Ident("acos"), - 534..535: Control('|'), - 536..540: Ident("math"), - 540..541: Control('.'), - 541..546: Ident("round"), - 547..548: Literal(Integer(2)), - 548..549: Control(','), - 549..550: NewLine, - 554..563: Ident("total_sin"), - 564..565: Control('='), - 566..570: Ident("math"), - 570..571: Control('.'), - 571..574: Ident("sin"), - 575..580: Ident("total"), - 581..582: Control('|'), - 583..587: Ident("math"), - 587..588: Control('.'), - 588..592: Ident("asin"), - 593..594: Control('|'), - 595..599: Ident("math"), - 599..600: Control('.'), - 600..605: Ident("round"), - 606..607: Literal(Integer(2)), - 607..608: Control(','), - 608..609: NewLine, - 613..622: Ident("total_tan"), - 623..624: Control('='), - 625..629: Ident("math"), - 629..630: Control('.'), - 630..633: Ident("tan"), - 634..639: Ident("total"), - 640..641: Control('|'), - 642..646: Ident("math"), - 646..647: Control('.'), - 647..651: Ident("atan"), - 652..653: Control('|'), - 654..658: Ident("math"), - 658..659: Control('.'), - 659..664: Ident("round"), - 665..666: Literal(Integer(2)), - 666..667: Control(','), - 667..668: NewLine, - 672..681: Ident("total_deg"), - 682..683: Control('='), - 684..689: Ident("total"), - 690..691: Control('|'), - 692..696: Ident("math"), - 696..697: Control('.'), - 697..704: Ident("degrees"), - 705..706: Control('|'), - 707..711: Ident("math"), - 711..712: Control('.'), - 712..719: Ident("radians"), - 720..721: Control('|'), - 722..726: Ident("math"), - 726..727: Control('.'), - 727..732: Ident("round"), - 733..734: Literal(Integer(2)), - 734..735: Control(','), - 735..736: NewLine, - 740..752: Ident("total_square"), - 753..754: Control('='), - 755..760: Ident("total"), - 761..762: Control('|'), - 763..767: Ident("math"), - 767..768: Control('.'), - 768..771: Ident("pow"), - 772..773: Literal(Integer(2)), - 773..774: Control('|'), - 775..779: Ident("math"), - 779..780: Control('.'), - 780..785: Ident("round"), - 786..787: Literal(Integer(2)), - 787..788: Control(','), - 788..789: NewLine, - 789..790: Control('}'), - 790..791: NewLine, + 87..95: Ident("invoices"), + 95..96: NewLine, + 96..100: Ident("take"), + 101..102: Literal(Integer(5)), + 102..103: NewLine, + 103..109: Ident("select"), + 110..111: Control('{'), + 111..112: NewLine, + 116..130: Ident("total_original"), + 131..132: Control('='), + 133..138: Ident("total"), + 139..140: Control('|'), + 141..145: Ident("math"), + 145..146: Control('.'), + 146..151: Ident("round"), + 152..153: Literal(Integer(2)), + 153..154: Control(','), + 154..155: NewLine, + 159..166: Ident("total_x"), + 167..168: Control('='), + 169..173: Ident("math"), + 173..174: Control('.'), + 174..176: Ident("pi"), + 177..178: Control('-'), + 179..184: Ident("total"), + 185..186: Control('|'), + 187..191: Ident("math"), + 191..192: Control('.'), + 192..197: Ident("round"), + 198..199: Literal(Integer(2)), + 200..201: Control('|'), + 202..206: Ident("math"), + 206..207: Control('.'), + 207..210: Ident("abs"), + 210..211: Control(','), + 211..212: NewLine, + 216..227: Ident("total_floor"), + 228..229: Control('='), + 230..234: Ident("math"), + 234..235: Control('.'), + 235..240: Ident("floor"), + 241..246: Ident("total"), + 246..247: Control(','), + 247..248: NewLine, + 252..262: Ident("total_ceil"), + 263..264: Control('='), + 265..269: Ident("math"), + 269..270: Control('.'), + 270..274: Ident("ceil"), + 275..280: Ident("total"), + 280..281: Control(','), + 281..282: NewLine, + 286..297: Ident("total_log10"), + 298..299: Control('='), + 300..304: Ident("math"), + 304..305: Control('.'), + 305..310: Ident("log10"), + 311..316: Ident("total"), + 317..318: Control('|'), + 319..323: Ident("math"), + 323..324: Control('.'), + 324..329: Ident("round"), + 330..331: Literal(Integer(3)), + 331..332: Control(','), + 332..333: NewLine, + 337..347: Ident("total_log2"), + 348..349: Control('='), + 350..354: Ident("math"), + 354..355: Control('.'), + 355..358: Ident("log"), + 359..360: Literal(Integer(2)), + 361..366: Ident("total"), + 367..368: Control('|'), + 369..373: Ident("math"), + 373..374: Control('.'), + 374..379: Ident("round"), + 380..381: Literal(Integer(3)), + 381..382: Control(','), + 382..383: NewLine, + 387..397: Ident("total_sqrt"), + 398..399: Control('='), + 400..404: Ident("math"), + 404..405: Control('.'), + 405..409: Ident("sqrt"), + 410..415: Ident("total"), + 416..417: Control('|'), + 418..422: Ident("math"), + 422..423: Control('.'), + 423..428: Ident("round"), + 429..430: Literal(Integer(3)), + 430..431: Control(','), + 431..432: NewLine, + 436..444: Ident("total_ln"), + 445..446: Control('='), + 447..451: Ident("math"), + 451..452: Control('.'), + 452..454: Ident("ln"), + 455..460: Ident("total"), + 461..462: Control('|'), + 463..467: Ident("math"), + 467..468: Control('.'), + 468..471: Ident("exp"), + 472..473: Control('|'), + 474..478: Ident("math"), + 478..479: Control('.'), + 479..484: Ident("round"), + 485..486: Literal(Integer(2)), + 486..487: Control(','), + 487..488: NewLine, + 492..501: Ident("total_cos"), + 502..503: Control('='), + 504..508: Ident("math"), + 508..509: Control('.'), + 509..512: Ident("cos"), + 513..518: Ident("total"), + 519..520: Control('|'), + 521..525: Ident("math"), + 525..526: Control('.'), + 526..530: Ident("acos"), + 531..532: Control('|'), + 533..537: Ident("math"), + 537..538: Control('.'), + 538..543: Ident("round"), + 544..545: Literal(Integer(2)), + 545..546: Control(','), + 546..547: NewLine, + 551..560: Ident("total_sin"), + 561..562: Control('='), + 563..567: Ident("math"), + 567..568: Control('.'), + 568..571: Ident("sin"), + 572..577: Ident("total"), + 578..579: Control('|'), + 580..584: Ident("math"), + 584..585: Control('.'), + 585..589: Ident("asin"), + 590..591: Control('|'), + 592..596: Ident("math"), + 596..597: Control('.'), + 597..602: Ident("round"), + 603..604: Literal(Integer(2)), + 604..605: Control(','), + 605..606: NewLine, + 610..619: Ident("total_tan"), + 620..621: Control('='), + 622..626: Ident("math"), + 626..627: Control('.'), + 627..630: Ident("tan"), + 631..636: Ident("total"), + 637..638: Control('|'), + 639..643: Ident("math"), + 643..644: Control('.'), + 644..648: Ident("atan"), + 649..650: Control('|'), + 651..655: Ident("math"), + 655..656: Control('.'), + 656..661: Ident("round"), + 662..663: Literal(Integer(2)), + 663..664: Control(','), + 664..665: NewLine, + 669..678: Ident("total_deg"), + 679..680: Control('='), + 681..686: Ident("total"), + 687..688: Control('|'), + 689..693: Ident("math"), + 693..694: Control('.'), + 694..701: Ident("degrees"), + 702..703: Control('|'), + 704..708: Ident("math"), + 708..709: Control('.'), + 709..716: Ident("radians"), + 717..718: Control('|'), + 719..723: Ident("math"), + 723..724: Control('.'), + 724..729: Ident("round"), + 730..731: Literal(Integer(2)), + 731..732: Control(','), + 732..733: NewLine, + 737..749: Ident("total_square"), + 750..751: Control('='), + 752..757: Ident("total"), + 758..759: Control('|'), + 760..764: Ident("math"), + 764..765: Control('.'), + 765..768: Ident("pow"), + 769..770: Literal(Integer(2)), + 770..771: Control('|'), + 772..776: Ident("math"), + 776..777: Control('.'), + 777..782: Ident("round"), + 783..784: Literal(Integer(2)), + 784..785: Control(','), + 785..786: NewLine, + 786..787: Control('}'), + 787..788: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__pipelines.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__pipelines.snap index 54de94796aa4..33b2a6ac8a2c 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__pipelines.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__pipelines.snap @@ -12,47 +12,45 @@ TokenVec ( 164..165: NewLine, 165..166: NewLine, 166..170: Ident("from"), - 171..173: Ident("db"), - 173..174: Control('.'), - 174..180: Ident("tracks"), - 180..181: NewLine, - 181..182: NewLine, - 182..188: Ident("filter"), - 189..190: Control('('), - 190..194: Ident("name"), - 195..197: RegexSearch, - 198..204: Literal(String("Love")), - 204..205: Control(')'), - 205..206: NewLine, - 206..212: Ident("filter"), - 213..214: Control('('), - 214..215: Control('('), - 215..227: Ident("milliseconds"), - 228..229: Control('/'), - 230..234: Literal(Integer(1000)), - 235..236: Control('/'), - 237..239: Literal(Integer(60)), - 239..240: Control(')'), - 241..242: Control('|'), - 243..245: Ident("in"), - 246..247: Literal(Integer(3)), - 247..249: Range { bind_left: true, bind_right: true }, - 249..250: Literal(Integer(4)), - 250..251: Control(')'), - 251..252: NewLine, - 252..256: Ident("sort"), - 257..265: Ident("track_id"), - 265..266: NewLine, - 266..270: Ident("take"), - 271..272: Literal(Integer(1)), - 272..274: Range { bind_left: true, bind_right: true }, - 274..276: Literal(Integer(15)), - 276..277: NewLine, - 277..283: Ident("select"), - 284..285: Control('{'), - 285..289: Ident("name"), - 289..290: Control(','), - 291..299: Ident("composer"), - 299..300: Control('}'), - 300..301: NewLine, + 171..177: Ident("tracks"), + 177..178: NewLine, + 178..179: NewLine, + 179..185: Ident("filter"), + 186..187: Control('('), + 187..191: Ident("name"), + 192..194: RegexSearch, + 195..201: Literal(String("Love")), + 201..202: Control(')'), + 202..203: NewLine, + 203..209: Ident("filter"), + 210..211: Control('('), + 211..212: Control('('), + 212..224: Ident("milliseconds"), + 225..226: Control('/'), + 227..231: Literal(Integer(1000)), + 232..233: Control('/'), + 234..236: Literal(Integer(60)), + 236..237: Control(')'), + 238..239: Control('|'), + 240..242: Ident("in"), + 243..244: Literal(Integer(3)), + 244..246: Range { bind_left: true, bind_right: true }, + 246..247: Literal(Integer(4)), + 247..248: Control(')'), + 248..249: NewLine, + 249..253: Ident("sort"), + 254..262: Ident("track_id"), + 262..263: NewLine, + 263..267: Ident("take"), + 268..269: Literal(Integer(1)), + 269..271: Range { bind_left: true, bind_right: true }, + 271..273: Literal(Integer(15)), + 273..274: NewLine, + 274..280: Ident("select"), + 281..282: Control('{'), + 282..286: Ident("name"), + 286..287: Control(','), + 288..296: Ident("composer"), + 296..297: Control('}'), + 297..298: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__read_csv.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__read_csv.snap index c2927c9b4b91..06d1d753e4cb 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__read_csv.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__read_csv.snap @@ -10,10 +10,13 @@ TokenVec ( 29..30: NewLine, 30..42: Comment(" mysql:skip"), 42..43: NewLine, - 43..51: Ident("read_csv"), - 52..84: Literal(String("data_file_root/media_types.csv")), - 84..85: NewLine, - 85..89: Ident("sort"), - 90..103: Ident("media_type_id"), - 103..104: NewLine, + 43..47: Ident("from"), + 48..49: Control('('), + 49..57: Ident("read_csv"), + 58..90: Literal(String("data_file_root/media_types.csv")), + 90..91: Control(')'), + 91..92: NewLine, + 92..96: Ident("sort"), + 97..110: Ident("media_type_id"), + 110..111: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__set_ops_remove.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__set_ops_remove.snap index c37211e46612..500fb54acc83 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__set_ops_remove.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__set_ops_remove.snap @@ -12,35 +12,44 @@ TokenVec ( 28..31: Ident("rel"), 32..34: ArrowThin, 35..36: Control('('), - 36..39: Ident("rel"), - 40..41: Control('|'), - 42..47: Ident("group"), - 48..52: Ident("this"), - 53..54: Control('('), - 54..58: Ident("take"), - 59..60: Literal(Integer(1)), - 60..61: Control(')'), - 61..62: Control(')'), - 62..63: NewLine, - 63..64: NewLine, - 64..73: Ident("from_text"), - 74..80: Ident("format"), - 80..81: Control(':'), - 81..85: Ident("json"), - 86..138: Literal(String("{ \"columns\": [\"a\"], \"data\": [[1], [2], [2], [3]] }")), - 138..139: NewLine, - 139..147: Ident("distinct"), - 147..148: NewLine, - 148..154: Ident("remove"), - 155..156: Control('('), - 156..165: Ident("from_text"), - 166..172: Ident("format"), - 172..173: Control(':'), - 173..177: Ident("json"), - 178..220: Literal(String("{ \"columns\": [\"a\"], \"data\": [[1], [2]] }")), - 220..221: Control(')'), - 221..222: NewLine, - 222..226: Ident("sort"), - 227..228: Ident("a"), - 228..229: NewLine, + 36..40: Ident("from"), + 41..42: Ident("t"), + 43..44: Control('='), + 45..51: Ident("_param"), + 51..52: Control('.'), + 52..55: Ident("rel"), + 56..57: Control('|'), + 58..63: Ident("group"), + 64..65: Control('{'), + 65..66: Ident("t"), + 66..67: Control('.'), + 67..68: Control('*'), + 68..69: Control('}'), + 70..71: Control('('), + 71..75: Ident("take"), + 76..77: Literal(Integer(1)), + 77..78: Control(')'), + 78..79: Control(')'), + 79..80: NewLine, + 80..81: NewLine, + 81..90: Ident("from_text"), + 91..97: Ident("format"), + 97..98: Control(':'), + 98..102: Ident("json"), + 103..155: Literal(String("{ \"columns\": [\"a\"], \"data\": [[1], [2], [2], [3]] }")), + 155..156: NewLine, + 156..164: Ident("distinct"), + 164..165: NewLine, + 165..171: Ident("remove"), + 172..173: Control('('), + 173..182: Ident("from_text"), + 183..189: Ident("format"), + 189..190: Control(':'), + 190..194: Ident("json"), + 195..237: Literal(String("{ \"columns\": [\"a\"], \"data\": [[1], [2]] }")), + 237..238: Control(')'), + 238..239: NewLine, + 239..243: Ident("sort"), + 244..245: Ident("a"), + 245..246: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__sort.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__sort.snap index db84379ef343..043f3f1f8f20 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__sort.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__sort.snap @@ -7,72 +7,56 @@ TokenVec ( 0..12: Comment(" mssql:test"), 12..13: NewLine, 13..17: Ident("from"), - 18..20: Ident("db"), - 20..21: Control('.'), - 21..30: Ident("employees"), - 30..31: NewLine, - 31..37: Ident("select"), - 38..39: Control('{'), - 39..40: Ident("e"), - 41..42: Control('='), - 43..47: Ident("this"), - 47..48: Control('}'), - 48..49: NewLine, - 49..55: Ident("filter"), - 56..66: Ident("first_name"), - 67..69: Ne, - 70..80: Literal(String("Mitchell")), - 80..81: NewLine, - 81..85: Ident("sort"), - 86..87: Control('{'), - 87..97: Ident("first_name"), - 97..98: Control(','), - 99..108: Ident("last_name"), - 108..109: Control('}'), - 109..110: NewLine, - 110..111: NewLine, - 111..163: Comment(" joining may use HashMerge, which can undo ORDER BY"), - 163..164: NewLine, - 164..168: Ident("join"), - 169..170: Control('('), - 170..172: Ident("db"), - 172..173: Control('.'), - 173..182: Ident("employees"), - 183..184: Control('|'), - 185..191: Ident("select"), - 192..193: Control('{'), - 193..200: Ident("manager"), - 201..202: Control('='), - 203..207: Ident("this"), - 207..208: Control('}'), - 208..209: Control(')'), - 210..214: Ident("side"), - 214..215: Control(':'), - 215..219: Ident("left"), - 220..221: Control('('), - 221..222: Ident("e"), - 222..223: Control('.'), - 223..233: Ident("reports_to"), - 234..236: Eq, - 237..244: Ident("manager"), - 244..245: Control('.'), - 245..256: Ident("employee_id"), - 256..257: Control(')'), - 257..258: NewLine, - 258..259: NewLine, - 259..265: Ident("select"), - 266..267: Control('{'), - 267..268: Ident("e"), - 268..269: Control('.'), - 269..279: Ident("first_name"), - 279..280: Control(','), - 281..282: Ident("e"), - 282..283: Control('.'), - 283..292: Ident("last_name"), - 292..293: Control(','), - 294..301: Ident("manager"), - 301..302: Control('.'), - 302..312: Ident("first_name"), - 312..313: Control('}'), - 313..314: NewLine, + 18..19: Ident("e"), + 19..20: Control('='), + 20..29: Ident("employees"), + 29..30: NewLine, + 30..36: Ident("filter"), + 37..47: Ident("first_name"), + 48..50: Ne, + 51..61: Literal(String("Mitchell")), + 61..62: NewLine, + 62..66: Ident("sort"), + 67..68: Control('{'), + 68..78: Ident("first_name"), + 78..79: Control(','), + 80..89: Ident("last_name"), + 89..90: Control('}'), + 90..91: NewLine, + 91..92: NewLine, + 92..144: Comment(" joining may use HashMerge, which can undo ORDER BY"), + 144..145: NewLine, + 145..149: Ident("join"), + 150..157: Ident("manager"), + 157..158: Control('='), + 158..167: Ident("employees"), + 168..172: Ident("side"), + 172..173: Control(':'), + 173..177: Ident("left"), + 178..179: Control('('), + 179..180: Ident("e"), + 180..181: Control('.'), + 181..191: Ident("reports_to"), + 192..194: Eq, + 195..202: Ident("manager"), + 202..203: Control('.'), + 203..214: Ident("employee_id"), + 214..215: Control(')'), + 215..216: NewLine, + 216..217: NewLine, + 217..223: Ident("select"), + 224..225: Control('{'), + 225..226: Ident("e"), + 226..227: Control('.'), + 227..237: Ident("first_name"), + 237..238: Control(','), + 239..240: Ident("e"), + 240..241: Control('.'), + 241..250: Ident("last_name"), + 250..251: Control(','), + 252..259: Ident("manager"), + 259..260: Control('.'), + 260..270: Ident("first_name"), + 270..271: Control('}'), + 271..272: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__switch.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__switch.snap index 64e1afd21b90..1e0d88328391 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__switch.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__switch.snap @@ -9,40 +9,38 @@ TokenVec ( 76..88: Comment(" mssql:test"), 88..89: NewLine, 89..93: Ident("from"), - 94..96: Ident("db"), - 96..97: Control('.'), - 97..103: Ident("tracks"), - 103..104: NewLine, - 104..108: Ident("sort"), - 109..121: Ident("milliseconds"), - 121..122: NewLine, - 122..128: Ident("select"), - 129..136: Ident("display"), - 137..138: Control('='), - 139..143: Keyword("case"), - 144..145: Control('['), - 145..146: NewLine, - 150..158: Ident("composer"), - 159..161: Ne, - 162..166: Literal(Null), - 167..169: ArrowFat, - 170..178: Ident("composer"), - 178..179: Control(','), - 179..180: NewLine, - 184..192: Ident("genre_id"), - 193..194: Control('<'), - 195..197: Literal(Integer(17)), - 198..200: ArrowFat, - 201..214: Literal(String("no composer")), - 214..215: Control(','), - 215..216: NewLine, - 220..224: Literal(Boolean(true)), - 225..227: ArrowFat, - 228..247: Interpolation('f', "unknown composer"), - 247..248: NewLine, - 248..249: Control(']'), - 249..250: NewLine, - 250..254: Ident("take"), - 255..257: Literal(Integer(10)), - 257..258: NewLine, + 94..100: Ident("tracks"), + 100..101: NewLine, + 101..105: Ident("sort"), + 106..118: Ident("milliseconds"), + 118..119: NewLine, + 119..125: Ident("select"), + 126..133: Ident("display"), + 134..135: Control('='), + 136..140: Keyword("case"), + 141..142: Control('['), + 142..143: NewLine, + 147..155: Ident("composer"), + 156..158: Ne, + 159..163: Literal(Null), + 164..166: ArrowFat, + 167..175: Ident("composer"), + 175..176: Control(','), + 176..177: NewLine, + 181..189: Ident("genre_id"), + 190..191: Control('<'), + 192..194: Literal(Integer(17)), + 195..197: ArrowFat, + 198..211: Literal(String("no composer")), + 211..212: Control(','), + 212..213: NewLine, + 217..221: Literal(Boolean(true)), + 222..224: ArrowFat, + 225..244: Interpolation('f', "unknown composer"), + 244..245: NewLine, + 245..246: Control(']'), + 246..247: NewLine, + 247..251: Ident("take"), + 252..254: Literal(Integer(10)), + 254..255: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__take.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__take.snap index 91f27559c953..a51f5e4113c4 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__take.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__take.snap @@ -7,19 +7,17 @@ TokenVec ( 0..12: Comment(" mssql:test"), 12..13: NewLine, 13..17: Ident("from"), - 18..20: Ident("db"), - 20..21: Control('.'), - 21..27: Ident("tracks"), - 27..28: NewLine, - 28..32: Ident("sort"), - 33..34: Control('{'), - 34..35: Control('+'), - 35..43: Ident("track_id"), - 43..44: Control('}'), - 44..45: NewLine, - 45..49: Ident("take"), - 50..51: Literal(Integer(3)), - 51..53: Range { bind_left: true, bind_right: true }, - 53..54: Literal(Integer(5)), - 54..55: NewLine, + 18..24: Ident("tracks"), + 24..25: NewLine, + 25..29: Ident("sort"), + 30..31: Control('{'), + 31..32: Control('+'), + 32..40: Ident("track_id"), + 40..41: Control('}'), + 41..42: NewLine, + 42..46: Ident("take"), + 47..48: Literal(Integer(3)), + 48..50: Range { bind_left: true, bind_right: true }, + 50..51: Literal(Integer(5)), + 51..52: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__text_module.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__text_module.snap index 3ec462cd7d51..2f537562ff56 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__text_module.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__text_module.snap @@ -7,130 +7,128 @@ TokenVec ( 0..12: Comment(" mssql:test"), 12..13: NewLine, 13..17: Ident("from"), - 18..20: Ident("db"), - 20..21: Control('.'), - 21..27: Ident("albums"), - 27..28: NewLine, - 28..34: Ident("select"), - 35..36: Control('{'), - 36..37: NewLine, - 41..46: Ident("title"), - 46..47: Control(','), - 47..48: NewLine, - 52..68: Ident("title_and_spaces"), - 69..70: Control('='), - 71..85: Interpolation('f', " {title} "), - 85..86: Control(','), - 86..87: NewLine, - 91..94: Ident("low"), - 95..96: Control('='), - 97..102: Ident("title"), - 103..104: Control('|'), - 105..109: Ident("text"), - 109..110: Control('.'), - 110..115: Ident("lower"), - 115..116: Control(','), - 116..117: NewLine, - 121..123: Ident("up"), - 124..125: Control('='), - 126..131: Ident("title"), - 132..133: Control('|'), - 134..138: Ident("text"), - 138..139: Control('.'), - 139..144: Ident("upper"), - 144..145: Control(','), - 145..146: NewLine, - 150..158: Ident("ltrimmed"), - 159..160: Control('='), - 161..166: Ident("title"), - 167..168: Control('|'), - 169..173: Ident("text"), - 173..174: Control('.'), - 174..179: Ident("ltrim"), - 179..180: Control(','), - 180..181: NewLine, - 185..193: Ident("rtrimmed"), - 194..195: Control('='), - 196..201: Ident("title"), - 202..203: Control('|'), - 204..208: Ident("text"), - 208..209: Control('.'), - 209..214: Ident("rtrim"), - 214..215: Control(','), - 215..216: NewLine, - 220..227: Ident("trimmed"), - 228..229: Control('='), - 230..235: Ident("title"), - 236..237: Control('|'), - 238..242: Ident("text"), - 242..243: Control('.'), - 243..247: Ident("trim"), - 247..248: Control(','), - 248..249: NewLine, - 253..256: Ident("len"), - 257..258: Control('='), - 259..264: Ident("title"), - 265..266: Control('|'), - 267..271: Ident("text"), - 271..272: Control('.'), - 272..278: Ident("length"), - 278..279: Control(','), - 279..280: NewLine, - 284..288: Ident("subs"), - 289..290: Control('='), - 291..296: Ident("title"), - 297..298: Control('|'), - 299..303: Ident("text"), - 303..304: Control('.'), - 304..311: Ident("extract"), - 312..313: Literal(Integer(2)), - 314..315: Literal(Integer(5)), - 315..316: Control(','), - 316..317: NewLine, - 321..328: Ident("replace"), - 329..330: Control('='), - 331..336: Ident("title"), - 337..338: Control('|'), - 339..343: Ident("text"), - 343..344: Control('.'), - 344..351: Ident("replace"), - 352..356: Literal(String("al")), - 357..363: Literal(String("PIKA")), - 363..364: Control(','), - 364..365: NewLine, - 365..366: Control('}'), - 366..367: NewLine, - 367..371: Ident("sort"), - 372..373: Control('{'), - 373..378: Ident("title"), - 378..379: Control('}'), - 379..380: NewLine, - 380..386: Ident("filter"), - 387..388: Control('('), - 388..393: Ident("title"), - 394..395: Control('|'), - 396..400: Ident("text"), - 400..401: Control('.'), - 401..412: Ident("starts_with"), - 413..420: Literal(String("Black")), - 420..421: Control(')'), - 422..424: Or, - 425..426: Control('('), - 426..431: Ident("title"), - 432..433: Control('|'), - 434..438: Ident("text"), - 438..439: Control('.'), - 439..447: Ident("contains"), - 448..457: Literal(String("Sabbath")), - 457..458: Control(')'), - 459..461: Or, - 462..463: Control('('), - 463..468: Ident("title"), - 469..470: Control('|'), - 471..475: Ident("text"), - 475..476: Control('.'), - 476..485: Ident("ends_with"), - 486..490: Literal(String("os")), - 490..491: Control(')'), - 491..492: NewLine, + 18..24: Ident("albums"), + 24..25: NewLine, + 25..31: Ident("select"), + 32..33: Control('{'), + 33..34: NewLine, + 38..43: Ident("title"), + 43..44: Control(','), + 44..45: NewLine, + 49..65: Ident("title_and_spaces"), + 66..67: Control('='), + 68..82: Interpolation('f', " {title} "), + 82..83: Control(','), + 83..84: NewLine, + 88..91: Ident("low"), + 92..93: Control('='), + 94..99: Ident("title"), + 100..101: Control('|'), + 102..106: Ident("text"), + 106..107: Control('.'), + 107..112: Ident("lower"), + 112..113: Control(','), + 113..114: NewLine, + 118..120: Ident("up"), + 121..122: Control('='), + 123..128: Ident("title"), + 129..130: Control('|'), + 131..135: Ident("text"), + 135..136: Control('.'), + 136..141: Ident("upper"), + 141..142: Control(','), + 142..143: NewLine, + 147..155: Ident("ltrimmed"), + 156..157: Control('='), + 158..163: Ident("title"), + 164..165: Control('|'), + 166..170: Ident("text"), + 170..171: Control('.'), + 171..176: Ident("ltrim"), + 176..177: Control(','), + 177..178: NewLine, + 182..190: Ident("rtrimmed"), + 191..192: Control('='), + 193..198: Ident("title"), + 199..200: Control('|'), + 201..205: Ident("text"), + 205..206: Control('.'), + 206..211: Ident("rtrim"), + 211..212: Control(','), + 212..213: NewLine, + 217..224: Ident("trimmed"), + 225..226: Control('='), + 227..232: Ident("title"), + 233..234: Control('|'), + 235..239: Ident("text"), + 239..240: Control('.'), + 240..244: Ident("trim"), + 244..245: Control(','), + 245..246: NewLine, + 250..253: Ident("len"), + 254..255: Control('='), + 256..261: Ident("title"), + 262..263: Control('|'), + 264..268: Ident("text"), + 268..269: Control('.'), + 269..275: Ident("length"), + 275..276: Control(','), + 276..277: NewLine, + 281..285: Ident("subs"), + 286..287: Control('='), + 288..293: Ident("title"), + 294..295: Control('|'), + 296..300: Ident("text"), + 300..301: Control('.'), + 301..308: Ident("extract"), + 309..310: Literal(Integer(2)), + 311..312: Literal(Integer(5)), + 312..313: Control(','), + 313..314: NewLine, + 318..325: Ident("replace"), + 326..327: Control('='), + 328..333: Ident("title"), + 334..335: Control('|'), + 336..340: Ident("text"), + 340..341: Control('.'), + 341..348: Ident("replace"), + 349..353: Literal(String("al")), + 354..360: Literal(String("PIKA")), + 360..361: Control(','), + 361..362: NewLine, + 362..363: Control('}'), + 363..364: NewLine, + 364..368: Ident("sort"), + 369..370: Control('{'), + 370..375: Ident("title"), + 375..376: Control('}'), + 376..377: NewLine, + 377..383: Ident("filter"), + 384..385: Control('('), + 385..390: Ident("title"), + 391..392: Control('|'), + 393..397: Ident("text"), + 397..398: Control('.'), + 398..409: Ident("starts_with"), + 410..417: Literal(String("Black")), + 417..418: Control(')'), + 419..421: Or, + 422..423: Control('('), + 423..428: Ident("title"), + 429..430: Control('|'), + 431..435: Ident("text"), + 435..436: Control('.'), + 436..444: Ident("contains"), + 445..454: Literal(String("Sabbath")), + 454..455: Control(')'), + 456..458: Or, + 459..460: Control('('), + 460..465: Ident("title"), + 466..467: Control('|'), + 468..472: Ident("text"), + 472..473: Control('.'), + 473..482: Ident("ends_with"), + 483..487: Literal(String("os")), + 487..488: Control(')'), + 488..489: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__window.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__window.snap index 88fc952e0711..0b66793a09df 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__window.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__window.snap @@ -13,68 +13,66 @@ TokenVec ( 296..337: Comment(" postgres:skip problems with DISTINCT ON"), 337..338: NewLine, 338..342: Ident("from"), - 343..345: Ident("db"), - 345..346: Control('.'), - 346..352: Ident("tracks"), - 352..353: NewLine, - 353..358: Ident("group"), - 359..367: Ident("genre_id"), - 368..369: Control('('), - 369..370: NewLine, - 372..376: Ident("sort"), - 377..389: Ident("milliseconds"), - 389..390: NewLine, - 392..398: Ident("derive"), - 399..400: Control('{'), - 400..401: NewLine, - 405..408: Ident("num"), - 409..410: Control('='), - 411..421: Ident("row_number"), - 422..426: Ident("this"), - 426..427: Control(','), - 427..428: NewLine, - 432..437: Ident("total"), - 438..439: Control('='), - 440..445: Ident("count"), - 446..450: Ident("this"), - 450..451: Control(','), - 451..452: NewLine, - 456..464: Ident("last_val"), - 465..466: Control('='), - 467..471: Ident("last"), - 472..480: Ident("track_id"), - 480..481: Control(','), - 481..482: NewLine, - 484..485: Control('}'), - 485..486: NewLine, - 488..492: Ident("take"), - 493..495: Literal(Integer(10)), - 495..496: NewLine, - 496..497: Control(')'), - 497..498: NewLine, - 498..502: Ident("sort"), - 503..504: Control('{'), - 504..512: Ident("genre_id"), - 512..513: Control(','), - 514..526: Ident("milliseconds"), - 526..527: Control('}'), - 527..528: NewLine, - 528..534: Ident("select"), - 535..536: Control('{'), - 536..544: Ident("track_id"), - 544..545: Control(','), - 546..554: Ident("genre_id"), - 554..555: Control(','), - 556..559: Ident("num"), - 559..560: Control(','), - 561..566: Ident("total"), - 566..567: Control(','), - 568..576: Ident("last_val"), - 576..577: Control('}'), - 577..578: NewLine, - 578..584: Ident("filter"), - 585..593: Ident("genre_id"), - 594..596: Gte, - 597..599: Literal(Integer(22)), - 599..600: NewLine, + 343..349: Ident("tracks"), + 349..350: NewLine, + 350..355: Ident("group"), + 356..364: Ident("genre_id"), + 365..366: Control('('), + 366..367: NewLine, + 369..373: Ident("sort"), + 374..386: Ident("milliseconds"), + 386..387: NewLine, + 389..395: Ident("derive"), + 396..397: Control('{'), + 397..398: NewLine, + 402..405: Ident("num"), + 406..407: Control('='), + 408..418: Ident("row_number"), + 419..423: Ident("this"), + 423..424: Control(','), + 424..425: NewLine, + 429..434: Ident("total"), + 435..436: Control('='), + 437..442: Ident("count"), + 443..447: Ident("this"), + 447..448: Control(','), + 448..449: NewLine, + 453..461: Ident("last_val"), + 462..463: Control('='), + 464..468: Ident("last"), + 469..477: Ident("track_id"), + 477..478: Control(','), + 478..479: NewLine, + 481..482: Control('}'), + 482..483: NewLine, + 485..489: Ident("take"), + 490..492: Literal(Integer(10)), + 492..493: NewLine, + 493..494: Control(')'), + 494..495: NewLine, + 495..499: Ident("sort"), + 500..501: Control('{'), + 501..509: Ident("genre_id"), + 509..510: Control(','), + 511..523: Ident("milliseconds"), + 523..524: Control('}'), + 524..525: NewLine, + 525..531: Ident("select"), + 532..533: Control('{'), + 533..541: Ident("track_id"), + 541..542: Control(','), + 543..551: Ident("genre_id"), + 551..552: Control(','), + 553..556: Ident("num"), + 556..557: Control(','), + 558..563: Ident("total"), + 563..564: Control(','), + 565..573: Ident("last_val"), + 573..574: Control('}'), + 574..575: NewLine, + 575..581: Ident("filter"), + 582..590: Ident("genre_id"), + 591..593: Gte, + 594..596: Literal(Integer(22)), + 596..597: NewLine, ) diff --git a/prqlc/prqlc/tests/integration/sql.rs b/prqlc/prqlc/tests/integration/sql.rs index b215632374c4..0b8b28575d37 100644 --- a/prqlc/prqlc/tests/integration/sql.rs +++ b/prqlc/prqlc/tests/integration/sql.rs @@ -25,7 +25,7 @@ fn compile_with_sql_dialect(prql: &str, dialect: sql::Dialect) -> Result 0, ltz = !(a > 0), @@ -381,7 +381,7 @@ fn test_precedence_04() { fn test_precedence_05() { assert_snapshot!(compile( r###" - from db.numbers + from numbers derive x = (y - z) select { c - (a + b), @@ -419,7 +419,7 @@ fn test_precedence_05() { // FIXME: right associativity of `pow` is not implemented yet fn test_pow_is_right_associative() { assert_snapshot!(compile(r#" - from db.numbers + from numbers select { c ** a ** b } @@ -435,8 +435,8 @@ fn test_pow_is_right_associative() { #[test] fn test_append() { assert_snapshot!(compile(r###" - from db.employees - append db.managers + from employees + append managers "###).unwrap(), @r###" SELECT * @@ -451,11 +451,11 @@ fn test_append() { "###); assert_snapshot!(compile(r###" - from db.employees + from employees select {name, cost = salary} take 3 append ( - from db.employees + from employees select {name, cost = salary + bonuses} take 10 ) @@ -491,10 +491,10 @@ fn test_append() { assert_snapshot!(compile(r###" let distinct = rel -> (_param.rel | group this (take 1)) - let union = func bottom top -> (top | append bottom | distinct) + let union = func `default_db.bottom` top -> (top | append bottom | distinct) - from db.employees - union db.managers + from employees + union (from managers) "###).unwrap(), @r###" SELECT * @@ -510,11 +510,11 @@ fn test_append() { assert_snapshot!(compile(r###" let distinct = rel -> (_param.rel | group this (take 1)) - let union = func bottom top -> (top | append bottom | distinct) + let union = func `default_db.bottom` top -> (top | append bottom | distinct) - from db.employees - append db.managers - union db.all_employees_of_some_other_company + from employees + append managers + union all_employees_of_some_other_company "###).unwrap(), @r###" SELECT * @@ -538,8 +538,8 @@ fn test_append() { #[test] fn test_remove_01() { assert_snapshot!(compile(r#" - from db.albums - remove db.artists + from albums + remove artists "#).unwrap(), @r###" SELECT @@ -559,10 +559,10 @@ fn test_remove_01() { #[test] fn test_remove_02() { assert_snapshot!(compile(r#" - from db.album + from album select artist_id remove ( - from db.artist | select artist_id + from artist | select artist_id ) "#).unwrap(), @r###" @@ -589,10 +589,10 @@ fn test_remove_02() { #[test] fn test_remove_03() { assert_snapshot!(compile(r#" - from db.album + from album select {artist_id, title} remove ( - from db.artist | select artist_id + from artist | select artist_id ) "#).unwrap(), @r###" @@ -619,8 +619,8 @@ fn test_remove_04() { assert_snapshot!(compile(r#" prql target:sql.sqlite - from db.album - remove db.artist + from album + remove artist "#).unwrap_err(), @r###" Error: The dialect SQLiteDialect does not support EXCEPT ALL @@ -634,12 +634,12 @@ fn test_remove_05() { assert_snapshot!(compile(r#" prql target:sql.sqlite - let distinct = rel -> (_param.rel | group this (take 1)) - let except = func bottom top -> (top | distinct | remove bottom) + let distinct = rel -> (from t = _param.rel | group {t.*} (take 1)) + let except = `default_db.bottom` top -> (top | distinct | remove bottom) - from db.album + from album select {artist_id, title} - except (from db.artist | select {artist_id, name}) + except (from artist | select {artist_id, name}) "#).unwrap(), @r###" WITH table_0 AS ( @@ -668,17 +668,17 @@ fn test_remove_06() { assert_snapshot!(compile(r#" prql target:sql.sqlite - let distinct = rel -> (_param.rel | group this (take 1)) - let except = func bottom top -> (top | distinct | remove bottom) + let distinct = rel -> (from t = _param.rel | group {t.*} (take 1)) + let except = func `default_db.bottom` top -> (top | distinct | remove bottom) - from db.album - except db.artist + from album + except artist "#).unwrap(), @r###" SELECT * FROM - album + album AS t EXCEPT SELECT * @@ -691,8 +691,8 @@ fn test_remove_06() { #[test] fn test_intersect_01() { assert_snapshot!(compile(r#" - from db.album - intersect db.artist + from album + intersect artist "#).unwrap(), @r###" SELECT @@ -712,10 +712,10 @@ fn test_intersect_01() { #[test] fn test_intersect_02() { assert_snapshot!(compile(r#" - from db.album + from album select artist_id intersect ( - from db.artist | select artist_id + from artist | select artist_id ) "#).unwrap(), @r###" @@ -744,11 +744,11 @@ fn test_intersect_03() { assert_snapshot!(compile(r#" let distinct = rel -> (_param.rel | group this (take 1)) - from db.album + from album select artist_id distinct intersect ( - from db.artist | select artist_id + from artist | select artist_id ) distinct "#).unwrap(), @@ -784,10 +784,10 @@ fn test_intersect_04() { assert_snapshot!(compile(r#" let distinct = rel -> (_param.rel | group this (take 1)) - from db.album + from album select artist_id intersect ( - from db.artist | select artist_id + from artist | select artist_id ) distinct "#).unwrap(), @@ -823,11 +823,11 @@ fn test_intersect_05() { assert_snapshot!(compile(r#" let distinct = rel -> (_param.rel | group this (take 1)) - from db.album + from album select artist_id distinct intersect ( - from db.artist | select artist_id + from artist | select artist_id ) "#).unwrap(), @r###" @@ -856,8 +856,8 @@ fn test_intersect_06() { assert_snapshot!(compile(r#" prql target:sql.sqlite - from db.album - intersect db.artist + from album + intersect artist "#).unwrap_err(), @r###" Error: The dialect SQLiteDialect does not support INTERSECT ALL @@ -869,8 +869,8 @@ fn test_intersect_06() { #[test] fn test_intersect_07() { assert_snapshot!(compile(r#" - from ds2 = db.foo.t1 - join side:inner ds1 = db.bar.t2 (ds2.idx==ds1.idx) + from ds2 = foo.t1 + join side:inner ds1 = bar.t2 (ds2.idx==ds1.idx) aggregate { count this } "#).unwrap(), @r###" @@ -887,7 +887,7 @@ fn test_intersect_07() { fn test_rn_ids_are_unique() { // this is wrong, output will have duplicate y_id and x_id assert_snapshot!((compile(r###" - from db.y_orig + from y_orig group {y_id} ( take 2 # take 1 uses `distinct` instead of partitioning, which might be a separate bug ) @@ -926,10 +926,10 @@ fn test_quoting() { assert_snapshot!((compile(r###" prql target:sql.postgres let UPPER = ( - from db.lower + default_db.lower ) - UPPER - join db.`some_schema.tablename` (==id) + from UPPER + join `some_schema.tablename` (==id) derive `from` = 5 "###).unwrap()), @r###" WITH "UPPER" AS ( @@ -949,7 +949,8 @@ fn test_quoting() { // GH-1493 let query = r###" - from db.`dir/*.parquet` + from `dir/*.parquet` + # join files=`*.parquet` (==id) "###; assert_snapshot!((compile(query).unwrap()), @r###" SELECT @@ -961,22 +962,22 @@ fn test_quoting() { // GH-#852 assert_snapshot!((compile(r###" prql target:sql.bigquery - from db.`db.schema.table` - join db.`db.schema.table2` (==id) - join c = db.`db.schema.t-able` (`db.schema.table`.id == c.id) + from `schema.table` + join `schema.table2` (==id) + join c = `schema.t-able` (`schema.table`.id == c.id) "###).unwrap()), @r###" SELECT - `db.schema.table`.*, - `db.schema.table2`.*, + `schema.table`.*, + `schema.table2`.*, c.* FROM - `db.schema.table` - JOIN `db.schema.table2` ON `db.schema.table`.id = `db.schema.table2`.id - JOIN `db.schema.t-able` AS c ON `db.schema.table`.id = c.id + `schema.table` + JOIN `schema.table2` ON `schema.table`.id = `schema.table2`.id + JOIN `schema.t-able` AS c ON `schema.table`.id = c.id "###); assert_snapshot!((compile(r###" - from db.table + from table select `first name` "###).unwrap()), @r###" SELECT @@ -986,20 +987,19 @@ fn test_quoting() { "###); assert_snapshot!((compile(r###" - from db.Assessment - select {as = this} + from as = Assessment "###).unwrap()), @r###" SELECT * FROM - "Assessment" + "Assessment" AS "as" "###); } #[test] fn test_sorts_01() { assert_snapshot!((compile(r###" - from db.invoices + from invoices sort {issued_at, -amount, +num_of_articles} "### ).unwrap()), @r###" @@ -1014,7 +1014,7 @@ fn test_sorts_01() { "###); assert_snapshot!((compile(r#" - from db.x + from x derive somefield = "something" sort {somefield} select {renamed = somefield} @@ -1042,11 +1042,11 @@ fn test_sorts_02() { assert_snapshot!((compile(r###" let x = ( - from db.table + from table sort index select {fieldA} ) - x + from x "### ).unwrap()), @r###" WITH table_0 AS ( @@ -1073,8 +1073,8 @@ fn test_sorts_02() { // TODO: this is invalid SQL: a._expr_0 does not exist assert_snapshot!((compile(r#" - from db.a - join db.b side:left (==col) + from a + join b side:left (==col) sort a.col select !{a.col} take 5 @@ -1105,7 +1105,7 @@ fn test_sorts_02() { #[test] fn test_numbers() { let query = r###" - from db.numbers + from numbers select { v = 5.000_000_1, w = 5_000, @@ -1130,7 +1130,7 @@ fn test_numbers() { #[test] fn test_ranges() { assert_snapshot!((compile(r###" - from db.employees + from employees derive { close = (distance | in ..50), middle = (distance | in 50..100), @@ -1152,7 +1152,7 @@ fn test_ranges() { #[test] fn test_in_values_01() { assert_snapshot!((compile(r#" - from db.employees + from employees filter (title | in ["Sales Manager", "Sales Support Agent"]) filter (employee_id | in [1, 2, 5]) "#).unwrap()), @r#" @@ -1172,7 +1172,7 @@ fn test_in_values_02() { assert_snapshot!((compile(r#" let allowed_titles = ["Sales Manager", "Sales Support Agent"] - from db.employees + from employees derive {allowed_ids = [1, 2, 5]} filter (title | in allowed_titles) filter (title | in allowed_ids) @@ -1190,7 +1190,7 @@ fn test_in_values_02() { #[ignore] // unimplemented, column ref type resolution required fn test_in_values_03() { assert_snapshot!((compile(r#" - from db.employees + from employees derive allowed_titles = case [ is_guest => ["Sales Manager"], true => ["Sales Manager", "Sales Support Agent"], @@ -1209,7 +1209,7 @@ fn test_in_values_03() { #[test] fn test_not_in_values() { assert_snapshot!((compile(r#" - from db.employees + from employees filter !(title | in ["Sales Manager", "Sales Support Agent"]) "#).unwrap()), @r#" SELECT @@ -1224,7 +1224,7 @@ fn test_not_in_values() { #[test] fn test_interval() { let query = r###" - from db.projects + from projects derive first_check_in = start + 10days "###; @@ -1239,7 +1239,7 @@ fn test_interval() { let query = r###" prql target:sql.postgres - from db.projects + from projects derive first_check_in = start + 10days "###; assert_snapshot!((compile(query).unwrap()), @r###" @@ -1254,7 +1254,7 @@ fn test_interval() { #[test] fn test_dates() { assert_snapshot!((compile(r###" - from db.to_do_empty_table + from to_do_empty_table derive { date = @2011-02-01, timestamp = @2011-02-01T10:00, @@ -1275,7 +1275,7 @@ fn test_dates() { #[test] fn test_window_functions_00() { assert_snapshot!((compile(r###" - from db.employees + from employees group last_name ( derive {count first_name} ) @@ -1291,9 +1291,8 @@ fn test_window_functions_00() { #[test] fn test_window_functions_02() { let query = r#" - from db.cust_order - select {co = this} - join (db.order_line | select {ol = this}) (==order_id) + from co=cust_order + join ol=order_line (==order_id) derive { order_month = s"TO_CHAR({co.order_date}, '%Y-%m')", order_day = s"TO_CHAR({co.order_date}, '%Y-%m-%d')", @@ -1318,23 +1317,17 @@ fn test_window_functions_02() { assert_snapshot!((compile(query).unwrap()), @r###" WITH table_0 AS ( SELECT - * - FROM - order_line - ), - table_1 AS ( - SELECT - TO_CHAR(cust_order.order_date, '%Y-%m') AS order_month, - TO_CHAR(cust_order.order_date, '%Y-%m-%d') AS order_day, - COUNT(DISTINCT cust_order.order_id) AS num_orders, + TO_CHAR(co.order_date, '%Y-%m') AS order_month, + TO_CHAR(co.order_date, '%Y-%m-%d') AS order_day, + COUNT(DISTINCT co.order_id) AS num_orders, COUNT(*) AS num_books, - COALESCE(SUM(table_0.price), 0) AS total_price + COALESCE(SUM(ol.price), 0) AS total_price FROM - cust_order - JOIN table_0 ON cust_order.order_id = table_0.order_id + cust_order AS co + JOIN order_line AS ol ON co.order_id = ol.order_id GROUP BY - TO_CHAR(cust_order.order_date, '%Y-%m'), - TO_CHAR(cust_order.order_date, '%Y-%m-%d') + TO_CHAR(co.order_date, '%Y-%m'), + TO_CHAR(co.order_date, '%Y-%m-%d') ) SELECT order_month, @@ -1352,7 +1345,7 @@ fn test_window_functions_02() { order_day ) AS num_books_last_week FROM - table_1 + table_0 ORDER BY order_day "###); @@ -1363,7 +1356,7 @@ fn test_window_functions_03() { // lag must be recognized as window function, even outside of group context // rank must not have two OVER clauses let query = r###" - from db.daily_orders + from daily_orders derive {last_week = lag 7 num_orders} derive {first_count = first num_orders} derive {last_count = last num_orders} @@ -1388,7 +1381,7 @@ fn test_window_functions_03() { fn test_window_functions_04() { // sort does not affects into groups, group undoes sorting let query = r###" - from db.daily_orders + from daily_orders sort day group month (derive {total_month = rank day}) derive {last_week = lag 7 num_orders} @@ -1408,7 +1401,7 @@ fn test_window_functions_04() { fn test_window_functions_05() { // sort does not leak out of groups let query = r###" - from db.daily_orders + from daily_orders sort day group month (sort num_orders | window expanding:true (derive {rank day})) derive {num_orders_last_week = lag 7 num_orders} @@ -1431,7 +1424,7 @@ fn test_window_functions_05() { fn test_window_functions_06() { // detect sum as a window function, even without group or window assert_snapshot!((compile(r###" - from db.foo + from foo derive {a = sum b} group c ( derive {d = sum b} @@ -1449,7 +1442,7 @@ fn test_window_functions_06() { #[test] fn test_window_functions_07() { assert_snapshot!((compile(r###" - from db.foo + from foo window expanding:true ( derive {running_total = sum b} ) @@ -1465,7 +1458,7 @@ fn test_window_functions_07() { #[test] fn test_window_functions_08() { assert_snapshot!((compile(r###" - from db.foo + from foo window rolling:3 ( derive {last_three = sum b} ) @@ -1481,7 +1474,7 @@ fn test_window_functions_08() { #[test] fn test_window_functions_09() { assert_snapshot!((compile(r###" - from db.foo + from foo window rows:0..4 ( derive {next_four_rows = sum b} ) @@ -1500,7 +1493,7 @@ fn test_window_functions_09() { #[test] fn test_window_functions_10() { assert_snapshot!((compile(r###" - from db.foo + from foo sort day window range:-4..4 ( derive {next_four_days = sum b} @@ -1522,7 +1515,7 @@ fn test_window_functions_10() { #[test] fn test_window_functions_11() { assert_snapshot!((compile(r###" - from db.employees + from employees sort age derive {num = row_number this} "###).unwrap()), @r###" @@ -1544,7 +1537,7 @@ fn test_window_functions_12() { // window params need to be simple expressions assert_snapshot!((compile(r###" - from db.x + from x derive {b = lag 1 a} window ( sort b @@ -1571,7 +1564,7 @@ fn test_window_functions_12() { "###); assert_snapshot!((compile(r###" - from db.x + from x derive {b = lag 1 a} group b ( derive {c = lag 1 a} @@ -1597,7 +1590,7 @@ fn test_window_functions_13() { // window params need to be simple expressions assert_snapshot!((compile(r###" - from db.tracks + from tracks group {album_id} ( window (derive {grp = milliseconds - (row_number this)}) ) @@ -1624,7 +1617,7 @@ fn test_window_functions_13() { #[test] fn test_window_single_item_range() { assert_snapshot!(compile(r###" - from db.login_event + from login_event window rows:1..1 ( sort time_upload derive { @@ -1648,7 +1641,7 @@ fn test_window_single_item_range() { #[test] fn test_name_resolving() { let query = r###" - from db.numbers + from numbers derive x = 5 select {y = 6, z = x + y + a} "###; @@ -1664,7 +1657,7 @@ fn test_name_resolving() { #[test] fn test_strings() { let query = r#" - from db.empty_table_to_do + from empty_table_to_do select { x = "two households'", y = 'two households"', @@ -1699,14 +1692,14 @@ fn test_strings() { fn test_filter() { // https://github.com/PRQL/prql/issues/469 let query = r###" - from db.employees + from employees filter {age > 25, age < 40} "###; assert!(compile(query).is_err()); assert_snapshot!((compile(r###" - from db.employees + from employees filter age > 25 && age < 40 "###).unwrap()), @r###" SELECT @@ -1719,7 +1712,7 @@ fn test_filter() { "###); assert_snapshot!((compile(r###" - from db.employees + from employees filter age > 25 filter age < 40 "###).unwrap()), @r###" @@ -1736,7 +1729,7 @@ fn test_filter() { #[test] fn test_nulls_01() { assert_snapshot!((compile(r###" - from db.employees + from employees select amount = null "###).unwrap()), @r###" SELECT @@ -1750,7 +1743,7 @@ fn test_nulls_01() { fn test_nulls_02() { // coalesce assert_snapshot!((compile(r###" - from db.employees + from employees derive amount = amount + 2 ?? 3 * 5 "###).unwrap()), @r###" SELECT @@ -1765,7 +1758,7 @@ fn test_nulls_02() { fn test_nulls_03() { // IS NULL assert_snapshot!((compile(r###" - from db.employees + from employees filter first_name == null && null == last_name "###).unwrap()), @r###" SELECT @@ -1782,7 +1775,7 @@ fn test_nulls_03() { fn test_nulls_04() { // IS NOT NULL assert_snapshot!((compile(r###" - from db.employees + from employees filter first_name != null && null != last_name "###).unwrap()), @r###" SELECT @@ -1798,7 +1791,7 @@ fn test_nulls_04() { #[test] fn test_take_01() { assert_snapshot!((compile(r###" - from db.employees + from employees take ..10 "###).unwrap()), @r###" SELECT @@ -1813,7 +1806,7 @@ fn test_take_01() { #[test] fn test_take_02() { assert_snapshot!((compile(r###" - from db.employees + from employees take 5..10 "###).unwrap()), @r###" SELECT @@ -1828,7 +1821,7 @@ fn test_take_02() { #[test] fn test_take_03() { assert_snapshot!((compile(r###" - from db.employees + from employees take 5.. "###).unwrap()), @r###" SELECT @@ -1841,7 +1834,7 @@ fn test_take_03() { #[test] fn test_take_04() { assert_snapshot!((compile(r###" - from db.employees + from employees take 5..5 "###).unwrap()), @r###" SELECT @@ -1857,7 +1850,7 @@ fn test_take_04() { fn test_take_05() { // should be one SELECT assert_snapshot!((compile(r###" - from db.employees + from employees take 11..20 take 1..5 "###).unwrap()), @r###" @@ -1874,7 +1867,7 @@ fn test_take_05() { fn test_take_06() { // should be two SELECTs assert_snapshot!((compile(r###" - from db.employees + from employees take 11..20 sort name take 1..5 @@ -1901,7 +1894,7 @@ fn test_take_06() { #[test] fn test_take_07() { assert_snapshot!((compile(r###" - from db.employees + from employees take 0..1 "###).unwrap_err()), @r###" Error: @@ -1917,7 +1910,7 @@ fn test_take_07() { #[test] fn test_take_08() { assert_snapshot!((compile(r###" - from db.employees + from employees take (-1..) "###).unwrap_err()), @r###" Error: @@ -1933,7 +1926,7 @@ fn test_take_08() { #[test] fn test_take_09() { assert_snapshot!((compile(r###" - from db.employees + from employees select a take 5..5.6 "###).unwrap_err()), @r###" @@ -1950,7 +1943,7 @@ fn test_take_09() { #[test] fn test_take_10() { assert_snapshot!((compile(r###" - from db.employees + from employees take (-1) "###).unwrap_err()), @r###" Error: @@ -1968,7 +1961,7 @@ fn test_take_mssql() { assert_snapshot!((compile(r#" prql target:sql.mssql - from db.tracks + from tracks take 3..5 "#).unwrap()), @r###" SELECT @@ -1987,7 +1980,7 @@ fn test_take_mssql() { assert_snapshot!((compile(r#" prql target:sql.mssql - from db.tracks + from tracks take ..5 "#).unwrap()), @r###" SELECT @@ -2006,7 +1999,7 @@ fn test_take_mssql() { assert_snapshot!((compile(r#" prql target:sql.mssql - from db.tracks + from tracks take 3.. "#).unwrap()), @r###" SELECT @@ -2020,7 +2013,7 @@ fn test_take_mssql() { fn test_distinct_01() { // window functions cannot materialize into where statement: CTE is needed assert_snapshot!((compile(r###" - from db.employees + from employees derive {rn = row_number id} filter rn > 2 "###).unwrap()), @r###" @@ -2044,7 +2037,7 @@ fn test_distinct_01() { fn test_distinct_02() { // basic distinct assert_snapshot!((compile(r###" - from db.employees + from employees select first_name group first_name (take 1) "###).unwrap()), @r###" @@ -2059,7 +2052,7 @@ fn test_distinct_02() { fn test_distinct_03() { // distinct on two columns assert_snapshot!((compile(r###" - from db.employees + from employees select {first_name, last_name} group {first_name, last_name} (take 1) "###).unwrap()), @r###" @@ -2075,7 +2068,7 @@ fn test_distinct_04() { // We want distinct only over first_name and last_name, so we can't use a // `DISTINCT *` here. assert_snapshot!((compile(r###" - from db.employees + from employees group {first_name, last_name} (take 1) "###).unwrap()), @r###" WITH table_0 AS ( @@ -2097,7 +2090,7 @@ fn test_distinct_04() { fn test_distinct_05() { // Check that a different order doesn't stop distinct from being used. assert!(compile( - "from db.employees | select {first_name, last_name} | group {last_name, first_name} (take 1)" + "from employees | select {first_name, last_name} | group {last_name, first_name} (take 1)" ) .unwrap() .contains("DISTINCT")); @@ -2106,7 +2099,7 @@ fn test_distinct_05() { fn test_distinct_06() { // head assert_snapshot!((compile(r###" - from db.employees + from employees group department (take 3) "###).unwrap()), @r###" WITH table_0 AS ( @@ -2127,7 +2120,7 @@ fn test_distinct_06() { #[test] fn test_distinct_07() { assert_snapshot!((compile(r###" - from db.employees + from employees group department (sort salary | take 2..3) "###).unwrap()), @r###" WITH table_0 AS ( @@ -2152,7 +2145,7 @@ fn test_distinct_07() { #[test] fn test_distinct_08() { assert_snapshot!((compile(r###" - from db.employees + from employees group department (sort salary | take 4..4) "###).unwrap()), @r###" WITH table_0 AS ( @@ -2178,7 +2171,7 @@ fn test_distinct_08() { #[test] fn test_distinct_09() { assert_snapshot!(compile(" - from db.invoices + from invoices select {billing_country, billing_city} group {billing_city} ( take 1 @@ -2210,7 +2203,7 @@ fn test_distinct_on_01() { assert_snapshot!((compile(r###" prql target:sql.postgres - from db.employees + from employees group department ( sort age take 1 @@ -2231,7 +2224,7 @@ fn test_distinct_on_02() { assert_snapshot!((compile(r###" prql target:sql.duckdb - from db.x + from x select {class, begins} group {begins} (take 1) "###).unwrap()), @r###" @@ -2248,7 +2241,7 @@ fn test_distinct_on_03() { assert_snapshot!((compile(r###" prql target:sql.duckdb - from db.tab1 + from tab1 group col1 ( take 1 ) @@ -2273,8 +2266,8 @@ fn test_distinct_on_04() { assert_snapshot!((compile(r###" prql target:sql.duckdb - from db.a - join db.b (b.a_id == a.id) + from a + join b (b.a_id == a.id) group {a.id} ( sort b.x take 1 @@ -2298,7 +2291,7 @@ fn test_group_take_n_01() { assert_snapshot!((compile(r###" prql target:sql.postgres - from db.employees + from employees group department ( sort age take 2 @@ -2329,7 +2322,7 @@ fn test_group_take_n_02() { assert_snapshot!((compile(r###" prql target:sql.postgres - from db.employees + from employees group department ( sort age take 2.. @@ -2358,8 +2351,8 @@ fn test_group_take_n_02() { #[test] fn test_join() { assert_snapshot!((compile(r###" - from db.x - join db.y (==id) + from x + join y (==id) "###).unwrap()), @r###" SELECT x.*, @@ -2369,23 +2362,22 @@ fn test_join() { JOIN y ON x.id = y.id "###); - compile("from x | join db.y {==x.id}").unwrap_err(); + compile("from x | join y {==x.id}").unwrap_err(); } #[test] fn test_from_json() { // Test that the SQL generated from the JSON of the PRQL is the same as the raw PRQL let original_prql = r#" - from db.employees - select {e = this} - join db.salaries (==emp_no) + from e=employees + join salaries (==emp_no) group {e.emp_no, e.gender} ( aggregate { emp_salary = average salaries.salary } ) - join (db.dept_emp | select {de = this}) (==emp_no) - join (db.dept_manager | select {dm = this}) ( + join de=dept_emp (==emp_no) + join dm=dept_manager ( (dm.dept_no == de.dept_no) && s"(de.from_date, de.to_date) OVERLAPS (dm.from_date, dm.to_date)" ) group {dm.emp_no, gender} ( @@ -2395,7 +2387,7 @@ fn test_from_json() { } ) derive mng_no = emp_no - join (db.employees | select {managers = this}) (==emp_no) + join managers=employees (==emp_no) derive mng_name = s"managers.first_name || ' ' || managers.last_name" select {mng_name, managers.gender, salary_avg, salary_sd} "#; @@ -2420,7 +2412,7 @@ fn test_from_json() { #[test] fn test_f_string() { let query = r#" - from db.employees + from employees derive age = year_born - s'now()' select { f"Hello my name is {prefix}{first_name} {last_name}", @@ -2466,7 +2458,7 @@ fn test_f_string() { #[test] fn test_sql_of_ast_1() { let query = r#" - from db.employees + from employees filter country == "USA" group {title, country} ( aggregate {average salary} @@ -2508,7 +2500,7 @@ fn test_bare_s_string() { GROUPING SETS ((b, c, d), (d), (b, d)) """ - grouping + from grouping "#; let sql = compile(query).unwrap(); @@ -2532,7 +2524,7 @@ fn test_bare_s_string() { // Test that case insensitive SELECT is accepted. We allow it as it is valid SQL. let query = r#" let a = s"select insensitive from rude" - a + from a "#; let sql = compile(query).unwrap(); @@ -2554,7 +2546,7 @@ fn test_bare_s_string() { // Check a mixture of cases for good measure. let query = r#" let a = s"sElEcT insensitive from rude" - a + from a "#; let sql = compile(query).unwrap(); @@ -2581,7 +2573,7 @@ fn test_bare_s_string() { FROM bar" - a + from a "#; let sql = compile(query).unwrap(); @@ -2608,12 +2600,11 @@ fn test_bare_s_string() { } #[test] +// Confirm that a regular expr_call in a table definition works as expected. fn test_table_definition_with_expr_call() { - // Confirm that a regular expr_call in a table definition works as expected. let query = r###" - let e = take 4 (from db.employees) - - e + let e = take 4 (from employees) + from e "###; let sql = compile(query).unwrap(); @@ -2638,7 +2629,7 @@ fn test_table_definition_with_expr_call() { #[test] fn test_sql_of_ast_2() { let query = r#" - from db.employees + from employees aggregate sum_salary = s"sum({salary})" filter sum_salary > 100 "#; @@ -2657,7 +2648,7 @@ fn test_sql_of_ast_2() { #[test] fn test_prql_to_sql_1() { assert_snapshot!(compile(r#" - from db.employees + from employees aggregate { count salary, sum salary, @@ -2673,7 +2664,7 @@ fn test_prql_to_sql_1() { ); assert_snapshot!(compile(r#" prql target:sql.postgres - from db.developers + from developers group team ( aggregate { skill_width = count_distinct specialty, @@ -2695,7 +2686,7 @@ fn test_prql_to_sql_1() { #[test] fn test_prql_to_sql_2() { let query = r#" -from db.employees +from employees filter country == "USA" # Each line transforms the previous result. derive { # This adds columns / variables. gross_salary = salary + payroll_tax, @@ -2763,19 +2754,19 @@ fn test_prql_to_sql_table() { // table let query = r#" let newest_employees = ( - from db.employees + from employees sort tenure take 50 ) let average_salaries = ( - from db.salaries + from salaries group country ( aggregate { average_country_salary = average salary } ) ) - newest_employees + from newest_employees join average_salaries (==country) select {name, salary, average_country_salary} "#; @@ -2817,7 +2808,7 @@ fn test_prql_to_sql_table() { fn test_nonatomic() { // A take, then two aggregates let query = r#" - from db.employees + from employees take 20 filter country == "USA" group {title, country} ( @@ -2871,7 +2862,7 @@ fn test_nonatomic() { // A aggregate, then sort and filter let query = r###" - from db.employees + from employees group {title, country} ( aggregate { sum_gross_cost = average salary @@ -2904,12 +2895,12 @@ fn test_nonatomic_table() { // A take, then two aggregates let query = r#" let a = ( - from db.employees + from employees take 50 group country (aggregate {s"count(*)"}) ) - a - join db.b (==country) + from a + join b (==country) select {name, salary, average_country_salary} "#; @@ -2943,50 +2934,38 @@ fn test_nonatomic_table() { #[test] fn test_table_names_between_splits() { let prql = r###" - from db.employees - join (db.department | select {d = this}) (==dept_no) + from employees + join d=department (==dept_no) take 10 derive emp_no = employees.emp_no - join (db.salaries | select {s = this}) (==emp_no) + join s=salaries (==emp_no) select {employees.emp_no, d.name, s.salary} "###; let result = compile(prql).unwrap(); assert_snapshot!(result, @r###" WITH table_0 AS ( - SELECT - * - FROM - department - ), - table_2 AS ( SELECT employees.emp_no, - table_0.name + d.name FROM employees - JOIN table_0 ON employees.dept_no = table_0.dept_no + JOIN department AS d ON employees.dept_no = d.dept_no LIMIT 10 - ), table_1 AS ( - SELECT - * - FROM - salaries ) SELECT - table_2.emp_no, - table_2.name, - table_1.salary + table_0.emp_no, + table_0.name, + s.salary FROM - table_2 - JOIN table_1 ON table_2.emp_no = table_1.emp_no + table_0 + JOIN salaries AS s ON table_0.emp_no = s.emp_no "###); let prql = r###" - from db.employees - select {e = this} + from e=employees take 10 - join db.salaries (==emp_no) + join salaries (==emp_no) select {e.*, salaries.salary} "###; let result = compile(prql).unwrap(); @@ -2995,7 +2974,7 @@ fn test_table_names_between_splits() { SELECT * FROM - employees + employees AS e LIMIT 10 ) @@ -3011,9 +2990,8 @@ fn test_table_names_between_splits() { #[test] fn test_table_alias_01() { assert_snapshot!((compile(r###" - from db.employees - select {e = this} - join db.salaries side:left (salaries.emp_no == e.emp_no) + from e = employees + join salaries side:left (salaries.emp_no == e.emp_no) group {e.emp_no} ( aggregate { emp_salary = average salaries.salary @@ -3022,28 +3000,27 @@ fn test_table_alias_01() { select {emp_no, emp_salary} "###).unwrap()), @r###" SELECT - employees.emp_no, + e.emp_no, AVG(salaries.salary) AS emp_salary FROM - employees - LEFT JOIN salaries ON salaries.emp_no = employees.emp_no + employees AS e + LEFT JOIN salaries ON salaries.emp_no = e.emp_no GROUP BY - employees.emp_no + e.emp_no "###); } #[test] fn test_table_alias_02() { assert_snapshot!((compile(r#" - from db.employees - select {e = this} + from e = employees select e.first_name filter e.first_name == "Fred" "#).unwrap()), @r###" SELECT first_name FROM - employees + employees AS e WHERE first_name = 'Fred' "###); @@ -3054,7 +3031,7 @@ fn test_targets() { // Generic let query = r###" prql target:sql.generic - from db.Employees + from Employees select {FirstName, `last name`} take 3 "###; @@ -3072,7 +3049,7 @@ fn test_targets() { // SQL server let query = r###" prql target:sql.mssql - from db.Employees + from Employees select {FirstName, `last name`} take 3 "###; @@ -3095,7 +3072,7 @@ fn test_targets() { // MySQL let query = r###" prql target:sql.mysql - from db.Employees + from Employees select {FirstName, `last name`} take 3 "###; @@ -3116,7 +3093,7 @@ fn test_target_clickhouse() { let query = r###" prql target:sql.clickhouse - from db.github_json + from github_json derive {event_type_dotted = `event.type`} "###; @@ -3133,7 +3110,7 @@ fn test_target_clickhouse() { fn test_ident_escaping() { // Generic let query = r#" - from db.`anim"ls` + from `anim"ls` derive {`čebela` = BeeName, medved = `bear's_name`} "#; @@ -3150,7 +3127,7 @@ fn test_ident_escaping() { let query = r#" prql target:sql.mysql - from db.`anim"ls` + from `anim"ls` derive {`čebela` = BeeName, medved = `bear's_name`} "#; @@ -3167,7 +3144,7 @@ fn test_ident_escaping() { #[test] fn test_literal() { let query = r###" - from db.employees + from employees derive {always_true = true} "###; @@ -3188,16 +3165,16 @@ fn test_same_column_names() { // #820 let query = r###" let x = ( -from db.x_table +from x_table select only_in_x = foo ) let y = ( -from db.y_table +from y_table select foo ) -x +from x join y (foo == only_in_x) "###; @@ -3230,7 +3207,7 @@ fn test_double_aggregate() { // #941 compile( r###" - from db.numbers + from numbers group {type} ( aggregate { total_amt = sum amount, @@ -3244,7 +3221,7 @@ fn test_double_aggregate() { .unwrap_err(); assert_snapshot!(compile(r###" - from db.numbers + from numbers group {`type`} ( aggregate { total_amt = sum amount, @@ -3269,7 +3246,7 @@ fn test_double_aggregate() { fn test_window_function_coalesce() { // #3587 assert_snapshot!(compile(r###" - from db.x + from x select {a, b=a} window ( select { @@ -3291,7 +3268,7 @@ fn test_window_function_coalesce() { #[test] fn test_casting() { assert_snapshot!(compile(r###" - from db.x + from x select {a} derive { b = (a | as int) + 10, @@ -3319,14 +3296,14 @@ fn test_toposort() { assert_snapshot!(compile(r###" let b = ( - from db.somesource + from somesource ) let a = ( - b + from b ) - b + from b "###).unwrap(), @r###" WITH b AS ( @@ -3347,10 +3324,10 @@ fn test_toposort() { fn test_inline_tables() { assert_snapshot!(compile(r###" ( - from db.employees + from employees select {emp_id, name, surname, `type`, amount} ) - join (db.salaries | select {emp_id, salary}) (==emp_id) + join s = (from salaries | select {emp_id, salary}) (==emp_id) "###).unwrap(), @r###" WITH table_0 AS ( @@ -3380,7 +3357,7 @@ fn test_filter_and_select_unchanged_alias() { // #1185 assert_snapshot!(compile(r###" - from db.account + from account filter account.name != null select {name = account.name} "###).unwrap(), @@ -3399,7 +3376,7 @@ fn test_filter_and_select_unchanged_alias() { fn test_filter_and_select_changed_alias() { // #1185 assert_snapshot!(compile(r###" - from db.account + from account filter account.name != null select {renamed_name = account.name} "###).unwrap(), @@ -3415,7 +3392,7 @@ fn test_filter_and_select_changed_alias() { // #1207 assert_snapshot!(compile(r#" - from db.x + from x filter name != "Bob" select name = name ?? "Default" "#).unwrap(), @@ -3434,7 +3411,7 @@ fn test_filter_and_select_changed_alias() { fn test_unused_alias() { // #1308 assert_snapshot!(compile(r###" - from db.account + from account select n = {account.name} "###).unwrap_err(), @r###" Error: @@ -3444,7 +3421,7 @@ fn test_unused_alias() { │ ───────┬────── │ ╰──────── unexpected assign to `n` │ - │ Help: move assign into the tuple: `{n = ...}` + │ Help: move assign into the tuple: `[n = ...]` ───╯ "###) } @@ -3477,7 +3454,7 @@ fn test_table_s_string_02() { s""" SELECT DISTINCT ON first_name, id, age FROM employees ORDER BY age ASC """ - join s"SELECT * FROM salaries" (==id) + join s = s"SELECT * FROM salaries" (==id) "#).unwrap(), @r###" WITH table_0 AS ( @@ -3577,7 +3554,7 @@ fn test_table_s_string_05() { #[test] fn test_table_s_string_06() { assert_snapshot!(compile(r#" - s"SELECT * FROM {db.x}" + s"SELECT * FROM {default_db.x}" "#).unwrap(), @r###" WITH table_0 AS ( @@ -3598,7 +3575,7 @@ fn test_table_s_string_06() { fn test_direct_table_references() { assert_snapshot!(compile( r#" - from db.x + from x select s"{x}.field" "#, ) @@ -3616,7 +3593,7 @@ fn test_direct_table_references() { assert_snapshot!(compile( r###" - from db.x + from x select x "###, ) @@ -3632,7 +3609,7 @@ fn test_direct_table_references() { fn test_name_shadowing() { assert_snapshot!(compile( r###" - from db.x + from x select {a, a, a = a + 1} "###).unwrap(), @r###" @@ -3647,7 +3624,7 @@ fn test_name_shadowing() { assert_snapshot!(compile( r###" - from db.x + from x select a derive a derive a = a + 1 @@ -3671,8 +3648,7 @@ fn test_group_all() { r###" prql target:sql.sqlite - from db.albums - select {a = this} + from a=albums group a.* (aggregate {count this}) "###).unwrap_err(), @r###" Error: Target dialect does not support * in this position. @@ -3680,8 +3656,7 @@ fn test_group_all() { assert_snapshot!(compile( r###" - from db.albums - select {e = this} + from e=albums group !{genre_id} (aggregate {count this}) "###).unwrap_err(), @r###" Error: Excluding columns not supported as this position @@ -3693,7 +3668,7 @@ fn test_output_column_deduplication() { // #1249 assert_snapshot!(compile( r#" - from db.report + from report derive r = s"RANK() OVER ()" filter r == 1 "#).unwrap(), @@ -3719,7 +3694,7 @@ fn test_output_column_deduplication() { fn test_case_01() { assert_snapshot!(compile( r###" - from db.employees + from employees derive display_name = case [ nickname != null => nickname, true => f'{first_name} {last_name}' @@ -3742,7 +3717,7 @@ fn test_case_01() { fn test_case_02() { assert_snapshot!(compile( r###" - from db.employees + from employees derive display_name = case [ nickname != null => nickname, first_name != null => f'{first_name} {last_name}' @@ -3766,7 +3741,7 @@ fn test_case_02() { fn test_case_03() { assert_snapshot!(compile( r###" - from db.tracks + from tracks select category = case [ length > avg_length => 'long' ] @@ -3798,13 +3773,13 @@ fn test_case_03() { #[test] fn test_sql_options() { let options = Options::default(); - let sql = prqlc::compile("from db.x", &options).unwrap(); + let sql = prqlc::compile("from x", &options).unwrap(); assert!(sql.contains('\n')); assert!(sql.contains("-- Generated by")); let options = Options::default().no_signature().no_format(); - let sql = prqlc::compile("from db.x", &options).unwrap(); + let sql = prqlc::compile("from x", &options).unwrap(); assert!(!sql.contains('\n')); assert!(!sql.contains("-- Generated by")); @@ -3814,7 +3789,7 @@ fn test_sql_options() { fn test_static_analysis() { assert_snapshot!(compile( r###" - from db.x + from x select { a = (- (-3)), b = !(!(!(!(!(true))))), @@ -3852,7 +3827,7 @@ fn test_closures_and_pipelines() { let addthree = a b c -> s"{a} || {b} || {c}" let arg = myarg myfunc -> ( myfunc myarg ) - from db.y + from y select x = ( addthree "apples" arg "bananas" @@ -3871,7 +3846,7 @@ fn test_closures_and_pipelines() { #[test] fn test_basic_agg() { assert_snapshot!(compile(r#" - from db.employees + from employees aggregate { count salary, count this, @@ -3890,7 +3865,7 @@ fn test_basic_agg() { #[test] fn test_exclude_columns_01() { assert_snapshot!(compile(r#" - from db.tracks + from tracks select {track_id, title, composer, bytes} select !{title, composer} "#).unwrap(), @@ -3907,7 +3882,7 @@ fn test_exclude_columns_01() { #[test] fn test_exclude_columns_02() { assert_snapshot!(compile(r#" - from db.tracks + from tracks select {track_id, title, composer, bytes} group !{title, composer} (aggregate {count this}) "#).unwrap(), @@ -3928,7 +3903,7 @@ fn test_exclude_columns_02() { #[test] fn test_exclude_columns_03() { assert_snapshot!(compile(r#" - from db.artists + from artists derive nick = name select !{artists.*} "#).unwrap(), @@ -3945,7 +3920,7 @@ fn test_exclude_columns_03() { fn test_exclude_columns_04() { assert_snapshot!(compile(r#" prql target:sql.bigquery - from db.tracks + from tracks select !{milliseconds,bytes} "#).unwrap(), @r###" @@ -3963,7 +3938,7 @@ fn test_exclude_columns_04() { fn test_exclude_columns_05() { assert_snapshot!(compile(r#" prql target:sql.snowflake - from db.tracks + from tracks select !{milliseconds,bytes} "#).unwrap(), @r###" @@ -3979,7 +3954,7 @@ fn test_exclude_columns_05() { fn test_exclude_columns_06() { assert_snapshot!(compile(r#" prql target:sql.duckdb - from db.tracks + from tracks select !{milliseconds,bytes} "#).unwrap(), @r###" @@ -3995,7 +3970,7 @@ fn test_exclude_columns_06() { fn test_exclude_columns_07() { assert_snapshot!(compile(r#" prql target:sql.duckdb - s"SELECT * FROM foo" + from s"SELECT * FROM foo" select !{bar} "#).unwrap(), @r###" @@ -4021,7 +3996,7 @@ fn test_custom_transforms() { sort name ) - from db.tab + from tab my_transform take 3 "#).unwrap(), @@ -4042,7 +4017,7 @@ fn test_custom_transforms() { #[test] fn test_name_inference() { assert_snapshot!(compile(r#" - from db.albums + from albums select {artist_id + album_id} # nothing inferred infer "#).unwrap(), @@ -4056,7 +4031,7 @@ fn test_name_inference() { let sql1 = compile( r#" - from db.albums + from albums select {artist_id} # infer albums.artist_id select {albums.artist_id} @@ -4065,7 +4040,7 @@ fn test_name_inference() { .unwrap(); let sql2 = compile( r#" - from db.albums + from albums select {albums.artist_id} # infer albums.artist_id select {albums.artist_id} @@ -4188,7 +4163,7 @@ fn test_header() { assert_snapshot!(compile(format!(r#" {header} - from db.a + from a take 5 "#).as_str()).unwrap(),@r###" SELECT @@ -4208,21 +4183,21 @@ fn test_header() { fn test_header_target_error() { assert_snapshot!(compile(r#" prql target:foo - from db.a + from a "#).unwrap_err(),@r###" Error: target `"foo"` not found "###); assert_snapshot!(compile(r#" prql target:sql.foo - from db.a + from a "#).unwrap_err(),@r###" Error: target `"sql.foo"` not found "###); assert_snapshot!(compile(r#" prql target:foo.bar - from db.a + from a "#).unwrap_err(),@r###" Error: target `"foo.bar"` not found "###); @@ -4232,7 +4207,7 @@ fn test_header_target_error() { // - At least not the first empty line? assert_snapshot!(compile(r#" prql dialect:foo.bar - from db.a + from a "#).unwrap_err(),@r###" Error: ╭─[:1:1] @@ -4248,7 +4223,7 @@ fn test_header_target_error() { #[test] fn prql_version() { assert_snapshot!(compile(r#" - from db.x + from x derive y = std.prql.version "#).unwrap(),@r###" SELECT @@ -4326,7 +4301,7 @@ fn test_loop_2() { read_csv 'employees.csv' filter last_name=="Mitchell" loop ( - join (db.employees | select {manager = this}) (manager.employee_id==this.reports_to) + join manager=employees (manager.employee_id==this.reports_to) select manager.* ) "#).unwrap(), @@ -4337,7 +4312,7 @@ fn test_loop_2() { FROM read_csv('employees.csv') ), - table_2 AS ( + table_1 AS ( SELECT * FROM @@ -4347,20 +4322,15 @@ fn test_loop_2() { UNION ALL SELECT - table_4.* + manager.* FROM - table_2 - JOIN ( - SELECT - * - FROM - employees - ) AS table_4 ON table_4.employee_id = table_2.reports_to + table_1 + JOIN employees AS manager ON manager.employee_id = table_1.reports_to ) SELECT * FROM - table_2 AS table_3 + table_1 AS table_2 "### ); } @@ -4368,7 +4338,7 @@ fn test_loop_2() { #[test] fn test_params() { assert_snapshot!(compile(r#" - from db.invoices + from invoices select {i = this} filter $1 <= i.date || i.date <= $2 select { @@ -4397,7 +4367,7 @@ fn test_params() { #[test] fn test_datetime() { let query = &r#" - from db.test_table + from test_table select {date = @2022-12-31, time = @08:30, timestamp = @2020-01-01T13:19:55-0800} "#; @@ -4420,7 +4390,7 @@ fn test_datetime_sqlite() { assert_snapshot!(compile(r#" prql target:sql.sqlite - from db.x + from x select { date = @2022-12-31, time = @08:30, @@ -4449,7 +4419,7 @@ fn test_datetime_sqlite() { #[test] fn test_datetime_parsing() { assert_snapshot!(compile(r#" - from db.test_tables + from test_tables select {date = @2022-12-31, time = @08:30, timestamp = @2020-01-01T13:19:55-0800} "#).unwrap(), @r###" @@ -4466,7 +4436,7 @@ fn test_datetime_parsing() { #[test] fn test_lower() { assert_snapshot!(compile(r#" - from db.test_tables + from test_tables derive {lower_name = (name | text.lower)} "#).unwrap(), @r###" @@ -4482,7 +4452,7 @@ fn test_lower() { #[test] fn test_upper() { assert_snapshot!(compile(r#" - from db.test_tables + from test_tables derive {upper_name = text.upper name} select {upper_name} "#).unwrap(), @@ -4498,7 +4468,7 @@ fn test_upper() { #[test] fn test_1535() { assert_snapshot!(compile(r#" - from db.x.y.z + from x.y.z "#).unwrap(), @r###" SELECT @@ -4544,7 +4514,7 @@ fn test_read_parquet_duckdb() { fn test_excess_columns() { // https://github.com/PRQL/prql/issues/2079 assert_snapshot!(compile(r#" - from db.tracks + from tracks derive d = track_id sort d select {title} @@ -4570,7 +4540,7 @@ fn test_excess_columns() { #[test] fn test_regex_search() { assert_snapshot!(compile(r#" - from db.tracks + from tracks derive is_bob_marley = artist_name ~= "Bob\\sMarley" "#).unwrap(), @r###" @@ -4586,7 +4556,7 @@ fn test_regex_search() { #[test] fn test_intervals() { assert_snapshot!(compile(r#" - from db.foo + from foo select dt = 1years + 1months + 1weeks + 1days + 1hours + 1minutes + 1seconds + 1milliseconds + 1microseconds "#).unwrap(), @r###" @@ -4601,10 +4571,10 @@ fn test_intervals() { #[test] fn test_into() { assert_snapshot!(compile(r#" - from db.data + from data into table_a - table_a + from table_a select {x, y} "#).unwrap(), @r###" @@ -4629,7 +4599,7 @@ fn test_array_01() { r#" let a = [1, 2, false] - from db.x + from x "#, ) .unwrap(); @@ -4674,7 +4644,7 @@ fn test_array_01() { #[test] fn test_array_02() { assert_snapshot!(compile(r#" - [ + from [ {x = null}, {x = '1'}, ] @@ -4698,8 +4668,8 @@ fn test_array_02() { #[test] fn test_double_stars() { assert_snapshot!(compile(r#" - from db.tb1 - join db.tb2 (==c2) + from tb1 + join tb2 (==c2) take 5 filter (tb2.c3 < 100) "#).unwrap(), @@ -4726,8 +4696,8 @@ fn test_double_stars() { assert_snapshot!(compile(r#" prql target:sql.duckdb - from db.tb1 - join db.tb2 (==c2) + from tb1 + join tb2 (==c2) take 5 filter (tb2.c3 < 100) "#).unwrap(), @@ -4816,7 +4786,7 @@ fn test_type_as_column_name() { select t.date ) - from db.foo + from foo f"#) .unwrap(), @r###" SELECT @@ -4830,7 +4800,7 @@ fn test_type_as_column_name() { fn test_error_code() { let err = compile( r###" - let a = (from db.x) + let a = (from x) "###, ) .unwrap_err(); @@ -4842,7 +4812,7 @@ fn large_query() { // This was causing a stack overflow on Windows, ref https://github.com/PRQL/prql/issues/2857 compile( r###" -from db.employees +from employees filter gross_cost > 0 group {title} ( aggregate { @@ -4870,7 +4840,7 @@ take 20 fn test_returning_constants_only() { assert_snapshot!(compile( r###" - from db.tb1 + from tb1 sort {a} select {c = b} select {d = 10} @@ -4894,7 +4864,7 @@ fn test_returning_constants_only() { assert_snapshot!(compile( r###" - from db.tb1 + from tb1 take 10 filter true take 20 @@ -4934,10 +4904,10 @@ fn test_conflicting_names_at_split() { // issue #2697 assert_snapshot!(compile( r#" - from db.workflow_steps | select {s = this} - join (db.workflow_phases | select {wp = this}) (s.phase_id == wp.id) + from s = workflow_steps + join wp=workflow_phases (s.phase_id == wp.id) filter wp.name == "CREATE_OUTLET" - join (db.workflow | select {w = this}) (wp.workflow_id == w.id) + join w=workflow (wp.workflow_id == w.id) select { step_id = s.id, phase_id = wp.id, @@ -4947,33 +4917,21 @@ fn test_conflicting_names_at_split() { .unwrap(), @r###" WITH table_0 AS ( SELECT - * - FROM - workflow_phases - ), - table_2 AS ( - SELECT - table_0.id, - workflow_steps.id AS _expr_0, - table_0.workflow_id + wp.id, + s.id AS _expr_0, + wp.workflow_id FROM - workflow_steps - JOIN table_0 ON workflow_steps.phase_id = table_0.id + workflow_steps AS s + JOIN workflow_phases AS wp ON s.phase_id = wp.id WHERE - table_0.name = 'CREATE_OUTLET' - ), - table_1 AS ( - SELECT - * - FROM - workflow + wp.name = 'CREATE_OUTLET' ) SELECT - table_2._expr_0 AS step_id, - table_2.id AS phase_id + table_0._expr_0 AS step_id, + table_0.id AS phase_id FROM - table_2 - JOIN table_1 ON table_2.workflow_id = table_1.id + table_0 + JOIN workflow AS w ON table_0.workflow_id = w.id "###); } @@ -4982,7 +4940,7 @@ fn test_relation_literal_quoting() { // issue #3484 assert_snapshot!(compile( r###" - [ + from [ {`small number`=1e-10, `large number`=1e10}, ] select {`small number`, `large number`} @@ -5006,9 +4964,9 @@ fn test_relation_literal_quoting() { fn test_relation_var_name_clashes_01() { assert_snapshot!(compile( r###" - let table_0 = (from db.a) + let table_0 = (from a) - table_0 + from table_0 take 10 filter x > 0 "###, @@ -5042,8 +5000,8 @@ fn test_relation_var_name_clashes_02() { // issue #3713 assert_snapshot!(compile( r###" - from db.t - join db.t (==x) + from t + join t (==x) "###, ) .unwrap(), @r###" @@ -5064,7 +5022,7 @@ fn test_select_this() { // - lineage is not computed correctly assert_snapshot!(compile( r###" - from db.x + from x select {a, b} select this "###, @@ -5082,7 +5040,7 @@ fn test_select_this() { fn test_group_exclude() { assert_snapshot!(compile( r###" - from db.x + from x select {a, b} group {a} (derive c = a + 1) "###, @@ -5119,7 +5077,7 @@ fn test_group_exclude() { fn test_table_declarations() { assert_snapshot!(compile( r###" - module db { + module default_{ module my_schema { let my_table <[{ id = int, a = text }]> } @@ -5127,15 +5085,13 @@ fn test_table_declarations() { let another_table <[{ id = int, b = text }]> } - from db.my_schema.my_table | join db.another_table (==id) | take 10 + from my_schema.my_table | join another_table (==id) | take 10 "###, ) .unwrap(), @r###" SELECT - my_table.id, - my_table.a, - another_table.id, - another_table.b + my_table.*, + another_table.* FROM my_schema.my_table JOIN another_table ON my_table.id = another_table.id @@ -5150,7 +5106,7 @@ fn test_param_declarations() { r###" let a - from db.x | filter b == a + from x | filter b == a "###, ) .unwrap(), @r###" @@ -5167,7 +5123,7 @@ fn test_param_declarations() { fn test_relation_aliasing() { assert_snapshot!(compile( r###" - from db.x | select {y = this} | select {y.hello} + from x | select {y = this} | select {y.hello} "###, ) .unwrap(), @r###" @@ -5188,7 +5144,7 @@ fn test_import() { import a = hello.world - from db.x | select a + from x | select a "###, ) .unwrap(), @r###" diff --git a/web/book/src/how-do-i/distinct.md b/web/book/src/how-do-i/distinct.md deleted file mode 100644 index a59bf7d4bb2f..000000000000 --- a/web/book/src/how-do-i/distinct.md +++ /dev/null @@ -1 +0,0 @@ -# Removing duplicates diff --git a/web/book/src/lib.rs b/web/book/src/lib.rs index 3b45e9f053f9..809829b794de 100644 --- a/web/book/src/lib.rs +++ b/web/book/src/lib.rs @@ -239,7 +239,7 @@ fn test_replace_examples() -> Result<()> { # PRQL Doc ```prql -from db.x +from x ``` ```python @@ -260,7 +260,7 @@ this is an error

PRQL

```prql - from db.x + from x ``` diff --git a/web/book/src/project/integrations/postgresql.md b/web/book/src/project/integrations/postgresql.md index d7e203f449a9..f08998a0a91a 100644 --- a/web/book/src/project/integrations/postgresql.md +++ b/web/book/src/project/integrations/postgresql.md @@ -9,7 +9,7 @@ PL/PRQL functions serve as intermediaries, compiling the user's PRQL code into S PL/PRQL functions are defined using the `plprql` language specifier: ```sql create function match_stats(int) returns table(player text, kd_ratio float) as $$ - from db.matches + from matches filter match_id == $1 group player ( aggregate { diff --git a/web/book/src/project/integrations/syntax-highlighting.md b/web/book/src/project/integrations/syntax-highlighting.md index 4dc6f7ed0db3..9414f81ea6d2 100644 --- a/web/book/src/project/integrations/syntax-highlighting.md +++ b/web/book/src/project/integrations/syntax-highlighting.md @@ -11,7 +11,7 @@ GitHub, Pandoc, and other Markdown renderers: ````markdown ```elm -from db.employees +from employees filter start_date > @2021-01-01 ``` ```` diff --git a/web/book/src/project/target.md b/web/book/src/project/target.md index c7e2c20688f1..53d66ae53e80 100644 --- a/web/book/src/project/target.md +++ b/web/book/src/project/target.md @@ -10,7 +10,7 @@ PRQL to compile to a database-specific SQL flavor. ```prql prql target:sql.postgres -from db.employees +from employees sort age take 10 ``` @@ -18,7 +18,7 @@ take 10 ```prql prql target:sql.mssql -from db.employees +from employees sort age take 10 ``` @@ -64,7 +64,7 @@ DuckDB dialect. ```sh echo 'prql target:sql.generic - from db.foo' | prqlc compile --target sql.duckdb + from foo' | prqlc compile --target sql.duckdb ``` To use the target described in the query, a special target `sql.any` can be @@ -72,7 +72,7 @@ specified in the compiler option. ```sh echo 'prql target:sql.generic - from db.foo' | prqlc compile --target sql.any + from foo' | prqlc compile --target sql.any ``` ## Version @@ -82,7 +82,7 @@ PRQL allows specifying a version of the language in the PRQL header, like: ```prql prql version:"0.11.5" -from db.employees +from employees ``` This has two roles, one of which is implemented: diff --git a/web/book/src/reference/data/from.md b/web/book/src/reference/data/from.md index 2b277dbe812b..4c9d7ebd8fba 100644 --- a/web/book/src/reference/data/from.md +++ b/web/book/src/reference/data/from.md @@ -3,13 +3,13 @@ Specifies a data source. ```prql -from db.artists +from artists ``` To introduce an alias, use an assign expression: ```prql -from e = db.employees +from e = employees select e.first_name ``` @@ -17,5 +17,17 @@ Table names containing spaces or special characters [need to be contained within backticks](../syntax/keywords.md#quoting): ```prql -from db.`artist tracks` +from `artist tracks` +``` + +`default_db.tablename` can be used if the table name matches a function from the +standard library. + +```admonish note +We realize this is an awkward workaround. Track & 👍 [#3271](https://github.com/PRQL/prql/issues/3271) for resolving this. +``` + +```prql +default_db.group # in place of `from group` +take 1 ``` diff --git a/web/book/src/reference/data/read-files.md b/web/book/src/reference/data/read-files.md index d8f55874ad20..9b0a14b47600 100644 --- a/web/book/src/reference/data/read-files.md +++ b/web/book/src/reference/data/read-files.md @@ -23,7 +23,7 @@ functions, which is allowed in DuckDB, enclose the file names in backticks ` `` ` as follows: ```prql -from db.`artists.parquet` +from `artists.parquet` ``` ## See also diff --git a/web/book/src/reference/data/relation-literals.md b/web/book/src/reference/data/relation-literals.md index 4eaf014c442d..001ea9de36a1 100644 --- a/web/book/src/reference/data/relation-literals.md +++ b/web/book/src/reference/data/relation-literals.md @@ -27,9 +27,9 @@ let my_artists = [ {artist="James Brown"}, ] -from db.artists +from artists join my_artists (==artist) -join db.albums (==artist_id) +join albums (==artist_id) select {artists.artist_id, albums.title} ``` diff --git a/web/book/src/reference/declarations/functions.md b/web/book/src/reference/declarations/functions.md index 70ffff48982a..8249d0d2746b 100644 --- a/web/book/src/reference/declarations/functions.md +++ b/web/book/src/reference/declarations/functions.md @@ -15,7 +15,7 @@ So this function is named `fahrenheit_to_celsius` and has one parameter `temp`: ```prql let fahrenheit_to_celsius = temp -> (temp - 32) / 1.8 -from db.cities +from cities derive temp_c = (fahrenheit_to_celsius temp_f) ``` @@ -27,7 +27,7 @@ and `x`, and one named parameter named `low` which takes a default argument of ```prql let interp = low:0 high x -> (x - low) / (high - low) -from db.students +from students derive { sat_proportion_1 = (interp 1600 sat_score), sat_proportion_2 = (interp low:0 1600 sat_score), @@ -42,7 +42,7 @@ let writes_code = col -> (col | in ["PRQL", "Rust"]) let square = col -> (col | math.pow 2) let starts_with_a = col -> (col | text.lower | text.starts_with("a")) -from db.employees +from employees select { first_name, last_name, @@ -64,7 +64,7 @@ above with an alternative construction: ```prql let interp = low:0 high x -> (x - low) / (high - low) -from db.students +from students derive { sat_proportion_1 = (sat_score | interp 1600), sat_proportion_2 = (sat_score | interp low:0 1600), @@ -76,7 +76,7 @@ and ```prql let fahrenheit_to_celsius = temp -> (temp - 32) / 1.8 -from db.cities +from cities derive temp_c = (temp_f | fahrenheit_to_celsius) ``` @@ -86,7 +86,7 @@ We can combine a chain of functions, which makes logic more readable: let fahrenheit_to_celsius = temp -> (temp - 32) / 1.8 let interp = low:0 high x -> (x - low) / (high - low) -from db.kettles +from kettles derive boiling_proportion = (temp_c | fahrenheit_to_celsius | interp 100) ``` @@ -99,7 +99,7 @@ in the `from`. ```prql let cost_share = cost -> cost / cost_total -from db.costs +from costs select {materials, labor, overhead, cost_total} derive { materials_share = (cost_share materials), diff --git a/web/book/src/reference/declarations/variables.md b/web/book/src/reference/declarations/variables.md index 861ff0dd11ef..37b6419ab1b4 100644 --- a/web/book/src/reference/declarations/variables.md +++ b/web/book/src/reference/declarations/variables.md @@ -24,7 +24,7 @@ Syntactically, variables can take 3 forms. - The final expression of a pipeline defaults to taking the name `main`. ```prql no-eval - x + from x ``` ... is equivalent to: @@ -38,21 +38,21 @@ Expressions (or sub-queries in some cases). ```prql let top_50 = ( - from db.employees + from employees sort salary take 50 aggregate {total_salary = sum salary} ) -top_50 # Starts a new pipeline +from top_50 # Starts a new pipeline ``` ```prql -from db.employees +from employees take 50 into first_50 -first_50 +from first_50 ``` Variables can be assigned an s-string containing the whole SQL query @@ -68,5 +68,5 @@ let grouping = s""" ((b, c, d), (d), (b, d)) """ -grouping +from grouping ``` diff --git a/web/book/src/reference/spec/modules.md b/web/book/src/reference/spec/modules.md index 729afeec027a..51360413fd55 100644 --- a/web/book/src/reference/spec/modules.md +++ b/web/book/src/reference/spec/modules.md @@ -62,9 +62,9 @@ module my_playlists { let movie_albums = (from albums | filter id == 3) } - from db.soundtracks.movie_albums + from soundtracks.movie_albums } -from db.my_playlists.soundtracks.movie_albums +from my_playlists.soundtracks.movie_albums ``` If an identifier cannot be resolved relative to the current module, it tries to @@ -94,9 +94,9 @@ acquire an implicit name main. ``` module my_playlists { - let bangers = (from db.tracks | take 10) + let bangers = (from tracks | take 10) - from db.playlists | take 10 + from playlists | take 10 } let album_titles = my_playlists.main @@ -251,13 +251,12 @@ module project { let mean = a -> ... } - module db { + module default_db { # all inferred tables and defined CTEs } let main = ( - from db.tracks - select {t = this} + from t = tracks select [track_id, title] ) } diff --git a/web/book/src/reference/spec/name-resolution.md b/web/book/src/reference/spec/name-resolution.md index f1e0aa9c29b2..bde941de5d8a 100644 --- a/web/book/src/reference/spec/name-resolution.md +++ b/web/book/src/reference/spec/name-resolution.md @@ -54,7 +54,7 @@ When translating into an SQL statement which references only one table, there is no need to reference column names with table prefix. ```prql -from db.employees +from employees select first_name ``` @@ -64,9 +64,9 @@ in multiple tables. Because of this, we have to use table prefixes for all column names. ```prql -from db.employees +from employees derive {first_name, dept_id} -join d = db.departments (==dept_id) +join d=departments (==dept_id) select {first_name, d.title} ``` diff --git a/web/book/src/reference/spec/null.md b/web/book/src/reference/spec/null.md index 81850df3f1a5..cee036de1440 100644 --- a/web/book/src/reference/spec/null.md +++ b/web/book/src/reference/spec/null.md @@ -22,7 +22,7 @@ PRQL, on the other hand, treats `null` as a value, which means that: - distinct column cannot contain multiple `null` values. ```prql -from db.employees +from employees filter first_name == null filter null != last_name ``` diff --git a/web/book/src/reference/stdlib/README.md b/web/book/src/reference/stdlib/README.md index 81c4dcd0c121..1ce6980b49cb 100644 --- a/web/book/src/reference/stdlib/README.md +++ b/web/book/src/reference/stdlib/README.md @@ -22,7 +22,7 @@ The source is the [`std.sql`](https://github.com/PRQL/prql/blob/main/prqlc/prqlc And a couple of examples: ```prql -from db.employees +from employees derive { gross_salary = (salary + payroll_tax | as int), gross_salary_rounded = (gross_salary | math.round 0), diff --git a/web/book/src/reference/stdlib/date.md b/web/book/src/reference/stdlib/date.md index d09779fbcb12..055473d8e5c3 100644 --- a/web/book/src/reference/stdlib/date.md +++ b/web/book/src/reference/stdlib/date.md @@ -20,7 +20,7 @@ For now the supported DBs are: Clickhouse, DuckDB, MySQL, MSSQL and Postgres. ```prql prql target:sql.duckdb -from db.invoices +from invoices select { invoice_date | date.to_text "%d/%m/%Y" } @@ -29,7 +29,7 @@ select { ```prql prql target:sql.postgres -from db.invoices +from invoices select { invoice_date | date.to_text "%d/%m/%Y" } @@ -38,7 +38,7 @@ select { ```prql prql target:sql.mysql -from db.invoices +from invoices select { invoice_date | date.to_text "%d/%m/%Y" } diff --git a/web/book/src/reference/stdlib/distinct.md b/web/book/src/reference/stdlib/distinct.md index a06c07b5e6ad..542e4c2b2a48 100644 --- a/web/book/src/reference/stdlib/distinct.md +++ b/web/book/src/reference/stdlib/distinct.md @@ -4,7 +4,7 @@ PRQL doesn't have a specific `distinct` keyword. Instead duplicate tuples in a relation can be removed by using `group` and `take 1`: ```prql -from db.employees +from employees select department group employees.* ( take 1 @@ -14,7 +14,7 @@ group employees.* ( This also works with a wildcard: ```prql -from db.employees +from employees group employees.* (take 1) ``` @@ -26,7 +26,7 @@ To ```prql # youngest employee from each department -from db.employees +from employees group department ( sort age take 1 @@ -37,7 +37,7 @@ Note that we can't always compile to `DISTINCT`; when the columns in the `group` aren't all the available columns, we need to use a window function: ```prql -from db.employees +from employees group {first_name, last_name} (take 1) ``` @@ -50,7 +50,7 @@ group {first_name, last_name} (take 1) ```prql prql target:sql.postgres -from db.employees +from employees group department ( sort age take 1 diff --git a/web/book/src/reference/stdlib/math.md b/web/book/src/reference/stdlib/math.md index 3fc48c47efc3..857dc7afde4a 100644 --- a/web/book/src/reference/stdlib/math.md +++ b/web/book/src/reference/stdlib/math.md @@ -27,7 +27,7 @@ These are all the functions defined in the `math` module: ### Example ```prql -from db.employees +from employees select { age_squared = age | math.pow 2 } diff --git a/web/book/src/reference/stdlib/text.md b/web/book/src/reference/stdlib/text.md index 02833ba2a6de..666eb275c1e3 100644 --- a/web/book/src/reference/stdlib/text.md +++ b/web/book/src/reference/stdlib/text.md @@ -19,7 +19,7 @@ These are all the functions defined in the `text` module: ### Example ```prql -from db.employees +from employees select { last_name | text.lower | text.starts_with("a"), title | text.replace "manager" "chief" diff --git a/web/book/src/reference/stdlib/transforms/aggregate.md b/web/book/src/reference/stdlib/transforms/aggregate.md index 17bc8a655736..303ed80b186f 100644 --- a/web/book/src/reference/stdlib/transforms/aggregate.md +++ b/web/book/src/reference/stdlib/transforms/aggregate.md @@ -20,7 +20,7 @@ process of filling out [std lib](../). ## Examples ```prql -from db.employees +from employees aggregate { average salary, ct = count salary @@ -28,7 +28,7 @@ aggregate { ``` ```prql -from db.employees +from employees group {title, country} ( aggregate { average salary, @@ -44,7 +44,7 @@ other transform except `aggregate`) will not trigger aggregation. By default, PRQL will interpret such attempts functions as window functions: ```prql -from db.employees +from employees derive {avg_sal = average salary} ``` diff --git a/web/book/src/reference/stdlib/transforms/append.md b/web/book/src/reference/stdlib/transforms/append.md index 48b8d92ab64f..09d2b088b697 100644 --- a/web/book/src/reference/stdlib/transforms/append.md +++ b/web/book/src/reference/stdlib/transforms/append.md @@ -7,8 +7,8 @@ number of rows from the two input tables. To replicate `UNION DISTINCT`, see [set operations](#set-operations). ```prql -from db.employees_1 -append db.employees_2 +from employees_1 +append employees_2 ``` ## Remove @@ -19,8 +19,8 @@ Removes rows that appear in another relation, like `EXCEPT ALL`. Duplicate rows are removed one-for-one. ```prql -from db.employees_1 -remove db.employees_2 +from employees_1 +remove employees_2 ``` ## Intersection @@ -28,8 +28,8 @@ remove db.employees_2 > _experimental_ ```prql -from db.employees_1 -intersect db.employees_2 +from employees_1 +intersect employees_2 ``` ## Set operations @@ -40,8 +40,11 @@ To imitate set operations i.e. (`UNION`, `EXCEPT` and `INTERSECT`), you can use the following functions: ```prql no-eval -let distinct = rel -> (rel | group this.* (take 1)) -let union = func bottom top -> (top | append bottom | distinct) -let except = func bottom top -> (top | distinct | remove bottom) -let intersect_distinct = func bottom top -> (top | intersect bottom | distinct) +let distinct = rel -> (from t = _param.rel | group {t.*} (take 1)) +let union = `default_db.bottom` top -> (top | append bottom | distinct) +let except = `default_db.bottom` top -> (top | distinct | remove bottom) +let intersect_distinct = `default_db.bottom` top -> (top | intersect bottom | distinct) ``` + +Don't mind the `default_db.` and `noop`, these are compiler implementation +detail for now. diff --git a/web/book/src/reference/stdlib/transforms/derive.md b/web/book/src/reference/stdlib/transforms/derive.md index 1ab9d804e058..ed1f467ec2a7 100644 --- a/web/book/src/reference/stdlib/transforms/derive.md +++ b/web/book/src/reference/stdlib/transforms/derive.md @@ -13,12 +13,12 @@ derive { ## Examples ```prql -from db.employees +from employees derive gross_salary = salary + payroll_tax ``` ```prql -from db.employees +from employees derive { gross_salary = salary + payroll_tax, gross_cost = gross_salary + benefits_cost diff --git a/web/book/src/reference/stdlib/transforms/filter.md b/web/book/src/reference/stdlib/transforms/filter.md index d2f82eb94586..09d8da469f84 100644 --- a/web/book/src/reference/stdlib/transforms/filter.md +++ b/web/book/src/reference/stdlib/transforms/filter.md @@ -9,21 +9,21 @@ filter boolean_expression ## Examples ```prql -from db.employees +from employees filter age > 25 ``` ```prql -from db.employees +from employees filter (age > 25 || department != "IT") ``` ```prql -from db.employees +from employees filter (department | in ["IT", "HR"]) ``` ```prql -from db.employees +from employees filter (age | in 25..40) ``` diff --git a/web/book/src/reference/stdlib/transforms/group.md b/web/book/src/reference/stdlib/transforms/group.md index 028f9cf1c67b..402d805afb16 100644 --- a/web/book/src/reference/stdlib/transforms/group.md +++ b/web/book/src/reference/stdlib/transforms/group.md @@ -11,7 +11,7 @@ The partitioning of groups are determined by the `key_column`s (first argument). The most conventional use of `group` is with `aggregate`: ```prql -from db.employees +from employees group {title, country} ( aggregate { average salary, @@ -25,7 +25,7 @@ the group as it would to the table — for example finding the employee who join first across the whole table: ```prql -from db.employees +from employees sort join_date take 1 ``` @@ -34,7 +34,7 @@ To find the employee who joined first in each department, it's exactly the same pipeline, but within a `group` expression: ```prql -from db.employees +from employees group role ( sort join_date # taken from above take 1 diff --git a/web/book/src/reference/stdlib/transforms/join.md b/web/book/src/reference/stdlib/transforms/join.md index cefc4652a48e..6d8c2cc9f8de 100644 --- a/web/book/src/reference/stdlib/transforms/join.md +++ b/web/book/src/reference/stdlib/transforms/join.md @@ -9,7 +9,8 @@ join side:{inner|left|right|full} table (condition) ## Parameters - `side` specifies which rows to include, defaulting to `inner`. -- _table_ - a reference to a relation, +- _table_ - a reference to a relation, possibly including an alias, e.g. + `a=artists` - _condition_ - a boolean condition - If the condition evaluates to true for a given row, the row will be joined - If name is the same from both tables, it can be expressed with only @@ -18,13 +19,18 @@ join side:{inner|left|right|full} table (condition) ## Examples ```prql -from db.employees -join side:left db.positions (employees.id==positions.employee_id) +from employees +join side:left positions (employees.id==positions.employee_id) ``` ```prql -from db.tracks -join side:left db.artists ( +from employees +join side:left p=positions (employees.id==p.employee_id) +``` + +```prql +from tracks +join side:left artists ( # This adds a `country` condition, as an alternative to filtering artists.id==tracks.artist_id && artists.country=='UK' ) @@ -34,8 +40,8 @@ join side:left db.artists ( the current & other table respectively: ```prql -from db.tracks -join side:inner db.artists ( +from tracks +join side:inner artists ( this.id==that.artist_id ) ``` @@ -46,6 +52,6 @@ If the join conditions are of form `left.x == right.x`, we can use "self equality operator": ```prql -from db.employees -join db.positions (==emp_no) +from employees +join positions (==emp_no) ``` diff --git a/web/book/src/reference/stdlib/transforms/loop.md b/web/book/src/reference/stdlib/transforms/loop.md index f5df2c9cf9c1..49f45b24cf0c 100644 --- a/web/book/src/reference/stdlib/transforms/loop.md +++ b/web/book/src/reference/stdlib/transforms/loop.md @@ -26,7 +26,7 @@ def loop(step, initial): ## Examples ```prql -[{n = 1}] +from [{n = 1}] loop ( filter n<4 select n = n+1 diff --git a/web/book/src/reference/stdlib/transforms/select.md b/web/book/src/reference/stdlib/transforms/select.md index 82a59b67d809..2e7f1c996ba0 100644 --- a/web/book/src/reference/stdlib/transforms/select.md +++ b/web/book/src/reference/stdlib/transforms/select.md @@ -15,12 +15,12 @@ select !{column} ## Examples ```prql -from db.employees +from employees select name = f"{first_name} {last_name}" ``` ```prql -from db.employees +from employees select { name = f"{first_name} {last_name}", age_eoy = dob - @2022-12-31, @@ -28,13 +28,12 @@ select { ``` ```prql -from db.employees +from employees select first_name ``` ```prql -from db.employees -select {e = this} +from e=employees select {e.first_name, e.last_name} ``` @@ -53,18 +52,18 @@ Some examples: ```prql prql target:sql.bigquery -from db.tracks +from tracks select !{milliseconds, bytes} ``` ```prql -from db.tracks +from tracks select {track_id, title, composer, bytes} select !{title, composer} ``` ```prql -from db.artists +from artists derive nick = name select !{artists.*} ``` @@ -74,6 +73,6 @@ different meaning: ```prql prql target:sql.bigquery -from db.tracks +from tracks select !is_compilation ``` diff --git a/web/book/src/reference/stdlib/transforms/sort.md b/web/book/src/reference/stdlib/transforms/sort.md index a09832fee599..2b90363f893d 100644 --- a/web/book/src/reference/stdlib/transforms/sort.md +++ b/web/book/src/reference/stdlib/transforms/sort.md @@ -19,24 +19,24 @@ sort {(+|-) column} ## Examples ```prql -from db.employees +from employees sort age ``` ```prql -from db.employees +from employees sort {-age} ``` ```prql -from db.employees +from employees sort {age, -tenure, +salary} ``` We can also use expressions: ```prql -from db.employees +from employees sort {s"substr({first_name}, 2, 5)"} ``` @@ -45,9 +45,9 @@ sort {s"substr({first_name}, 2, 5)"} Ordering is persistent through a pipeline in PRQL. For example: ```prql -from db.employees +from employees sort tenure -join db.locations (==employee_id) +join locations (==employee_id) ``` Here, PRQL pushes the `sort` down the pipeline, compiling the `ORDER BY` to the @@ -108,7 +108,7 @@ above: ```prql prql target:sql.duckdb -from db.artists +from artists sort artist_id take 42 ``` diff --git a/web/book/src/reference/stdlib/transforms/take.md b/web/book/src/reference/stdlib/transforms/take.md index 4bc081b837a5..eec95db2385d 100644 --- a/web/book/src/reference/stdlib/transforms/take.md +++ b/web/book/src/reference/stdlib/transforms/take.md @@ -11,12 +11,12 @@ See [Ranges](../../syntax/ranges.md) for more details on how ranges work. ## Examples ```prql -from db.employees +from employees take 10 ``` ```prql -from db.orders +from orders sort {-value, created_at} take 101..110 ``` diff --git a/web/book/src/reference/stdlib/transforms/window.md b/web/book/src/reference/stdlib/transforms/window.md index c6ee69b86ff9..bf0290e06fe4 100644 --- a/web/book/src/reference/stdlib/transforms/window.md +++ b/web/book/src/reference/stdlib/transforms/window.md @@ -41,7 +41,7 @@ Some examples: ## Example ```prql -from db.employees +from employees group employee_id ( sort month window rolling:12 ( @@ -51,7 +51,7 @@ group employee_id ( ``` ```prql -from db.orders +from orders sort day window rows:-3..3 ( derive {centered_weekly_average = average value} @@ -67,7 +67,7 @@ group {order_month} ( Rows vs Range: ```prql -[ +from [ {time_id=1, value=15}, {time_id=2, value=11}, {time_id=3, value=16}, @@ -119,7 +119,7 @@ the whole table. Unlike in SQL, they will remain window functions and will not trigger aggregation. ```prql -from db.employees +from employees sort age derive {rnk = rank age} ``` @@ -127,7 +127,7 @@ derive {rnk = rank age} You can also only apply `group`: ```prql -from db.employees +from employees group department ( sort age derive {rnk = rank age} @@ -139,6 +139,6 @@ group department ( There are no limitations on where windowed expressions can be used: ```prql -from db.employees +from employees filter salary < (average salary) ``` diff --git a/web/book/src/reference/syntax/README.md b/web/book/src/reference/syntax/README.md index 9a3507dab4f9..8833f862321c 100644 --- a/web/book/src/reference/syntax/README.md +++ b/web/book/src/reference/syntax/README.md @@ -10,7 +10,7 @@ A summary of PRQL syntax: | Syntax | Usage | Example | | -------------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------- | -| \| | [Pipelines](./function-calls.md) | from db.employees \| select first_name | +| \| | [Pipelines](./function-calls.md) | from employees \| select first_name | | `=` | [Assigns](../declarations/variables.md) | `from e = employees`
`derive total = (sum salary)` | | `:` | [Named args & parameters](../declarations/functions.md) | `interp low:0 1600 sat_score` | | `{}` | [Tuples](./tuples.md) | `{id, false, total = 3}` | diff --git a/web/book/src/reference/syntax/case.md b/web/book/src/reference/syntax/case.md index f58d2cc22e03..9964faaf8408 100644 --- a/web/book/src/reference/syntax/case.md +++ b/web/book/src/reference/syntax/case.md @@ -4,7 +4,7 @@ Search for the first condition that evaluates to `true` and return its associated value. If none of the conditions match, `null` is returned. ```prql -from db.employees +from employees derive distance = case [ city == "Calgary" => 0, city == "Edmonton" => 300, @@ -14,7 +14,7 @@ derive distance = case [ To set a default, a `true` condition can be used: ```prql -from db.employees +from employees derive distance = case [ city == "Calgary" => 0, city == "Edmonton" => 300, diff --git a/web/book/src/reference/syntax/comments.md b/web/book/src/reference/syntax/comments.md index c685d8bc8934..6825b46ee2ab 100644 --- a/web/book/src/reference/syntax/comments.md +++ b/web/book/src/reference/syntax/comments.md @@ -3,7 +3,7 @@ Character `#` denotes a comment until the end of the line. ```prql -from db.employees # Comment 1 +from employees # Comment 1 # Comment 2 aggregate {average salary} ``` diff --git a/web/book/src/reference/syntax/f-strings.md b/web/book/src/reference/syntax/f-strings.md index 150556dbc28b..fb68ebb96dea 100644 --- a/web/book/src/reference/syntax/f-strings.md +++ b/web/book/src/reference/syntax/f-strings.md @@ -4,7 +4,7 @@ F-strings are a readable approach to building new strings from existing strings & variables. ```prql -from db.employees +from employees select full_name = f"{first_name} {last_name}" ``` @@ -12,7 +12,7 @@ This can be much easier to read for longer strings, relative to the SQL approach: ```prql -from db.web +from web select url = f"http{tls}://www.{domain}.{tld}/{page}" ``` @@ -20,7 +20,7 @@ Note that currently interpolations can only contain plain variable names and not whole expressions like Python, so this won't work: ```prql error no-fmt -from db.tracks +from tracks select length_str = f"{length_seconds / 60} minutes" ``` diff --git a/web/book/src/reference/syntax/function-calls.md b/web/book/src/reference/syntax/function-calls.md index 3795069a8c06..8102376b69c2 100644 --- a/web/book/src/reference/syntax/function-calls.md +++ b/web/book/src/reference/syntax/function-calls.md @@ -52,7 +52,7 @@ TODO: this should be a part of the tutorial As you may have noticed, transforms are regular functions too! ```prql -from db.employees +from employees filter age > 50 sort name ``` @@ -60,19 +60,19 @@ sort name ... is equivalent to ... ```prql -from db.employees | filter age > 50 | sort name +from employees | filter age > 50 | sort name ``` ... is equivalent to ... ```prql -filter age > 50 (from db.employees) | sort name +filter age > 50 (from employees) | sort name ``` ... is equivalent to ... ```prql -sort name (filter age > 50 (from db.employees)) +sort name (filter age > 50 (from employees)) ``` As you can see, the first example with pipeline notation is much easier to diff --git a/web/book/src/reference/syntax/keywords.md b/web/book/src/reference/syntax/keywords.md index cd52825c5df3..4eeb1bf63375 100644 --- a/web/book/src/reference/syntax/keywords.md +++ b/web/book/src/reference/syntax/keywords.md @@ -17,7 +17,7 @@ hello.world `this` refers to the current relation: ```prql -from db.invoices +from invoices aggregate ( count this ) @@ -27,22 +27,22 @@ Within a [`join`](../stdlib/transforms/join.md), `that` refers to the other table: ```prql -from db.invoices -join db.tracks (this.track_id==that.id) +from invoices +join tracks (this.track_id==that.id) ``` `this` can also be used to remove any column ambiguity. For example, currently using a bare `time` as a column name will fail, because it's also a type: ```prql error no-fmt -from db.invoices +from invoices derive t = time ``` But with `this.time`, we can remove the ambiguity: ```prql -from db.invoices +from invoices derive t = this.time ``` @@ -56,23 +56,21 @@ quoting rules. ```prql prql target:sql.mysql - -from db.employees +from employees select `first name` ``` ```prql prql target:sql.postgres - -from db.employees +from employees select `first name` ``` ```prql prql target:sql.bigquery -from db.`project-foo.dataset.table` -join db.`project-bar.dataset.table` (==col_bax) +from `project-foo.dataset.table` +join `project-bar.dataset.table` (==col_bax) ``` ## Schemas & database names @@ -80,7 +78,7 @@ join db.`project-bar.dataset.table` (==col_bax) Identifiers of database tables can be prefixed with schema and databases names. ```prql -from db.my_database.chinook.albums +from my_database.chinook.albums ``` Note that all of following identifiers will be treated as separate table @@ -111,7 +109,7 @@ is, `std.from` is the same function as `from`. In the example below, the resulting query is the same as without the `std.` namespace: ```prql -from db.my_table +std.from my_table std.select {from = my_table.a, take = my_table.b} std.take 3 ``` diff --git a/web/book/src/reference/syntax/literals.md b/web/book/src/reference/syntax/literals.md index 7c99b540aba8..466d5a1f44ee 100644 --- a/web/book/src/reference/syntax/literals.md +++ b/web/book/src/reference/syntax/literals.md @@ -22,7 +22,7 @@ Integers can, alternatively, be expressed using hexadecimal, octal or binary notation using these prefixes respectively: `0x`, `0o` or `0b`. ```prql -from db.numbers +from numbers select { small = 1.000_000_1, big = 5_000_000, @@ -63,7 +63,7 @@ that just uses a string `'2004-10-19 10:23:54'`. Dates are represented by `@{yyyy-mm-dd}` — a `@` followed by the date format. ```prql -from db.employees +from employees derive age_at_year_end = (@2022-12-31 - dob) ``` @@ -74,7 +74,7 @@ defaulting to zero. This includes the timezone, which is represented by `+HH:mm`, `-HH:mm` or `Z`. This is consistent with the ISO8601 time format. ```prql -from db.orders +from orders derive should_have_shipped_today = (order_time < @08:30) ``` @@ -86,7 +86,7 @@ which is represented by `+HH:mm`, `-HH:mm` or `Z` (`:` is optional). This is `@ followed by the ISO8601 datetime format, which uses `T` to separate date & time. ```prql -from db.commits +from commits derive first_prql_commit = @2020-01-01T13:19:55-08:00 derive first_prql_commit_utc = @2020-01-02T21:19:55Z ``` @@ -105,7 +105,7 @@ issue if this is inconvenient. ``` ```prql -from db.projects +from projects derive first_check_in = start + 10days ``` diff --git a/web/book/src/reference/syntax/operators.md b/web/book/src/reference/syntax/operators.md index a3c016293c2f..2fba60871e85 100644 --- a/web/book/src/reference/syntax/operators.md +++ b/web/book/src/reference/syntax/operators.md @@ -5,7 +5,7 @@ Expressions can be composed from _function calls_ and _operations_, such as to calculate the alias `circumference` and in the `filter` transform. ```prql -from db.foo +from foo select { circumference = diameter * 3.14159, color, @@ -44,7 +44,7 @@ integer value. ```prql prql target:sql.sqlite -[ +from [ {a = 5, b = 2}, {a = 5, b = -2}, ] @@ -60,7 +60,7 @@ We can coalesce values with an `??` operator. Coalescing takes either the first value or, if that value is null, the second value. ```prql -from db.orders +from orders derive amount ?? 0 ``` @@ -75,42 +75,42 @@ compiles to `REGEXP`, though differs by dialect. A regex search means that to match an exact value, the start and end need to be anchored with `^foo$`. ```prql -from db.tracks +from tracks filter (name ~= "Love") ``` ```prql prql target:sql.duckdb -from db.artists +from artists filter (name ~= "Love.*You") ``` ```prql prql target:sql.bigquery -from db.tracks +from tracks filter (name ~= "\\bLove\\b") ``` ```prql prql target:sql.postgres -from db.tracks +from tracks filter (name ~= "\\(I Can't Help\\) Falling") ``` ```prql prql target:sql.mysql -from db.tracks +from tracks filter (name ~= "With You") ``` ```prql prql target:sql.sqlite -from db.tracks +from tracks filter (name ~= "But Why Isn't Your Syntax More Similar\\?") ``` @@ -137,7 +137,7 @@ calls, for example: `foo + bar`. Here's a set of examples of these rules: ```prql -from db.employees +from employees # Requires parentheses, because it contains a pipe derive is_proximate = (distance | in 0..20) # Requires parentheses, because it's a function call @@ -171,14 +171,14 @@ For example, the snippet below produces an error because the `sum` function call is not in a tuple. ```prql error no-fmt -from db.employees +from employees derive total_distance = sum distance ``` ...while with parentheses, it works at expected: ```prql -from db.employees +from employees derive other_distance = (sum distance) ``` @@ -195,7 +195,7 @@ multiple physical lines, we can use `\` at the beginning of subsequent physical lines: ```prql -from db.artists +from artists select is_europe = \ country == "DE" \ || country == "FR" @@ -206,7 +206,7 @@ Wrapping will "jump over" empty lines or lines with comments. For example, the `select` here is only one logical line: ```prql -from db.tracks +from tracks # This would be a really long line without being able to split it: select listening_time_years = (spotify_plays + apple_music_plays + pandora_plays) # We can toggle between lines when developing: diff --git a/web/book/src/reference/syntax/parameters.md b/web/book/src/reference/syntax/parameters.md index e5c7b7385c1f..268e25d2e2e1 100644 --- a/web/book/src/reference/syntax/parameters.md +++ b/web/book/src/reference/syntax/parameters.md @@ -9,6 +9,6 @@ string. Most database engines only support numeric positional parameter ids (i.e `$3`). ```prql -from db.employees +from employees filter id == $1 ``` diff --git a/web/book/src/reference/syntax/pipes.md b/web/book/src/reference/syntax/pipes.md index 3e9e28bd2368..fe625bf06859 100644 --- a/web/book/src/reference/syntax/pipes.md +++ b/web/book/src/reference/syntax/pipes.md @@ -6,11 +6,11 @@ the input for the transform following the pipe. A pipe can be represented with either a line break or a pipe character (`|`). For example, here the `filter` transform operates on the result of -`from db.employees` (which is just the `employees` table), and the `select` +`from employees` (which is just the `employees` table), and the `select` transform operates on the result of the `filter` transform. ```prql -from db.employees +from employees filter department == "Product" select {first_name, last_name} ``` @@ -19,7 +19,7 @@ In the place of a line break, it's also possible to use the `|` character to pipe results between transforms, such that this is equivalent: ```prql -from db.employees | filter department == "Product" | select {first_name, last_name} +from employees | filter department == "Product" | select {first_name, last_name} ``` ## "C'est ne pas un pipe" @@ -49,7 +49,7 @@ let b = # No pipe from line break before this `from` statement -from db.y +from y derive a = b ``` @@ -62,7 +62,7 @@ pass their result to an "inner transform". The example below applies the `aggregate` pipeline to each group of unique `title` and `country` values: ```prql -from db.employees +from employees group {title, country} ( aggregate { average salary, diff --git a/web/book/src/reference/syntax/r-strings.md b/web/book/src/reference/syntax/r-strings.md index dd8bd45c311c..8844261c13a3 100644 --- a/web/book/src/reference/syntax/r-strings.md +++ b/web/book/src/reference/syntax/r-strings.md @@ -3,7 +3,7 @@ R-strings handle escape characters without special treatment: ```prql -from db.artists +from artists derive normal_string = "\\\t" # two characters - \ and tab (\t) derive raw_string = r"\\\t" # four characters - \, \, \, and t ``` diff --git a/web/book/src/reference/syntax/ranges.md b/web/book/src/reference/syntax/ranges.md index 9e9369c0bd81..2823b8fc4ff7 100644 --- a/web/book/src/reference/syntax/ranges.md +++ b/web/book/src/reference/syntax/ranges.md @@ -10,7 +10,7 @@ Ranges can be used in filters with the `in` function, with any type of literal, including dates: ```prql -from db.events +from events filter (created_at | in @1776-07-04..@1787-09-17) filter (magnitude | in 50..100) derive is_northern = (latitude | in 0..) @@ -19,7 +19,7 @@ derive is_northern = (latitude | in 0..) Ranges can also be used in `take`: ```prql -from db.orders +from orders sort {-value, created_at} take 101..110 ``` diff --git a/web/book/src/reference/syntax/s-strings.md b/web/book/src/reference/syntax/s-strings.md index bc678646a456..c8d17c0b9b68 100644 --- a/web/book/src/reference/syntax/s-strings.md +++ b/web/book/src/reference/syntax/s-strings.md @@ -6,7 +6,7 @@ PostgreSQL that returns the PostgreSQL version, so if we want to use that, we use an s-string: ```prql -from db.my_table +from my_table select db_version = s"version()" ``` @@ -20,7 +20,7 @@ let average = column -> s"AVG({column})" So this compiles using the function: ```prql -from db.employees +from employees aggregate {average salary} ``` @@ -33,9 +33,8 @@ adjust the quotes of the S-string. For example, instead of `s'CONCAT("hello", "w Here's an example of a more involved use of an s-string: ```prql -from db.dept_emp -select {de = this} -join (db.salaries | select {s = this}) side:left (s.emp_no == de.emp_no && s""" +from de=dept_emp +join s=salaries side:left (s.emp_no == de.emp_no && s""" ({s.from_date}, {s.to_date}) OVERLAPS ({de.from_date}, {de.to_date}) @@ -53,8 +52,8 @@ expression like Python. We can also use s-strings to produce a full table: ```prql -s"SELECT DISTINCT ON first_name, id, age FROM employees ORDER BY age ASC" -join s"SELECT * FROM salaries" (==id) +from s"SELECT DISTINCT ON first_name, id, age FROM employees ORDER BY age ASC" +join s = s"SELECT * FROM salaries" (==id) ``` ```admonish note @@ -69,7 +68,7 @@ should implement it in PRQL or PRQL's stdlib. If you often require an s-string, To output braces from an s-string, use double braces: ```prql -from db.employees +from employees derive { has_valid_title = s"regexp_contains(title, '([a-z0-9]*-){{2,}}')" } @@ -86,7 +85,7 @@ wrong. The generated SQL code is as if we had written `salary + (benefits / 365)`. ```prql -from db.employees +from employees derive { gross_salary = salary + benefits, daily_rate = s"{gross_salary} / 365" @@ -96,7 +95,7 @@ derive { Instead, the numerator `{gross_salary}` must be encased in parentheses: ```prql -from db.employees +from employees derive { gross_salary = salary + benefits, daily_rate = s"({gross_salary}) / 365" diff --git a/web/book/src/reference/syntax/strings.md b/web/book/src/reference/syntax/strings.md index 1a06c379b03f..3c717f58d89c 100644 --- a/web/book/src/reference/syntax/strings.md +++ b/web/book/src/reference/syntax/strings.md @@ -4,7 +4,7 @@ String literals can use any matching odd number of either single or double quotes: ```prql -from db.artists +from artists derive { single = 'hello world', double = "hello world", @@ -18,7 +18,7 @@ To quote a string containing quote characters, use the "other" type of quote, or use the escape character `\`, or use more quotes. ```prql -from db.artists +from artists select { other = '"hello world"', escaped = "\"hello world\"", @@ -30,7 +30,7 @@ Strings can contain any escape character sequences defined by the [JSON standard](https://www.ecma-international.org/publications-and-standards/standards/ecma-404/). ```prql -from db.artists +from artists derive escapes = "\tXYZ\n \\ " # tab (\t), "XYZ", newline (\n), " ", \, " " derive world = "\u{0048}\u{0065}\u{006C}\u{006C}\u{006F}" # "Hello" derive hex = "\x48\x65\x6C\x6C\x6F" # "Hello" diff --git a/web/book/src/reference/syntax/tuples.md b/web/book/src/reference/syntax/tuples.md index 6b325d14a08a..98bb094445cd 100644 --- a/web/book/src/reference/syntax/tuples.md +++ b/web/book/src/reference/syntax/tuples.md @@ -25,12 +25,12 @@ transforms. Most transforms can also take a single field, which will be converted into a tuple. These are equivalent: ```prql -from db.employees +from employees select {first_name} ``` ```prql -from db.employees +from employees select first_name ``` diff --git a/web/book/src/tutorial/aggregation.md b/web/book/src/tutorial/aggregation.md index 095d96a89c13..2616b6f792f1 100644 --- a/web/book/src/tutorial/aggregation.md +++ b/web/book/src/tutorial/aggregation.md @@ -10,7 +10,7 @@ The `aggregate` transform takes a tuple to create one or more new columns that "distill down" data from all the rows. ```prql no-eval -from db.invoices +from invoices aggregate { sum_of_orders = sum total } ``` @@ -22,7 +22,7 @@ expressions are contained in a tuple. `aggregate` discards all columns that are not present in the tuple. ```prql no-eval -from db.invoices +from invoices aggregate { num_orders = count this, sum_of_orders = sum total, @@ -39,7 +39,7 @@ Suppose we want to produce summaries of invoices _for each city_ in the table. We could create a query for each city, and aggregate its rows: ```prql no-eval -from db.albums +from albums filter billing_city == "Oslo" aggregate { sum_of_orders = sum total } ``` @@ -56,7 +56,7 @@ same city) using information that's already in the table. It then applies a transform to each group, and combines the results back together: ```prql no-eval -from db.invoices +from invoices group billing_city ( aggregate { num_orders = count this, @@ -66,14 +66,14 @@ group billing_city ( ``` Those familiar with SQL have probably noticed that we just decoupled aggregation -from db.grouping. +from grouping. Although these operations are connected in SQL, PRQL makes it straightforward to use `group` and `aggregate` separate from each other, while combining with other transform functions, such as: ```prql no-eval -from db.invoices +from invoices group billing_city ( take 2 ) diff --git a/web/book/src/tutorial/annotated_example.md b/web/book/src/tutorial/annotated_example.md index 67ddccfc84a3..edcbe55f4f7c 100644 --- a/web/book/src/tutorial/annotated_example.md +++ b/web/book/src/tutorial/annotated_example.md @@ -10,7 +10,7 @@ explains the details of each line in that example. --> ```prql no-eval -from db.invoices # A PRQL query begins with a table +from invoices # A PRQL query begins with a table # Subsequent lines "transform" (modify) it derive { # "derive" adds columns to the result transaction_fee = 0.8, # "=" sets a column name @@ -25,7 +25,7 @@ group customer_id ( # "group" performs the pipeline in (...) on ct = count customer_id, # } ) -join c = db.customers (==customer_id) # join on "customer_id" from both tables +join c=customers (==customer_id) # join on "customer_id" from both tables derive name = f"{c.last_name}, {c.first_name}" # F-strings like Python derive db_version = s"version()" # S-string offers escape hatch to SQL select { # "select" passes along only the named columns diff --git a/web/book/src/tutorial/filtering.md b/web/book/src/tutorial/filtering.md index cf21c9f16654..332284e5e3d9 100644 --- a/web/book/src/tutorial/filtering.md +++ b/web/book/src/tutorial/filtering.md @@ -11,7 +11,7 @@ Now we will explore how to manipulate the rows of a table using `filter` and The `filter` transform picks rows to pass through based on their values: ```prql no-eval -from db.invoices +from invoices filter billing_city == "Berlin" ``` @@ -29,19 +29,19 @@ the table. The set of rows picked can be specified in two ways: - an inclusive range of rows `start..end`. ```prql no-eval -from db.invoices +from invoices take 4 ``` ```prql no-eval -from db.invoices +from invoices take 4..7 ``` Of course, it is possible combine all these transforms into a single pipeline: ```prql no-eval -from db.invoices +from invoices # retain only rows for orders from Berlin filter billing_city == "Berlin" diff --git a/web/book/src/tutorial/relations.md b/web/book/src/tutorial/relations.md index bf98ff014b3c..f18fd0a93f3e 100644 --- a/web/book/src/tutorial/relations.md +++ b/web/book/src/tutorial/relations.md @@ -29,7 +29,7 @@ The main purpose of PRQL is to build queries that combine and transform data from relations such as the `invoices` table above. Here is the most basic query: ```prql no-eval -from db.invoices +from invoices ``` ```admonish note @@ -53,7 +53,7 @@ the columns to pass through. _(Try it in the [Playground.](https://prql-lang.org/playground/))_ ```prql no-eval -from db.invoices +from invoices select { order_id, total } ``` @@ -62,7 +62,7 @@ ignored. In addition, we can assign any of the expressions to a _variable_ that becomes the name of the resulting column in the SQL output. ```prql no-eval -from db.invoices +from invoices select { OrderID = invoice_id, Total = total, @@ -81,7 +81,7 @@ To add columns to a relation, we can use `derive` function. Let's define a new column for Value Added Tax, set at 19% of the invoice total. ```prql no-eval -from db.invoices +from invoices derive { VAT = total * 0.19 } ``` @@ -98,8 +98,8 @@ from two relations "side by side". To determine which rows from each relation should be joined, `join` has match criteria, written in `( ... )`. ```prql no-eval -from db.invoices -join db.customers ( ==customer_id ) +from invoices +join customers ( ==customer_id ) ``` This example "connects" the customer information from the `customers` relation @@ -110,9 +110,8 @@ It is frequently useful to assign an alias to both relations being joined together so that each relation's columns can be referred to uniquely. ```prql no-eval -from db.invoices -select {inv = this} -join (db.customers | select {cust = this}) ( ==customer_id ) +from inv=invoices +join cust=customers ( ==customer_id ) ``` In the example above, the alias `inv` represents the `invoices` relation and @@ -132,9 +131,8 @@ at the end of the query. Each transform modifies the relation produced by the statement above to produce the desired result. ```prql no-eval -from db.invoices -select {inv = this} -join (db.customers | select {cust = this}) (==customer_id) +from inv=invoices +join cust=customers (==customer_id) derive { VAT = inv.total * 0.19 } select { OrderID = inv.invoice_id, diff --git a/web/book/tests/documentation/snapshots/documentation__book__reference__data__from__3.snap b/web/book/tests/documentation/snapshots/documentation__book__reference__data__from__3.snap new file mode 100644 index 000000000000..b396f045105e --- /dev/null +++ b/web/book/tests/documentation/snapshots/documentation__book__reference__data__from__3.snap @@ -0,0 +1,10 @@ +--- +source: web/book/tests/documentation/book.rs +expression: "default_db.group # in place of `from group`\ntake 1\n" +--- +SELECT + * +FROM + "group" +LIMIT + 1 diff --git a/web/book/tests/documentation/snapshots/documentation__book__reference__spec__name-resolution__translating-to-sql__1.snap b/web/book/tests/documentation/snapshots/documentation__book__reference__spec__name-resolution__translating-to-sql__1.snap index 23de7512b6af..18835346beac 100644 --- a/web/book/tests/documentation/snapshots/documentation__book__reference__spec__name-resolution__translating-to-sql__1.snap +++ b/web/book/tests/documentation/snapshots/documentation__book__reference__spec__name-resolution__translating-to-sql__1.snap @@ -1,6 +1,6 @@ --- source: web/book/tests/documentation/book.rs -expression: "from db.employees\nderive {first_name, dept_id}\njoin d = db.departments (==dept_id)\nselect {first_name, d.title}\n" +expression: "from employees\nderive {first_name, dept_id}\njoin d=departments (==dept_id)\nselect {first_name, d.title}\n" --- SELECT employees.first_name, diff --git a/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__distinct__remove-duplicates-from-each-group__0.snap b/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__distinct__remove-duplicates-from-each-group__0.snap index a580a17ad7f1..36fadace0ce8 100644 --- a/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__distinct__remove-duplicates-from-each-group__0.snap +++ b/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__distinct__remove-duplicates-from-each-group__0.snap @@ -1,6 +1,6 @@ --- source: web/book/tests/documentation/book.rs -expression: "# youngest employee from each department\nfrom db.employees\ngroup department (\n sort age\n take 1\n)\n" +expression: "# youngest employee from each department\nfrom employees\ngroup department (\n sort age\n take 1\n)\n" --- WITH table_0 AS ( SELECT @@ -19,4 +19,3 @@ FROM table_0 WHERE _expr_0 <= 1 - diff --git a/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__distinct__remove-duplicates-from-each-group__1.snap b/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__distinct__remove-duplicates-from-each-group__1.snap index 0c6a8947f79e..f78830fe8076 100644 --- a/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__distinct__remove-duplicates-from-each-group__1.snap +++ b/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__distinct__remove-duplicates-from-each-group__1.snap @@ -1,6 +1,6 @@ --- source: web/book/tests/documentation/book.rs -expression: "from db.employees\ngroup {first_name, last_name} (take 1)\n" +expression: "from employees\ngroup {first_name, last_name} (take 1)\n" --- WITH table_0 AS ( SELECT @@ -15,4 +15,3 @@ FROM table_0 WHERE _expr_0 <= 1 - diff --git a/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__transforms__join__examples__1.snap b/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__transforms__join__examples__1.snap index 71b7e5ead80a..867a9539905a 100644 --- a/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__transforms__join__examples__1.snap +++ b/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__transforms__join__examples__1.snap @@ -1,12 +1,11 @@ --- source: web/book/tests/documentation/book.rs -expression: "from db.tracks\njoin side:left db.artists (\n # This adds a `country` condition, as an alternative to filtering\n artists.id==tracks.artist_id && artists.country=='UK'\n)\n" +expression: "from employees\njoin side:left p=positions (employees.id==p.employee_id)\n" --- SELECT - tracks.*, - artists.* + employees.*, + p.* FROM - tracks - LEFT JOIN artists ON artists.id = tracks.artist_id - AND artists.country = 'UK' + employees + LEFT JOIN positions AS p ON employees.id = p.employee_id diff --git a/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__transforms__join__examples__2.snap b/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__transforms__join__examples__2.snap index f12e60c6d217..f7c73eca2c27 100644 --- a/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__transforms__join__examples__2.snap +++ b/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__transforms__join__examples__2.snap @@ -1,11 +1,12 @@ --- source: web/book/tests/documentation/book.rs -expression: "from db.tracks\njoin side:inner db.artists (\n this.id==that.artist_id\n)\n" +expression: "from tracks\njoin side:left artists (\n # This adds a `country` condition, as an alternative to filtering\n artists.id==tracks.artist_id && artists.country=='UK'\n)\n" --- SELECT tracks.*, artists.* FROM tracks - JOIN artists ON tracks.id = artists.artist_id + LEFT JOIN artists ON artists.id = tracks.artist_id + AND artists.country = 'UK' diff --git a/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__transforms__join__examples__3.snap b/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__transforms__join__examples__3.snap new file mode 100644 index 000000000000..4f98b7e6b369 --- /dev/null +++ b/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__transforms__join__examples__3.snap @@ -0,0 +1,11 @@ +--- +source: web/book/tests/documentation/book.rs +expression: "from tracks\njoin side:inner artists (\n this.id==that.artist_id\n)\n" +--- +SELECT + tracks.*, + artists.* +FROM + tracks + JOIN artists ON tracks.id = artists.artist_id + diff --git a/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__transforms__select__examples__3.snap b/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__transforms__select__examples__3.snap index 45bf13bba07a..f094cd2231c3 100644 --- a/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__transforms__select__examples__3.snap +++ b/web/book/tests/documentation/snapshots/documentation__book__reference__stdlib__transforms__select__examples__3.snap @@ -1,10 +1,10 @@ --- source: web/book/tests/documentation/book.rs -expression: "from db.employees\nselect {e = this}\nselect {e.first_name, e.last_name}\n" +expression: "from e=employees\nselect {e.first_name, e.last_name}\n" --- SELECT first_name, last_name FROM - employees + employees AS e diff --git a/web/book/tests/documentation/snapshots/documentation__book__reference__syntax__pipes__cest-ne-pas-un-pipe__1.snap b/web/book/tests/documentation/snapshots/documentation__book__reference__syntax__pipes__cest-ne-pas-un-pipe__1.snap index f50d862a195f..d413b4152218 100644 --- a/web/book/tests/documentation/snapshots/documentation__book__reference__syntax__pipes__cest-ne-pas-un-pipe__1.snap +++ b/web/book/tests/documentation/snapshots/documentation__book__reference__syntax__pipes__cest-ne-pas-un-pipe__1.snap @@ -1,6 +1,6 @@ --- source: web/book/tests/documentation/book.rs -expression: "let b =\n \\ 3 # No pipe from line break within this line wrap\n\n# No pipe from line break before this `from` statement\n\nfrom db.y\nderive a = b\n" +expression: "let b =\n \\ 3 # No pipe from line break within this line wrap\n\n# No pipe from line break before this `from` statement\n\nfrom y\nderive a = b\n" --- SELECT *, diff --git a/web/book/tests/documentation/snapshots/documentation__book__reference__syntax__s-strings__2.snap b/web/book/tests/documentation/snapshots/documentation__book__reference__syntax__s-strings__2.snap index 7b4d7c664beb..74a0450e96af 100644 --- a/web/book/tests/documentation/snapshots/documentation__book__reference__syntax__s-strings__2.snap +++ b/web/book/tests/documentation/snapshots/documentation__book__reference__syntax__s-strings__2.snap @@ -1,18 +1,12 @@ --- source: web/book/tests/documentation/book.rs -expression: "from db.dept_emp\nselect {de = this}\njoin (db.salaries | select {s = this}) side:left (s.emp_no == de.emp_no && s\"\"\"\n ({s.from_date}, {s.to_date})\n OVERLAPS\n ({de.from_date}, {de.to_date})\n\"\"\")\n" +expression: "from de=dept_emp\njoin s=salaries side:left (s.emp_no == de.emp_no && s\"\"\"\n ({s.from_date}, {s.to_date})\n OVERLAPS\n ({de.from_date}, {de.to_date})\n\"\"\")\n" --- -WITH table_0 AS ( - SELECT - * - FROM - salaries -) SELECT - dept_emp.*, - table_0.* + de.*, + s.* FROM - dept_emp - LEFT JOIN table_0 ON table_0.emp_no = dept_emp.emp_no - AND (table_0.from_date, table_0.to_date) OVERLAPS (dept_emp.from_date, dept_emp.to_date) + dept_emp AS de + LEFT JOIN salaries AS s ON s.emp_no = de.emp_no + AND (s.from_date, s.to_date) OVERLAPS (de.from_date, de.to_date) diff --git a/web/playground/src/examples.js b/web/playground/src/examples.js index 468a1631ec66..fddba0506d48 100644 --- a/web/playground/src/examples.js +++ b/web/playground/src/examples.js @@ -16,7 +16,7 @@ group customer_id ( # "group" performs the pipeline in (...) on ct = count customer_id, # } ) -join c = db.customers (==customer_id) # join on "customer_id" from both tables +join c=customers (==customer_id) # join on "customer_id" from both tables derive name = f"{c.last_name}, {c.first_name}" # F-strings like Python derive db_version = s"version()" # S-string offers escape hatch to SQL select { # "select" passes along only the named columns @@ -33,26 +33,25 @@ take 1..10 # Limit to a range - could also be "take 10 "let-table-0.prql": [ "sql", `let soundtracks = ( - from db.playlists + from playlists filter name == 'TV Shows' - join (db.playlist_track | select {pt = this}) (==playlist_id) + join pt=playlist_track (==playlist_id) select pt.track_id ) let high_energy = ( - from db.genres + from genres filter name == 'Rock And Roll' || name == 'Hip Hop/Rap' ) -from db.tracks -select {t = this} +from t=tracks # anti-join soundtracks join side:left s=soundtracks (==track_id) filter s.track_id == null # limit to kicker genres -join g= db.high_energy (==genre_id) +join g=high_energy (==genre_id) # format output select {t.track_id, track = t.name, genre = g.name} @@ -71,14 +70,14 @@ group album_id ( album_price = sum unit_price } ) -join db.albums (==album_id) +join albums (==album_id) group artist_id ( aggregate { track_count = sum track_count, artist_price = sum album_price } ) -join db.artists (==artist_id) +join artists (==artist_id) select {artists.name, artist_price, track_count} sort {-artist_price} derive avg_track_price = artist_price / track_count diff --git a/web/prql-codemirror-demo/src/main.ts b/web/prql-codemirror-demo/src/main.ts index adf3e73730ca..20a51f627c2e 100644 --- a/web/prql-codemirror-demo/src/main.ts +++ b/web/prql-codemirror-demo/src/main.ts @@ -29,7 +29,7 @@ group customer_id ( ) sort {-sum_income} take 10 -join (db.customers | select {c = this}) (==customer_id) +join c=customers (==customer_id) derive name = f"{c.last_name}, {c.first_name}" select { c.customer_id, name, sum_income diff --git a/web/website/content/demos/ace-demo.html b/web/website/content/demos/ace-demo.html index 3818ded679f2..ef6a5fca3481 100644 --- a/web/website/content/demos/ace-demo.html +++ b/web/website/content/demos/ace-demo.html @@ -15,7 +15,7 @@
# https://ace.c9.io/ -from db.invoices +from invoices filter invoice_date >= @1970-01-16 derive { transaction_fees = 0.8, @@ -31,7 +31,7 @@ ) sort {-sum_income} take 10 -join (db.customers | select {c = this}) (==customer_id) +join c=customers (==customer_id) derive name = f"{c.last_name}, {c.first_name}" select { c.customer_id, name, sum_income diff --git a/web/website/content/faq.md b/web/website/content/faq.md index f9d7428514d1..633e196d6190 100644 --- a/web/website/content/faq.md +++ b/web/website/content/faq.md @@ -164,7 +164,7 @@ PRQL clearly delineates two operations with two transforms: exactly one output row for every input row. ```prql - from db.employees + from employees select name = f"{first_name} {last_name}" ``` @@ -172,7 +172,7 @@ PRQL clearly delineates two operations with two transforms: function like `sum` or `min`. ```prql - from db.employees + from employees aggregate [total_salary = sum salary] ``` @@ -181,7 +181,7 @@ same semantics on the group as it would on a whole table — another example of PRQL's orthogonality. ```prql -from db.employees +from employees group department ( aggregate [total_salary = sum salary] ) diff --git a/web/website/content/posts/2022-05-19-examples.md b/web/website/content/posts/2022-05-19-examples.md index d7c21aa8fd94..a01b90e2bb52 100644 --- a/web/website/content/posts/2022-05-19-examples.md +++ b/web/website/content/posts/2022-05-19-examples.md @@ -53,7 +53,7 @@ abstractions: Here's the same query with PRQL: ```prql -from db.employees # Each line transforms the previous result. +from employees # Each line transforms the previous result. filter start_date > @2021-01-01 # Clear date syntax. derive { # `derive` adds columns / variables. gross_salary = salary + payroll_tax, @@ -150,8 +150,8 @@ func lag_day x -> group sec_id ( # `group` is used for wind func ret x -> x / (x | lag_day) - 1 + dividend_return -from db.prices -join db.interest_rates (==date) +from prices +join interest_rates (==date) select [ # `select` only includes unnamed columns, unlike `derive` return_total = prices_adj | ret | if_valid # `|` can be used rather than newlines return_usd = prices_usd | ret | if_valid diff --git a/web/website/content/posts/2023-01-07-functional-relations.md b/web/website/content/posts/2023-01-07-functional-relations.md index e4e05dcc3001..8d01cb230168 100644 --- a/web/website/content/posts/2023-01-07-functional-relations.md +++ b/web/website/content/posts/2023-01-07-functional-relations.md @@ -251,7 +251,7 @@ columns of a relation in function calls: ```prql (select [title, artist_id] default_db.albums) # and with a pipeline: -(from db.albums | select {title, artist_id}) +(from albums | select {title, artist_id}) ``` All these queries can be simplified to an expression of relations and scalars. @@ -300,7 +300,7 @@ applies `aggregate` to each of the groups. This is exactly how PRQL expressed it: ```prql -from db.albums | group artist_id (aggregate {n_albums = count}) +from albums | group artist_id (aggregate {n_albums = count}) ``` This is a lot for one line, so let's unveil new syntactic conveniences: a new @@ -308,7 +308,7 @@ line is a pipe operator and the top-level pipeline does not need parenthesis. I'll also add a new transform at the back, don't worry about it. ```prql -from db.albums +from albums group artist_id ( aggregate {n_albums = count} ) @@ -377,7 +377,7 @@ that can be expressed as `sort x | take 1` (which evaluates to a function), so now surely this should work: ```prql -from db.tab +from tab group y (sort x | take 1) ``` @@ -390,7 +390,7 @@ then take one row from each group". Or another way: "select distinct values of all columns". ```prql -from db.tab +from tab group tab.* (take 1) ``` diff --git a/web/website/content/posts/2023-01-27-prql-query.md b/web/website/content/posts/2023-01-27-prql-query.md index 5777c470251d..dca0083b800e 100644 --- a/web/website/content/posts/2023-01-27-prql-query.md +++ b/web/website/content/posts/2023-01-27-prql-query.md @@ -54,7 +54,7 @@ let substr = text start len -> s"substr({text}, {start}, {len})" # start of the pipeline -from db.tt # as declared in --from +from tt # as declared in --from # compute a few new columns derive [ diff --git a/web/website/content/posts/2023-01-28-format-pretty-reports/_index.md b/web/website/content/posts/2023-01-28-format-pretty-reports/_index.md index fb6fab26bd92..bd9d59f1b2cc 100644 --- a/web/website/content/posts/2023-01-28-format-pretty-reports/_index.md +++ b/web/website/content/posts/2023-01-28-format-pretty-reports/_index.md @@ -101,7 +101,7 @@ let percent_diff = old new -> 100.0*( new - old ) / old let format_percent = v -> s"printf('%1.1f%', {v})" # Step 1: First calculate important columns -from db.PropertyData +from PropertyData select { Map, Lot, App_Total2020, diff --git a/web/website/content/posts/2023-02-02-one-year/_index.md b/web/website/content/posts/2023-02-02-one-year/_index.md index 92b5ebcb2111..898e8f0837ff 100644 --- a/web/website/content/posts/2023-02-02-one-year/_index.md +++ b/web/website/content/posts/2023-02-02-one-year/_index.md @@ -105,7 +105,7 @@ let take_oldest = n rel -> ( take n ) -from db.invoices +from invoices take_oldest 3 ``` diff --git a/web/website/content/posts/2023-03-14-pi-day.md b/web/website/content/posts/2023-03-14-pi-day.md index 01a1507bddbb..28322ce75b99 100644 --- a/web/website/content/posts/2023-03-14-pi-day.md +++ b/web/website/content/posts/2023-03-14-pi-day.md @@ -182,7 +182,7 @@ let q_steps = step_q9 step_q10 step_j2 step_jg2 other -> case [ ] -from db.config +from config select [ num_digits, array_len, diff --git a/web/website/data/examples/basic.yaml b/web/website/data/examples/basic.yaml index e75bbcc31b4e..b8d176b8b49b 100644 --- a/web/website/data/examples/basic.yaml +++ b/web/website/data/examples/basic.yaml @@ -1,6 +1,6 @@ label: Basic example prql: | - from db.employees + from employees select {id, first_name, age} sort age take 10 diff --git a/web/website/data/examples/dialects.yaml b/web/website/data/examples/dialects.yaml index 7f5b0cf192ec..161ae5bf2162 100644 --- a/web/website/data/examples/dialects.yaml +++ b/web/website/data/examples/dialects.yaml @@ -2,7 +2,7 @@ label: Dialects prql: | prql target:sql.mssql # Will generate TOP rather than LIMIT - from db.employees + from employees sort age take 10 sql: | diff --git a/web/website/data/examples/expressions.yaml b/web/website/data/examples/expressions.yaml index 63aa1f49cee2..32bbdf8e8013 100644 --- a/web/website/data/examples/expressions.yaml +++ b/web/website/data/examples/expressions.yaml @@ -1,6 +1,6 @@ label: Expressions prql: | - from db.track_plays + from track_plays derive { finished = started + unfinished, fin_share = finished / started, # Use previous definitions diff --git a/web/website/data/examples/f-strings.yaml b/web/website/data/examples/f-strings.yaml index e5d772f05903..150b6655d2fa 100644 --- a/web/website/data/examples/f-strings.yaml +++ b/web/website/data/examples/f-strings.yaml @@ -1,6 +1,6 @@ label: F-strings prql: | - from db.web + from web # Just like Python select url = f"https://www.{domain}.{tld}/{page}" sql: | diff --git a/web/website/data/examples/friendly-syntax.yaml b/web/website/data/examples/friendly-syntax.yaml index ee7c951fb8d9..4a23ec97330c 100644 --- a/web/website/data/examples/friendly-syntax.yaml +++ b/web/website/data/examples/friendly-syntax.yaml @@ -1,6 +1,6 @@ label: Friendly syntax prql: | - from db.track_plays + from track_plays filter plays > 10_000 # Readable numbers filter (length | in 60..240) # Ranges with `..` filter recorded > @2008-01-01 # Simple date literals diff --git a/web/website/data/examples/functions.yaml b/web/website/data/examples/functions.yaml index cff70275f0fb..eed045ff2822 100644 --- a/web/website/data/examples/functions.yaml +++ b/web/website/data/examples/functions.yaml @@ -2,7 +2,7 @@ label: Functions prql: | let celsius_to_fahrenheit = temp -> temp * 9/5 + 32 - from db.weather + from weather select temp_f = (celsius_to_fahrenheit temp_c) sql: | SELECT diff --git a/web/website/data/examples/hero.yaml b/web/website/data/examples/hero.yaml index b7b0d4d8cb75..90c24edf4ce7 100644 --- a/web/website/data/examples/hero.yaml +++ b/web/website/data/examples/hero.yaml @@ -1,5 +1,5 @@ prql: | - from db.invoices + from invoices filter invoice_date >= @1970-01-16 derive { transaction_fees = 0.8, @@ -15,7 +15,7 @@ prql: | ) sort {-sum_income} take 10 - join (db.customers | select {c = this}) (==customer_id) + join c=customers (==customer_id) derive name = f"{c.last_name}, {c.first_name}" select { c.customer_id, name, sum_income diff --git a/web/website/data/examples/joins.yaml b/web/website/data/examples/joins.yaml index ee10ee568917..b1684163c352 100644 --- a/web/website/data/examples/joins.yaml +++ b/web/website/data/examples/joins.yaml @@ -1,8 +1,8 @@ label: Joins prql: | - from db.employees - join b = db.benefits (==employee_id) - join side:left p = db.positions (p.id==employees.employee_id) + from employees + join b=benefits (==employee_id) + join side:left p=positions (p.id==employees.employee_id) select {employees.employee_id, p.role, b.vision_coverage} sql: | SELECT diff --git a/web/website/data/examples/null-handling.yaml b/web/website/data/examples/null-handling.yaml index d7240fd7cdeb..38bab1ea3c44 100644 --- a/web/website/data/examples/null-handling.yaml +++ b/web/website/data/examples/null-handling.yaml @@ -1,6 +1,6 @@ label: Null handling prql: | - from db.users + from users filter last_login != null filter deleted_at == null derive channel = channel ?? "unknown" diff --git a/web/website/data/examples/orthogonal.yaml b/web/website/data/examples/orthogonal.yaml index bb7973d7997e..291cf03090f6 100644 --- a/web/website/data/examples/orthogonal.yaml +++ b/web/website/data/examples/orthogonal.yaml @@ -1,6 +1,6 @@ label: Orthogonality prql: | - from db.employees + from employees # `filter` before aggregations... filter start_date > @2021-01-01 group country ( diff --git a/web/website/data/examples/s-strings.yaml b/web/website/data/examples/s-strings.yaml index ebb0fc68c05d..6d71f2eff950 100644 --- a/web/website/data/examples/s-strings.yaml +++ b/web/website/data/examples/s-strings.yaml @@ -2,7 +2,7 @@ label: S-strings prql: | # There's no `version` in PRQL, but s-strings # let us embed SQL as an escape hatch: - from db.x + from x derive db_version = s"version()" sql: | SELECT diff --git a/web/website/data/examples/top-n.yaml b/web/website/data/examples/top-n.yaml index 3c21d82ee95b..9de7505c2344 100644 --- a/web/website/data/examples/top-n.yaml +++ b/web/website/data/examples/top-n.yaml @@ -2,7 +2,7 @@ label: Top N by group prql: | # Most recent employee in each role # Quite difficult in SQL... - from db.employees + from employees group role ( sort join_date take 1 diff --git a/web/website/data/examples/windows.yaml b/web/website/data/examples/windows.yaml index f861373ba927..cbfb365630d8 100644 --- a/web/website/data/examples/windows.yaml +++ b/web/website/data/examples/windows.yaml @@ -1,6 +1,6 @@ label: Windows prql: | - from db.employees + from employees group employee_id ( sort month window rolling:12 (