lava-oushudb-dt-sql-parser/test/parser/trinosql/syntax/fixtures/select.sql
mumiao 9c82a5d248
feat: support trino(presto) sql language (#105)
* feat(trino): intergrate prestoGrammar to dt-sql-parser

* feat(trino): add trinoSQl test framework

* feat(trino): intergrate test files for trinoSQL

* test(trino): support alterStatement test

* test(trino): support alter table set authorization statement

* feat(trino): complete trinosql alter unit tests

* test(trino): complete dropStatement unit cases for trinosql

* test(trino): complete create statement unit cases for trinoSQL

* test(trino): complete insertStatement unit cases for trinoSQl

* test(trino): dropStatement test files changed to short line split

* test(trino): complete selectStatement unit cases and grammar check

* test(trino): complete commentStatement unit case for trinoSQL

* test(trino): complete analyze commit and call clause unit case

* test(trino): complete delete deny and describe statement unit case

* test(trino): complete explain execute and grant statement unit case

* feat(trino): improve GRANT Role grammar

* test(trino): complete show statement unit case

* test(trino): complete truncateTable startTransaction update and values  statement unit case

* test(trino): improve update statement test cases

* test(trino): complete revoke revoke roles  and rollback statement unit case

* test(trino): add set statement test case

* feat: generator new trino parser and lexer file

* feat(trino): improve alter statement grammar

* test(trino): complete alter statement unit cases

* feat(trino): support case-insensitive lexers

* fix(trino): rm unless gen files

* test(trino): complete merge and reset session statement unit cases

* test(trino): complete merge anduse statement unit cases

* test(trino): complete prepare and refresh materialized view statement unit cases

* test(trino): improve statement unit cases

* test(trino): complete match recognize statement unit cases

* test(trino): complete window with row pattern recognition statement unit cases
2023-05-24 15:07:02 +08:00

118 lines
3.7 KiB
SQL

-- DOUBLE IN Query
SELECT 123.456E7 FROM DUAL;
-- GROUP BY
SELECT * FROM table1 GROUP BY a;
SELECT * FROM table1 GROUP BY a, b;
SELECT * FROM table1 GROUP BY ();
-- GROUP BY GROUPING SETS
SELECT * FROM table1 GROUP BY GROUPING SETS (a);
SELECT a, b, GROUPING(a, b) FROM table1 GROUP BY GROUPING SETS ((a), (b));
-- GROUP BY ROLLUP
SELECT * FROM table1 GROUP BY ALL GROUPING SETS ((a, b), (a), ()), CUBE (c), ROLLUP (d);
SELECT * FROM table1 GROUP BY DISTINCT GROUPING SETS ((a, b), (a), ()), CUBE (c), ROLLUP (d);
-- GROUP BY CUBE
SELECT origin_state, destination_state, sum(package_weight)
FROM shipping
GROUP BY CUBE (origin_state, destination_state);
-- GROUP BY Combining multiple grouping expressions
SELECT origin_state, destination_state, origin_zip, sum(package_weight)
FROM shipping
GROUP BY
GROUPING SETS ((origin_state, destination_state)),
ROLLUP (origin_zip);
SELECT origin_state, destination_state, origin_zip, sum(package_weight)
FROM shipping
GROUP BY GROUPING SETS (
(origin_state, destination_state, origin_zip),
(origin_state, destination_state)
);
SELECT origin_state, destination_state, origin_zip, sum(package_weight)
FROM shipping
GROUP BY
GROUPING SETS ((origin_state, destination_state)),
GROUPING SETS ((origin_zip), ());
-- GROUP BY ALL and DISTINCT quantifiers
SELECT origin_state, destination_state, origin_zip, sum(package_weight)
FROM shipping
GROUP BY ALL
CUBE (origin_state, destination_state),
ROLLUP (origin_state, origin_zip);
SELECT origin_state, destination_state, origin_zip, sum(package_weight)
FROM shipping
GROUP BY GROUPING SETS (
(origin_state, destination_state, origin_zip),
(origin_state, origin_zip),
(origin_state, destination_state, origin_zip),
(origin_state, origin_zip),
(origin_state, destination_state),
(origin_state),
(origin_state, destination_state),
(origin_state),
(origin_state, destination_state),
(origin_state),
(destination_state),
()
);
SELECT origin_state, destination_state, origin_zip, sum(package_weight)
FROM shipping
GROUP BY DISTINCT
CUBE (origin_state, destination_state),
ROLLUP (origin_state, origin_zip);
SELECT origin_state, destination_state, origin_zip, sum(package_weight)
FROM shipping
GROUP BY GROUPING SETS (
(origin_state, destination_state, origin_zip),
(origin_state, origin_zip),
(origin_state, destination_state),
(origin_state),
(destination_state),
()
);
-- GROUP BY GROUPING operation
SELECT origin_state, origin_zip, destination_state, sum(package_weight),
grouping(origin_state, origin_zip, destination_state)
FROM shipping
GROUP BY GROUPING SETS (
(origin_state),
(origin_state, origin_zip),
(destination_state)
);
-- ORDER BY
SELECT * FROM table1 ORDER BY a;
-- Select expressions
SELECT (CAST(ROW(1, true) AS ROW(field1 bigint, field2 boolean))).* AS (alias1, alias2);
SELECT (CAST(ROW(1, true) AS ROW(field1 bigint, field2 boolean))).*;
SELECT (ROW(1, true)).*;
-- LIMIT
SELECT * FROM table1 LIMIT 2;
SELECT * FROM table1 LIMIT ALL;
SELECT * FROM (VALUES (1, '1'), (2, '2')) LIMIT ALL;
-- HAVING
SELECT count(*), mktsegment, nationkey,
CAST(sum(acctbal) AS bigint) AS totalbal
FROM customer
GROUP BY mktsegment, nationkey
HAVING sum(acctbal) > 5700000
ORDER BY totalbal DESC;
-- WINDOW
SELECT orderkey, clerk, totalprice,
rank() OVER w AS rnk
FROM orders
WINDOW w AS (PARTITION BY clerk ORDER BY totalprice DESC)
ORDER BY count() OVER w, clerk, rnk
-- AGGREGATION FILTER/ ORDER BY
SELECT SUM(x) FILTER (WHERE x > 4);
SELECT array_agg(x ORDER BY t.y) FROM t;
-- INTERSECT
SELECT 123 INTERSECT DISTINCT SELECT 123 INTERSECT ALL SELECT 123;
-- substring_built_in_function
SELECT substring('string' FROM 2);
SELECT substring('string' FROM 2 FOR 3);