diff --git a/deny.toml b/deny.toml index f9962c86..7b2f31e9 100644 --- a/deny.toml +++ b/deny.toml @@ -126,15 +126,13 @@ allow = [ deny = [ # Use `once_cell` instead # `OnceCell`s API is under consideration for inclusion in `std`: https://github.com/rust-lang/rust/issues/74465 - { name = "lazy_static", wrappers = ["Inflector", "criterion"]}, - - + { name = "lazy_static", wrappers = ["Inflector", "criterion", "insta"] }, # Advisory: https://rustsec.org/advisories/RUSTSEC-2020-0071 # `time` < 0.2.23 has a potential (though unlikely) potential segfault - { name = "time", version ="<0.2.23", wrappers = ["chrono"]}, + { name = "time", version = "<0.2.23", wrappers = ["chrono"] }, # Advisory: https://rustsec.org/advisories/RUSTSEC-2020-0071 # `chrono` uses an old version of `time`, but `chrono` >= 4.2 doesn't use the code path with the issue - { name = "chrono", version ="<0.4.20"} + { name = "chrono", version = "<0.4.20" } ] diff --git a/partiql-ast/Cargo.toml b/partiql-ast/Cargo.toml index a9f1624f..b16e849a 100644 --- a/partiql-ast/Cargo.toml +++ b/partiql-ast/Cargo.toml @@ -28,6 +28,8 @@ thiserror = "1.0" [dev-dependencies] partiql-parser = { path = "../partiql-parser", version = "0.8" } +itertools = "0.13" +insta = "1.38.0" [features] default = [] diff --git a/partiql-ast/tests/common.rs b/partiql-ast/tests/pretty.rs similarity index 54% rename from partiql-ast/tests/common.rs rename to partiql-ast/tests/pretty.rs index ec30d1e2..ab4ec023 100644 --- a/partiql-ast/tests/common.rs +++ b/partiql-ast/tests/pretty.rs @@ -1,10 +1,7 @@ +use itertools::Itertools; use partiql_ast::pretty::ToPretty; use partiql_parser::ParserResult; -pub fn setup() { - // setup test code goes here -} - #[track_caller] #[inline] fn parse(statement: &str) -> ParserResult<'_> { @@ -13,19 +10,33 @@ fn parse(statement: &str) -> ParserResult<'_> { #[track_caller] #[inline] -fn pretty_print_test(statement: &str) { +fn pretty_print_test(name: &str, statement: &str) { let res = parse(statement); assert!(res.is_ok()); let res = res.unwrap(); + // TODO https://github.com/partiql/partiql-lang-rust/issues/473 - for w in [180, 120, 80, 40, 30, 20, 10] { - println!("{:- 2 ORDER BY a LIMIT 1 OFFSET 1"); + pretty_print_test( + "having_limit_offset", + "SELECT a FROM foo GROUP BY a HAVING a > 2 ORDER BY a LIMIT 1 OFFSET 1", + ); } #[test] fn pretty_select_value_unpivot() { - pretty_print_test("SELECT VALUE foo FROM (SELECT VALUE v FROM UNPIVOT e AS v) AS foo"); + pretty_print_test( + "select value unpivot", + "SELECT VALUE foo FROM (SELECT VALUE v FROM UNPIVOT e AS v) AS foo", + ); } #[test] fn pretty_select_value_tuple_ctor() { - pretty_print_test("SELECT VALUE {'a':v.a, 'b':v.b} FROM [{'a':1, 'b':1}, {'a':2, 'b':2}] AS v"); + pretty_print_test( + "pretty_select_value_tuple_ctor", + "SELECT VALUE {'a':v.a, 'b':v.b} FROM [{'a':1, 'b':1}, {'a':2, 'b':2}] AS v", + ); } #[test] fn pretty_from_comma() { - pretty_print_test("SELECT a, b FROM T1, T2"); + pretty_print_test("pretty_from_comma", "SELECT a, b FROM T1, T2"); } #[test] fn pretty_expr_in() { - pretty_print_test("(a, b) IN ((1, 2), (3, 4))"); + pretty_print_test("pretty_expr_in", "(a, b) IN ((1, 2), (3, 4))"); } #[test] fn pretty_setop() { pretty_print_test( + "pretty_setop", "(SELECT a1 FROM b1 ORDER BY c1 LIMIT d1 OFFSET e1) UNION (SELECT a2 FROM b2 ORDER BY c2 LIMIT d2 OFFSET e2) @@ -88,6 +110,7 @@ fn pretty_setop() { #[test] fn pretty_bagop() { pretty_print_test( + "pretty_bagop", " ( (SELECT a1 FROM b1 ORDER BY c1 LIMIT d1 OFFSET e1) @@ -103,6 +126,7 @@ fn pretty_bagop() { #[test] fn pretty_join() { pretty_print_test( + "pretty_join", " SELECT t1.id AS id, t1.val AS val1, t2.val AS val2 FROM table1 AS t1 JOIN table1_null_row AS t2 ON t1.id = t2.id", @@ -111,27 +135,31 @@ fn pretty_join() { #[test] fn pretty_kw_fns() { - pretty_print_test("trim(trailing from 'test')"); - pretty_print_test("POSITION('abc' IN 'abcdefg')"); - pretty_print_test("substring('test', 100, 50)"); - pretty_print_test("substring('test', 100)"); + pretty_print_test("pretty_kw_fn1", "trim(trailing from 'test')"); + pretty_print_test("pretty_kw_fn2", "POSITION('abc' IN 'abcdefg')"); + pretty_print_test("pretty_kw_fn3", "substring('test', 100, 50)"); + pretty_print_test("pretty_kw_fn4", "substring('test', 100)"); } #[test] fn pretty_typed_lits() { - pretty_print_test("TIME WITH TIME ZONE '23:59:59.1234567890+18:00'"); - pretty_print_test("TIME (3) WITH TIME ZONE '12:59:31'"); + pretty_print_test( + "pretty_typed_lits1", + "TIME WITH TIME ZONE '23:59:59.1234567890+18:00'", + ); + pretty_print_test("pretty_typed_lits2", "TIME (3) WITH TIME ZONE '12:59:31'"); } #[test] fn pretty_case() { - pretty_print_test("SELECT VALUE CASE WHEN x + 1 < i THEN '< ONE' WHEN x + 1 = f THEN 'TWO' WHEN (x + 1 > d) AND (x + 1 < 100) THEN '>= THREE < 100' ELSE '?' END FROM << -1.0000, i, f, d, 100e0, null, missing >> AS x"); - pretty_print_test("SELECT VALUE CASE x + 1 WHEN NULL THEN 'shouldnt be null' WHEN MISSING THEN 'shouldnt be missing' WHEN i THEN 'ONE' WHEN f THEN 'TWO' WHEN d THEN 'THREE' END FROM << i, f, d, null, missing >> AS x"); + pretty_print_test("pretty_case_1", "SELECT VALUE CASE WHEN x + 1 < i THEN '< ONE' WHEN x + 1 = f THEN 'TWO' WHEN (x + 1 > d) AND (x + 1 < 100) THEN '>= THREE < 100' ELSE '?' END FROM << -1.0000, i, f, d, 100e0, null, missing >> AS x"); + pretty_print_test("pretty_case_2","SELECT VALUE CASE x + 1 WHEN NULL THEN 'shouldnt be null' WHEN MISSING THEN 'shouldnt be missing' WHEN i THEN 'ONE' WHEN f THEN 'TWO' WHEN d THEN 'THREE' END FROM << i, f, d, null, missing >> AS x"); } #[test] fn pretty_pivot() { pretty_print_test( + "pretty_pivot", " PIVOT foo.a AT foo.b FROM <<{'a': 1, 'b':'I'}, {'a': 2, 'b':'II'}, {'a': 3, 'b':'III'}>> AS foo diff --git a/partiql-ast/tests/snapshots/pretty__having_limit_offset.snap b/partiql-ast/tests/snapshots/pretty__having_limit_offset.snap new file mode 100644 index 00000000..3e011962 --- /dev/null +++ b/partiql-ast/tests/snapshots/pretty__having_limit_offset.snap @@ -0,0 +1,42 @@ +--- +source: partiql-ast/tests/pretty.rs +expression: doc +--- +======================================================================================================================================================================================================== +SELECT a FROM foo GROUP BY a HAVING a > 2 ORDER BY a LIMIT 1 OFFSET 1 +======================================================================================================================================================================================================== + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +SELECT a FROM foo GROUP BY a HAVING (a > 2) ORDER BY a LIMIT 1 OFFSET 1 + +------------------------------------------------------------------------------------------------------------------------ +SELECT a FROM foo GROUP BY a HAVING (a > 2) ORDER BY a LIMIT 1 OFFSET 1 + +-------------------------------------------------------------------------------- +SELECT a FROM foo GROUP BY a HAVING (a > 2) ORDER BY a LIMIT 1 OFFSET 1 + +---------------------------------------- +SELECT a FROM foo GROUP BY a +HAVING (a > 2) ORDER BY a LIMIT 1 +OFFSET 1 + +------------------------------ +SELECT a FROM foo GROUP BY a +HAVING (a > 2) ORDER BY a +LIMIT 1 OFFSET 1 + +-------------------- +SELECT a FROM foo +GROUP BY a +HAVING (a > 2) +ORDER BY a LIMIT 1 +OFFSET 1 + +---------- +SELECT a +FROM foo +GROUP BY a +HAVING (a > 2) +ORDER BY a +LIMIT 1 +OFFSET 1 diff --git a/partiql-ast/tests/snapshots/pretty__pretty.snap b/partiql-ast/tests/snapshots/pretty__pretty.snap new file mode 100644 index 00000000..20a40166 --- /dev/null +++ b/partiql-ast/tests/snapshots/pretty__pretty.snap @@ -0,0 +1,149 @@ +--- +source: partiql-ast/tests/pretty.rs +expression: doc +--- +======================================================================================================================================================================================================== +select foo,bar, baz,thud.*,grunt.a[*].b[2].*, count(1) as n from + << + { 'foo': 'foo', 'x': 9, 'y':5, z:-11 }, + { 'foo': 'bar' }, + { 'foo': 'qux' }, + { 'foo': 'bar' }, + { 'foo': 'baz' }, + { 'foo': 'bar' }, + { 'foo': 'baz' } + >> group by foo order by n desc +======================================================================================================================================================================================================== + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +SELECT foo, bar, baz, thud.*, grunt.a[*].b[2].*, count(1) AS n FROM << + { 'foo': 'foo', 'x': 9, 'y': 5, z: -11 }, + { 'foo': 'bar' }, + { 'foo': 'qux' }, + { 'foo': 'bar' }, + { 'foo': 'baz' }, + { 'foo': 'bar' }, + { 'foo': 'baz' } + >> GROUP BY foo ORDER BY n DESC + +------------------------------------------------------------------------------------------------------------------------ +SELECT foo, bar, baz, thud.*, grunt.a[*].b[2].*, count(1) AS n FROM << + { 'foo': 'foo', 'x': 9, 'y': 5, z: -11 }, + { 'foo': 'bar' }, + { 'foo': 'qux' }, + { 'foo': 'bar' }, + { 'foo': 'baz' }, + { 'foo': 'bar' }, + { 'foo': 'baz' } + >> GROUP BY foo ORDER BY n DESC + +-------------------------------------------------------------------------------- +SELECT foo, bar, baz, thud.*, grunt.a[*].b[2].*, count(1) AS n FROM << + { 'foo': 'foo', 'x': 9, 'y': 5, z: -11 }, + { 'foo': 'bar' }, + { 'foo': 'qux' }, + { 'foo': 'bar' }, + { 'foo': 'baz' }, + { 'foo': 'bar' }, + { 'foo': 'baz' } + >> GROUP BY foo ORDER BY n DESC + +---------------------------------------- +SELECT foo, bar, baz, thud.*, + grunt.a[*].b[2].*, count(1) AS n +FROM << + { + 'foo': 'foo', + 'x': 9, + 'y': 5, + z: -11 + }, + { 'foo': 'bar' }, + { 'foo': 'qux' }, + { 'foo': 'bar' }, + { 'foo': 'baz' }, + { 'foo': 'bar' }, + { 'foo': 'baz' } + >> GROUP BY foo ORDER BY n DESC + +------------------------------ +SELECT foo, bar, baz, thud.*, + grunt.a[*].b[2].*, + count(1) AS n FROM << + { + 'foo': 'foo', + 'x': 9, + 'y': 5, + z: -11 + }, + { 'foo': 'bar' }, + { 'foo': 'qux' }, + { 'foo': 'bar' }, + { 'foo': 'baz' }, + { 'foo': 'bar' }, + { 'foo': 'baz' } + >> GROUP BY foo +ORDER BY n DESC + +-------------------- +SELECT foo, bar, + baz, thud.*, + grunt.a[*].b[2].*, + count(1) AS n +FROM << + { + 'foo': 'foo', + 'x': 9, + 'y': 5, + z: -11 + }, + { 'foo': 'bar' + }, + { 'foo': 'qux' + }, + { 'foo': 'bar' + }, + { 'foo': 'baz' + }, + { 'foo': 'bar' + }, + { 'foo': 'baz' } + >> GROUP BY foo +ORDER BY n DESC + +---------- +SELECT foo, + bar, + baz, + thud.*, + grunt.a[*].b[2].*, + count(1) AS n +FROM << + { + 'foo': 'foo', + 'x': 9, + 'y': 5, + z: -11 + }, + { + 'foo': 'bar' + }, + { + 'foo': 'qux' + }, + { + 'foo': 'bar' + }, + { + 'foo': 'baz' + }, + { + 'foo': 'bar' + }, + { + 'foo': 'baz' + } + >> +GROUP BY +foo +ORDER BY n DESC diff --git a/partiql-ast/tests/snapshots/pretty__pretty2.snap b/partiql-ast/tests/snapshots/pretty__pretty2.snap new file mode 100644 index 00000000..ef85961e --- /dev/null +++ b/partiql-ast/tests/snapshots/pretty__pretty2.snap @@ -0,0 +1,62 @@ +--- +source: partiql-ast/tests/pretty.rs +expression: doc +--- +======================================================================================================================================================================================================== +select foo,bar, baz,thud,grunt, count(1) as n from + (SELECT * FROM table1) + where (bar between 3 and 25 AND baz NOT LIKE 'example%') OR foo.a.b[*] IS MISSING + group by foo + order by n desc +======================================================================================================================================================================================================== + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +SELECT foo, bar, baz, thud, grunt, count(1) AS n FROM (SELECT * FROM table1) WHERE ((bar BETWEEN 3 AND 25 AND NOT (baz LIKE 'example%')) OR (foo.a.b[*] IS MISSING)) GROUP BY foo +ORDER BY n DESC + +------------------------------------------------------------------------------------------------------------------------ +SELECT foo, bar, baz, thud, grunt, count(1) AS n FROM (SELECT * FROM table1) +WHERE ((bar BETWEEN 3 AND 25 AND NOT (baz LIKE 'example%')) OR (foo.a.b[*] IS MISSING)) GROUP BY foo ORDER BY n DESC + +-------------------------------------------------------------------------------- +SELECT foo, bar, baz, thud, grunt, count(1) AS n FROM (SELECT * FROM table1) +WHERE ((bar BETWEEN 3 AND 25 AND NOT (baz LIKE 'example%')) OR (foo.a.b[*] IS MISSING)) +GROUP BY foo ORDER BY n DESC + +---------------------------------------- +SELECT foo, bar, baz, thud, grunt, + count(1) AS n FROM (SELECT * + FROM table1) +WHERE ((bar BETWEEN 3 AND 25 AND NOT (baz LIKE 'example%')) OR (foo.a.b[*] IS MISSING)) +GROUP BY foo ORDER BY n DESC + +------------------------------ +SELECT foo, bar, baz, thud, + grunt, count(1) AS n +FROM (SELECT * FROM table1) +WHERE ((bar BETWEEN 3 AND 25 AND NOT (baz LIKE 'example%')) OR (foo.a.b[*] IS MISSING)) +GROUP BY foo ORDER BY n DESC + +-------------------- +SELECT foo, bar, + baz, thud, grunt, + count(1) AS n +FROM (SELECT * + FROM table1) +WHERE ((bar BETWEEN 3 AND 25 AND NOT (baz LIKE 'example%')) OR (foo.a.b[*] IS MISSING)) +GROUP BY foo +ORDER BY n DESC + +---------- +SELECT foo, + bar, + baz, + thud, + grunt, + count(1) AS n +FROM (SELECT * + FROM table1) +WHERE ((bar BETWEEN 3 AND 25 AND NOT (baz LIKE 'example%')) OR (foo.a.b[*] IS MISSING)) +GROUP BY +foo +ORDER BY n DESC diff --git a/partiql-ast/tests/snapshots/pretty__pretty_bagop.snap b/partiql-ast/tests/snapshots/pretty__pretty_bagop.snap new file mode 100644 index 00000000..b1841f94 --- /dev/null +++ b/partiql-ast/tests/snapshots/pretty__pretty_bagop.snap @@ -0,0 +1,104 @@ +--- +source: partiql-ast/tests/pretty.rs +expression: doc +--- +======================================================================================================================================================================================================== + + ( + (SELECT a1 FROM b1 ORDER BY c1 LIMIT d1 OFFSET e1) + UNION DISTINCT + (SELECT a2 FROM b2 ORDER BY c2 LIMIT d2 OFFSET e2) + ) + OUTER UNION ALL + (SELECT a3 FROM b3 ORDER BY c3 LIMIT d3 OFFSET e3) + ORDER BY c4 LIMIT d4 OFFSET e4 +======================================================================================================================================================================================================== + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +( ( SELECT a1 FROM b1 ORDER BY c1 LIMIT d1 OFFSET e1 ) + UNION DISTINCT + ( SELECT a2 FROM b2 ORDER BY c2 LIMIT d2 OFFSET e2 ) ) +OUTER UNION ALL +( SELECT a3 FROM b3 ORDER BY c3 LIMIT d3 OFFSET e3 ) ORDER BY c4 LIMIT d4 OFFSET e4 + +------------------------------------------------------------------------------------------------------------------------ +( ( SELECT a1 FROM b1 ORDER BY c1 LIMIT d1 OFFSET e1 ) + UNION DISTINCT + ( SELECT a2 FROM b2 ORDER BY c2 LIMIT d2 OFFSET e2 ) ) +OUTER UNION ALL +( SELECT a3 FROM b3 ORDER BY c3 LIMIT d3 OFFSET e3 ) ORDER BY c4 LIMIT d4 OFFSET e4 + +-------------------------------------------------------------------------------- +( ( SELECT a1 FROM b1 ORDER BY c1 LIMIT d1 OFFSET e1 ) + UNION DISTINCT + ( SELECT a2 FROM b2 ORDER BY c2 LIMIT d2 OFFSET e2 ) ) +OUTER UNION ALL +( SELECT a3 FROM b3 ORDER BY c3 LIMIT d3 OFFSET e3 ) ORDER BY c4 LIMIT d4 +OFFSET e4 + +---------------------------------------- +( ( SELECT a1 FROM b1 ORDER BY c1 + LIMIT d1 OFFSET e1 ) + UNION DISTINCT + ( SELECT a2 FROM b2 ORDER BY c2 + LIMIT d2 OFFSET e2 ) ) +OUTER UNION ALL +( SELECT a3 FROM b3 ORDER BY c3 LIMIT d3 + OFFSET e3 ) ORDER BY c4 LIMIT d4 +OFFSET e4 + +------------------------------ +( ( SELECT a1 FROM b1 + ORDER BY c1 LIMIT d1 + OFFSET e1 ) + UNION DISTINCT + ( SELECT a2 FROM b2 + ORDER BY c2 LIMIT d2 + OFFSET e2 ) ) +OUTER UNION ALL +( SELECT a3 FROM b3 + ORDER BY c3 LIMIT d3 + OFFSET e3 ) ORDER BY c4 +LIMIT d4 OFFSET e4 + +-------------------- +( ( SELECT a1 + FROM b1 + ORDER BY c1 + LIMIT d1 + OFFSET e1 ) + UNION DISTINCT + ( SELECT a2 + FROM b2 + ORDER BY c2 + LIMIT d2 + OFFSET e2 ) ) +OUTER UNION ALL +( SELECT a3 FROM b3 + ORDER BY c3 + LIMIT d3 + OFFSET e3 ) +ORDER BY c4 LIMIT d4 +OFFSET e4 + +---------- +( ( SELECT a1 + FROM b1 + ORDER BY c1 + LIMIT d1 + OFFSET e1 ) + UNION DISTINCT + ( SELECT a2 + FROM b2 + ORDER BY c2 + LIMIT d2 + OFFSET e2 ) ) +OUTER UNION ALL +( SELECT a3 + FROM b3 + ORDER BY c3 + LIMIT d3 + OFFSET e3 ) +ORDER BY c4 +LIMIT d4 +OFFSET e4 diff --git a/partiql-ast/tests/snapshots/pretty__pretty_case_1.snap b/partiql-ast/tests/snapshots/pretty__pretty_case_1.snap new file mode 100644 index 00000000..5aa8e7b3 --- /dev/null +++ b/partiql-ast/tests/snapshots/pretty__pretty_case_1.snap @@ -0,0 +1,89 @@ +--- +source: partiql-ast/tests/pretty.rs +expression: doc +--- +======================================================================================================================================================================================================== +SELECT VALUE CASE WHEN x + 1 < i THEN '< ONE' WHEN x + 1 = f THEN 'TWO' WHEN (x + 1 > d) AND (x + 1 < 100) THEN '>= THREE < 100' ELSE '?' END FROM << -1.0000, i, f, d, 100e0, null, missing >> AS x +======================================================================================================================================================================================================== + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +SELECT VALUE CASE WHEN ((x + 1) < i) THEN '< ONE' WHEN ((x + 1) = f) THEN 'TWO' WHEN (((x + 1) > d) AND ((x + 1) < 100)) THEN '>= THREE < 100' ELSE '?' FROM << + -1.0000, + i, + f, + d, + 100, + NULL, + MISSING + >> AS x + +------------------------------------------------------------------------------------------------------------------------ +SELECT VALUE CASE WHEN ((x + 1) < i) THEN '< ONE' WHEN ((x + 1) = f) THEN 'TWO' + WHEN (((x + 1) > d) AND ((x + 1) < 100)) THEN '>= THREE < 100' ELSE '?' FROM << -1.0000, i, f, d, 100, NULL, MISSING + >> AS x + +-------------------------------------------------------------------------------- +SELECT VALUE CASE WHEN ((x + 1) < i) THEN '< ONE' WHEN ((x + 1) = f) THEN 'TWO' + WHEN (((x + 1) > d) AND ((x + 1) < 100)) THEN '>= THREE < 100' ELSE '?' +FROM << -1.0000, i, f, d, 100, NULL, MISSING >> AS x + +---------------------------------------- +SELECT VALUE CASE + WHEN ((x + 1) < i) THEN '< ONE' + WHEN ((x + 1) = f) THEN 'TWO' + WHEN (((x + 1) > d) AND ((x + 1) < 100)) THEN '>= THREE < 100' + ELSE '?' FROM << + -1.0000, + i, + f, + d, + 100, + NULL, + MISSING + >> AS x + +------------------------------ +SELECT VALUE CASE + WHEN ((x + 1) < i) THEN '< ONE' + WHEN ((x + 1) = f) THEN 'TWO' + WHEN (((x + 1) > d) AND ((x + 1) < 100)) THEN '>= THREE < 100' + ELSE '?' FROM << + -1.0000, + i, + f, + d, + 100, + NULL, + MISSING + >> AS x + +-------------------- +SELECT VALUE CASE + WHEN ((x + 1) < i) THEN '< ONE' + WHEN ((x + 1) = f) THEN 'TWO' + WHEN (((x + 1) > d) AND ((x + 1) < 100)) THEN '>= THREE < 100' + ELSE '?' FROM << + -1.0000, + i, + f, + d, + 100, + NULL, + MISSING + >> AS x + +---------- +SELECT VALUE CASE + WHEN ((x + 1) < i) THEN '< ONE' + WHEN ((x + 1) = f) THEN 'TWO' + WHEN (((x + 1) > d) AND ((x + 1) < 100)) THEN '>= THREE < 100' + ELSE '?' +FROM << + -1.0000, + i, + f, + d, + 100, + NULL, + MISSING + >> AS x diff --git a/partiql-ast/tests/snapshots/pretty__pretty_case_2.snap b/partiql-ast/tests/snapshots/pretty__pretty_case_2.snap new file mode 100644 index 00000000..ed115ee4 --- /dev/null +++ b/partiql-ast/tests/snapshots/pretty__pretty_case_2.snap @@ -0,0 +1,80 @@ +--- +source: partiql-ast/tests/pretty.rs +expression: doc +--- +======================================================================================================================================================================================================== +SELECT VALUE CASE x + 1 WHEN NULL THEN 'shouldnt be null' WHEN MISSING THEN 'shouldnt be missing' WHEN i THEN 'ONE' WHEN f THEN 'TWO' WHEN d THEN 'THREE' END FROM << i, f, d, null, missing >> AS x +======================================================================================================================================================================================================== + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +SELECT VALUE CASE (x + 1) WHEN NULL THEN 'shouldnt be null' WHEN MISSING THEN 'shouldnt be missing' WHEN i THEN 'ONE' WHEN f THEN 'TWO' WHEN d THEN 'THREE' FROM << + i, + f, + d, + NULL, + MISSING + >> AS x + +------------------------------------------------------------------------------------------------------------------------ +SELECT VALUE CASE (x + 1) WHEN NULL THEN 'shouldnt be null' WHEN MISSING THEN 'shouldnt be missing' WHEN i THEN 'ONE' + WHEN f THEN 'TWO' WHEN d THEN 'THREE' FROM << i, f, d, NULL, MISSING >> AS x + +-------------------------------------------------------------------------------- +SELECT VALUE CASE (x + 1) WHEN NULL THEN 'shouldnt be null' + WHEN MISSING THEN 'shouldnt be missing' WHEN i THEN 'ONE' WHEN f THEN 'TWO' + WHEN d THEN 'THREE' FROM << i, f, d, NULL, MISSING >> AS x + +---------------------------------------- +SELECT VALUE CASE (x + 1) + WHEN NULL THEN 'shouldnt be null' + WHEN MISSING THEN 'shouldnt be missing' + WHEN i THEN 'ONE' WHEN f THEN 'TWO' + WHEN d THEN 'THREE' FROM << + i, + f, + d, + NULL, + MISSING + >> AS x + +------------------------------ +SELECT VALUE CASE (x + 1) + WHEN NULL THEN 'shouldnt be null' + WHEN MISSING THEN 'shouldnt be missing' + WHEN i THEN 'ONE' + WHEN f THEN 'TWO' + WHEN d THEN 'THREE' +FROM << i, f, d, NULL, MISSING + >> AS x + +-------------------- +SELECT VALUE CASE + (x + 1) + WHEN NULL THEN 'shouldnt be null' + WHEN MISSING THEN 'shouldnt be missing' + WHEN i THEN 'ONE' + WHEN f THEN 'TWO' + WHEN d THEN 'THREE' +FROM << + i, + f, + d, + NULL, + MISSING + >> AS x + +---------- +SELECT VALUE CASE + (x + 1) + WHEN NULL THEN 'shouldnt be null' + WHEN MISSING THEN 'shouldnt be missing' + WHEN i THEN 'ONE' + WHEN f THEN 'TWO' + WHEN d THEN 'THREE' +FROM << + i, + f, + d, + NULL, + MISSING + >> AS x diff --git a/partiql-ast/tests/snapshots/pretty__pretty_expr_in.snap b/partiql-ast/tests/snapshots/pretty__pretty_expr_in.snap new file mode 100644 index 00000000..cb931e4f --- /dev/null +++ b/partiql-ast/tests/snapshots/pretty__pretty_expr_in.snap @@ -0,0 +1,39 @@ +--- +source: partiql-ast/tests/pretty.rs +expression: doc +--- +======================================================================================================================================================================================================== +(a, b) IN ((1, 2), (3, 4)) +======================================================================================================================================================================================================== + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +[ a, b ] IN [ [ 1, 2 ], [ 3, 4 ] ] + +------------------------------------------------------------------------------------------------------------------------ +[ a, b ] IN [ [ 1, 2 ], [ 3, 4 ] ] + +-------------------------------------------------------------------------------- +[ a, b ] IN [ [ 1, 2 ], [ 3, 4 ] ] + +---------------------------------------- +[ a, b ] IN [ [ 1, 2 ], [ 3, 4 ] ] + +------------------------------ +[ a, b ] IN [ + [ 1, 2 ], + [ 3, 4 ] +] + +-------------------- +[ a, b ] IN [ + [ 1, 2 ], + [ 3, 4 ] +] + +---------- +[ a, b +] IN [ + [ 1, 2 + ], + [ 3, 4 ] +] diff --git a/partiql-ast/tests/snapshots/pretty__pretty_from_comma.snap b/partiql-ast/tests/snapshots/pretty__pretty_from_comma.snap new file mode 100644 index 00000000..ef6b556a --- /dev/null +++ b/partiql-ast/tests/snapshots/pretty__pretty_from_comma.snap @@ -0,0 +1,32 @@ +--- +source: partiql-ast/tests/pretty.rs +expression: doc +--- +======================================================================================================================================================================================================== +SELECT a, b FROM T1, T2 +======================================================================================================================================================================================================== + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +SELECT a, b FROM T1, T2 + +------------------------------------------------------------------------------------------------------------------------ +SELECT a, b FROM T1, T2 + +-------------------------------------------------------------------------------- +SELECT a, b FROM T1, T2 + +---------------------------------------- +SELECT a, b FROM T1, T2 + +------------------------------ +SELECT a, b FROM T1, T2 + +-------------------- +SELECT a, b FROM T1, + T2 + +---------- +SELECT a, + b +FROM T1, + T2 diff --git a/partiql-ast/tests/snapshots/pretty__pretty_join.snap b/partiql-ast/tests/snapshots/pretty__pretty_join.snap new file mode 100644 index 00000000..9cb90a86 --- /dev/null +++ b/partiql-ast/tests/snapshots/pretty__pretty_join.snap @@ -0,0 +1,47 @@ +--- +source: partiql-ast/tests/pretty.rs +expression: doc +--- +======================================================================================================================================================================================================== + + SELECT t1.id AS id, t1.val AS val1, t2.val AS val2 + FROM table1 AS t1 JOIN table1_null_row AS t2 ON t1.id = t2.id +======================================================================================================================================================================================================== + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +SELECT t1.id AS id, t1.val AS val1, t2.val AS val2 FROM table1 AS t1 INNER JOIN table1_null_row AS t2 ON (t1.id = t2.id) + +------------------------------------------------------------------------------------------------------------------------ +SELECT t1.id AS id, t1.val AS val1, t2.val AS val2 FROM table1 AS t1 INNER JOIN table1_null_row AS t2 ON (t1.id = t2.id) + +-------------------------------------------------------------------------------- +SELECT t1.id AS id, t1.val AS val1, t2.val AS val2 +FROM table1 AS t1 INNER JOIN table1_null_row AS t2 ON (t1.id = t2.id) + +---------------------------------------- +SELECT t1.id AS id, t1.val AS val1, + t2.val AS val2 +FROM table1 AS t1 INNER JOIN table1_null_row AS t2 + ON (t1.id = t2.id) + +------------------------------ +SELECT t1.id AS id, + t1.val AS val1, + t2.val AS val2 +FROM table1 AS t1 INNER JOIN table1_null_row AS t2 + ON (t1.id = t2.id) + +-------------------- +SELECT t1.id AS id, + t1.val AS val1, + t2.val AS val2 +FROM table1 AS t1 INNER JOIN table1_null_row AS t2 + ON (t1.id = t2.id) + +---------- +SELECT t1.id AS id, + t1.val AS val1, + t2.val AS val2 +FROM table1 AS t1 INNER JOIN table1_null_row AS t2 + ON + (t1.id = t2.id) diff --git a/partiql-ast/tests/snapshots/pretty__pretty_kw_fn1.snap b/partiql-ast/tests/snapshots/pretty__pretty_kw_fn1.snap new file mode 100644 index 00000000..cdd00ae1 --- /dev/null +++ b/partiql-ast/tests/snapshots/pretty__pretty_kw_fn1.snap @@ -0,0 +1,31 @@ +--- +source: partiql-ast/tests/pretty.rs +expression: doc +--- +======================================================================================================================================================================================================== +trim(trailing from 'test') +======================================================================================================================================================================================================== + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +trim(trailing:' ', "from":'test') + +------------------------------------------------------------------------------------------------------------------------ +trim(trailing:' ', "from":'test') + +-------------------------------------------------------------------------------- +trim(trailing:' ', "from":'test') + +---------------------------------------- +trim(trailing:' ', "from":'test') + +------------------------------ +trim(trailing:' ', + "from":'test') + +-------------------- +trim(trailing:' ', + "from":'test') + +---------- +trim(trailing:' ', + "from":'test') diff --git a/partiql-ast/tests/snapshots/pretty__pretty_kw_fn2.snap b/partiql-ast/tests/snapshots/pretty__pretty_kw_fn2.snap new file mode 100644 index 00000000..c4503800 --- /dev/null +++ b/partiql-ast/tests/snapshots/pretty__pretty_kw_fn2.snap @@ -0,0 +1,31 @@ +--- +source: partiql-ast/tests/pretty.rs +expression: doc +--- +======================================================================================================================================================================================================== +POSITION('abc' IN 'abcdefg') +======================================================================================================================================================================================================== + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +POSITION('abc', "IN":'abcdefg') + +------------------------------------------------------------------------------------------------------------------------ +POSITION('abc', "IN":'abcdefg') + +-------------------------------------------------------------------------------- +POSITION('abc', "IN":'abcdefg') + +---------------------------------------- +POSITION('abc', "IN":'abcdefg') + +------------------------------ +POSITION('abc', + "IN":'abcdefg') + +-------------------- +POSITION('abc', + "IN":'abcdefg') + +---------- +POSITION('abc', + "IN":'abcdefg') diff --git a/partiql-ast/tests/snapshots/pretty__pretty_kw_fn3.snap b/partiql-ast/tests/snapshots/pretty__pretty_kw_fn3.snap new file mode 100644 index 00000000..4ee2c4b3 --- /dev/null +++ b/partiql-ast/tests/snapshots/pretty__pretty_kw_fn3.snap @@ -0,0 +1,30 @@ +--- +source: partiql-ast/tests/pretty.rs +expression: doc +--- +======================================================================================================================================================================================================== +substring('test', 100, 50) +======================================================================================================================================================================================================== + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +substring('test', 100, 50) + +------------------------------------------------------------------------------------------------------------------------ +substring('test', 100, 50) + +-------------------------------------------------------------------------------- +substring('test', 100, 50) + +---------------------------------------- +substring('test', 100, 50) + +------------------------------ +substring('test', 100, 50) + +-------------------- +substring('test', + 100, 50) + +---------- +substring('test', + 100, 50) diff --git a/partiql-ast/tests/snapshots/pretty__pretty_kw_fn4.snap b/partiql-ast/tests/snapshots/pretty__pretty_kw_fn4.snap new file mode 100644 index 00000000..02b57c82 --- /dev/null +++ b/partiql-ast/tests/snapshots/pretty__pretty_kw_fn4.snap @@ -0,0 +1,30 @@ +--- +source: partiql-ast/tests/pretty.rs +expression: doc +--- +======================================================================================================================================================================================================== +substring('test', 100) +======================================================================================================================================================================================================== + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +substring('test', 100) + +------------------------------------------------------------------------------------------------------------------------ +substring('test', 100) + +-------------------------------------------------------------------------------- +substring('test', 100) + +---------------------------------------- +substring('test', 100) + +------------------------------ +substring('test', 100) + +-------------------- +substring('test', + 100) + +---------- +substring('test', + 100) diff --git a/partiql-ast/tests/snapshots/pretty__pretty_pivot.snap b/partiql-ast/tests/snapshots/pretty__pretty_pivot.snap new file mode 100644 index 00000000..3588dde7 --- /dev/null +++ b/partiql-ast/tests/snapshots/pretty__pretty_pivot.snap @@ -0,0 +1,80 @@ +--- +source: partiql-ast/tests/pretty.rs +expression: doc +--- +======================================================================================================================================================================================================== + + PIVOT foo.a AT foo.b + FROM <<{'a': 1, 'b':'I'}, {'a': 2, 'b':'II'}, {'a': 3, 'b':'III'}>> AS foo + ORDER BY a + LIMIT 1 OFFSET 1 + +======================================================================================================================================================================================================== + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +PIVOT foo.b AT foo.a FROM << { 'a': 1, 'b': 'I' }, { 'a': 2, 'b': 'II' }, { 'a': 3, 'b': 'III' } >> AS foo ORDER BY a LIMIT 1 OFFSET 1 + +------------------------------------------------------------------------------------------------------------------------ +PIVOT foo.b AT foo.a FROM << { 'a': 1, 'b': 'I' }, { 'a': 2, 'b': 'II' }, { 'a': 3, 'b': 'III' } >> AS foo ORDER BY a +LIMIT 1 OFFSET 1 + +-------------------------------------------------------------------------------- +PIVOT foo.b AT foo.a FROM << + { 'a': 1, 'b': 'I' }, + { 'a': 2, 'b': 'II' }, + { 'a': 3, 'b': 'III' } + >> AS foo ORDER BY a LIMIT 1 OFFSET 1 + +---------------------------------------- +PIVOT foo.b AT foo.a FROM << + { 'a': 1, 'b': 'I' }, + { 'a': 2, 'b': 'II' }, + { 'a': 3, 'b': 'III' } + >> AS foo ORDER BY a LIMIT 1 OFFSET 1 + +------------------------------ +PIVOT foo.b AT foo.a FROM << + { 'a': 1, 'b': 'I' }, + { 'a': 2, 'b': 'II' }, + { 'a': 3, 'b': 'III' } + >> AS foo ORDER BY a LIMIT 1 +OFFSET 1 + +-------------------- +PIVOT foo.b AT foo.a +FROM << + { + 'a': 1, + 'b': 'I' + }, + { + 'a': 2, + 'b': 'II' + }, + { + 'a': 3, + 'b': 'III' + } + >> AS foo +ORDER BY a LIMIT 1 +OFFSET 1 + +---------- +PIVOT foo.b AT foo.a +FROM << + { + 'a': 1, + 'b': 'I' + }, + { + 'a': 2, + 'b': 'II' + }, + { + 'a': 3, + 'b': 'III' + } + >> AS foo +ORDER BY a +LIMIT 1 +OFFSET 1 diff --git a/partiql-ast/tests/snapshots/pretty__pretty_select_value_tuple_ctor.snap b/partiql-ast/tests/snapshots/pretty__pretty_select_value_tuple_ctor.snap new file mode 100644 index 00000000..3a00243a --- /dev/null +++ b/partiql-ast/tests/snapshots/pretty__pretty_select_value_tuple_ctor.snap @@ -0,0 +1,61 @@ +--- +source: partiql-ast/tests/pretty.rs +expression: doc +--- +======================================================================================================================================================================================================== +SELECT VALUE {'a':v.a, 'b':v.b} FROM [{'a':1, 'b':1}, {'a':2, 'b':2}] AS v +======================================================================================================================================================================================================== + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +SELECT VALUE { 'a': v.a, 'b': v.b } FROM [ { 'a': 1, 'b': 1 }, { 'a': 2, 'b': 2 } ] AS v + +------------------------------------------------------------------------------------------------------------------------ +SELECT VALUE { 'a': v.a, 'b': v.b } FROM [ { 'a': 1, 'b': 1 }, { 'a': 2, 'b': 2 } ] AS v + +-------------------------------------------------------------------------------- +SELECT VALUE { 'a': v.a, 'b': v.b } FROM [ + { 'a': 1, 'b': 1 }, + { 'a': 2, 'b': 2 } + ] AS v + +---------------------------------------- +SELECT VALUE { 'a': v.a, 'b': v.b } +FROM [ + { 'a': 1, 'b': 1 }, + { 'a': 2, 'b': 2 } + ] AS v + +------------------------------ +SELECT VALUE { + 'a': v.a, + 'b': v.b + } FROM [ + { 'a': 1, 'b': 1 }, + { 'a': 2, 'b': 2 } + ] AS v + +-------------------- +SELECT VALUE { + 'a': v.a, + 'b': v.b + } FROM [ + { 'a': 1, 'b': 1 + }, + { 'a': 2, 'b': 2 + } + ] AS v + +---------- +SELECT VALUE { + 'a': v.a, + 'b': v.b + } FROM [ + { + 'a': 1, + 'b': 1 + }, + { + 'a': 2, + 'b': 2 + } + ] AS v diff --git a/partiql-ast/tests/snapshots/pretty__pretty_setop.snap b/partiql-ast/tests/snapshots/pretty__pretty_setop.snap new file mode 100644 index 00000000..674006cc --- /dev/null +++ b/partiql-ast/tests/snapshots/pretty__pretty_setop.snap @@ -0,0 +1,73 @@ +--- +source: partiql-ast/tests/pretty.rs +expression: doc +--- +======================================================================================================================================================================================================== +(SELECT a1 FROM b1 ORDER BY c1 LIMIT d1 OFFSET e1) + UNION + (SELECT a2 FROM b2 ORDER BY c2 LIMIT d2 OFFSET e2) + ORDER BY c3 LIMIT d3 OFFSET e3 +======================================================================================================================================================================================================== + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +( SELECT a1 FROM b1 ORDER BY c1 LIMIT d1 OFFSET e1 ) +UNION +( SELECT a2 FROM b2 ORDER BY c2 LIMIT d2 OFFSET e2 ) ORDER BY c3 LIMIT d3 OFFSET e3 + +------------------------------------------------------------------------------------------------------------------------ +( SELECT a1 FROM b1 ORDER BY c1 LIMIT d1 OFFSET e1 ) +UNION +( SELECT a2 FROM b2 ORDER BY c2 LIMIT d2 OFFSET e2 ) ORDER BY c3 LIMIT d3 OFFSET e3 + +-------------------------------------------------------------------------------- +( SELECT a1 FROM b1 ORDER BY c1 LIMIT d1 OFFSET e1 ) +UNION +( SELECT a2 FROM b2 ORDER BY c2 LIMIT d2 OFFSET e2 ) ORDER BY c3 LIMIT d3 +OFFSET e3 + +---------------------------------------- +( SELECT a1 FROM b1 ORDER BY c1 LIMIT d1 + OFFSET e1 ) +UNION +( SELECT a2 FROM b2 ORDER BY c2 LIMIT d2 + OFFSET e2 ) ORDER BY c3 LIMIT d3 +OFFSET e3 + +------------------------------ +( SELECT a1 FROM b1 + ORDER BY c1 LIMIT d1 + OFFSET e1 ) +UNION +( SELECT a2 FROM b2 + ORDER BY c2 LIMIT d2 + OFFSET e2 ) ORDER BY c3 +LIMIT d3 OFFSET e3 + +-------------------- +( SELECT a1 FROM b1 + ORDER BY c1 + LIMIT d1 + OFFSET e1 ) +UNION +( SELECT a2 FROM b2 + ORDER BY c2 + LIMIT d2 + OFFSET e2 ) +ORDER BY c3 LIMIT d3 +OFFSET e3 + +---------- +( SELECT a1 + FROM b1 + ORDER BY c1 + LIMIT d1 + OFFSET e1 ) +UNION +( SELECT a2 + FROM b2 + ORDER BY c2 + LIMIT d2 + OFFSET e2 ) +ORDER BY c3 +LIMIT d3 +OFFSET e3 diff --git a/partiql-ast/tests/snapshots/pretty__pretty_typed_lits1.snap b/partiql-ast/tests/snapshots/pretty__pretty_typed_lits1.snap new file mode 100644 index 00000000..372ffa4a --- /dev/null +++ b/partiql-ast/tests/snapshots/pretty__pretty_typed_lits1.snap @@ -0,0 +1,28 @@ +--- +source: partiql-ast/tests/pretty.rs +expression: doc +--- +======================================================================================================================================================================================================== +TIME WITH TIME ZONE '23:59:59.1234567890+18:00' +======================================================================================================================================================================================================== + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +TIME WITH TIME ZONE '23:59:59.1234567890+18:00' + +------------------------------------------------------------------------------------------------------------------------ +TIME WITH TIME ZONE '23:59:59.1234567890+18:00' + +-------------------------------------------------------------------------------- +TIME WITH TIME ZONE '23:59:59.1234567890+18:00' + +---------------------------------------- +TIME WITH TIME ZONE '23:59:59.1234567890+18:00' + +------------------------------ +TIME WITH TIME ZONE '23:59:59.1234567890+18:00' + +-------------------- +TIME WITH TIME ZONE '23:59:59.1234567890+18:00' + +---------- +TIME WITH TIME ZONE '23:59:59.1234567890+18:00' diff --git a/partiql-ast/tests/snapshots/pretty__pretty_typed_lits2.snap b/partiql-ast/tests/snapshots/pretty__pretty_typed_lits2.snap new file mode 100644 index 00000000..ba2f4302 --- /dev/null +++ b/partiql-ast/tests/snapshots/pretty__pretty_typed_lits2.snap @@ -0,0 +1,28 @@ +--- +source: partiql-ast/tests/pretty.rs +expression: doc +--- +======================================================================================================================================================================================================== +TIME (3) WITH TIME ZONE '12:59:31' +======================================================================================================================================================================================================== + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +TIME( 3 ) WITH TIME ZONE '12:59:31' + +------------------------------------------------------------------------------------------------------------------------ +TIME( 3 ) WITH TIME ZONE '12:59:31' + +-------------------------------------------------------------------------------- +TIME( 3 ) WITH TIME ZONE '12:59:31' + +---------------------------------------- +TIME( 3 ) WITH TIME ZONE '12:59:31' + +------------------------------ +TIME( 3 ) WITH TIME ZONE '12:59:31' + +-------------------- +TIME( 3 ) WITH TIME ZONE '12:59:31' + +---------- +TIME( 3 ) WITH TIME ZONE '12:59:31' diff --git a/partiql-ast/tests/snapshots/pretty__select value unpivot.snap b/partiql-ast/tests/snapshots/pretty__select value unpivot.snap new file mode 100644 index 00000000..0c17dff6 --- /dev/null +++ b/partiql-ast/tests/snapshots/pretty__select value unpivot.snap @@ -0,0 +1,35 @@ +--- +source: partiql-ast/tests/pretty.rs +expression: doc +--- +======================================================================================================================================================================================================== +SELECT VALUE foo FROM (SELECT VALUE v FROM UNPIVOT e AS v) AS foo +======================================================================================================================================================================================================== + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +SELECT VALUE foo FROM (SELECT VALUE v FROM UNPIVOT e AS v) AS foo + +------------------------------------------------------------------------------------------------------------------------ +SELECT VALUE foo FROM (SELECT VALUE v FROM UNPIVOT e AS v) AS foo + +-------------------------------------------------------------------------------- +SELECT VALUE foo FROM (SELECT VALUE v FROM UNPIVOT e AS v) AS foo + +---------------------------------------- +SELECT VALUE foo FROM (SELECT VALUE v + FROM UNPIVOT e AS v) AS foo + +------------------------------ +SELECT VALUE foo +FROM (SELECT VALUE v + FROM UNPIVOT e AS v) AS foo + +-------------------- +SELECT VALUE foo +FROM (SELECT VALUE v + FROM UNPIVOT e AS v) AS foo + +---------- +SELECT VALUE foo +FROM (SELECT VALUE v + FROM UNPIVOT e AS v) AS foo