lava-oushudb-dt-sql-parser/test/parser/spark/syntax/fixtures/selectCET.sql
Frank d0ad381833
test: spark sql query syntax unit test (#173)
* test: add spark query unit test and check grammar

* test: add select explain、lateralSubQuery、transform unit test

* chore: fileName exchange

---------

Co-authored-by: dilu <dilu@dtstack.com>
2023-10-10 16:25:43 +08:00

30 lines
920 B
SQL

-- WITH common_table_expression [ , ... ]
-- expression_name [ ( column_name [ , ... ] ) ] [ AS ] ( query )
-- CTE with multiple column aliases
WITH t(x, y) AS (SELECT 1, 2)
SELECT * FROM t WHERE x = 1 AND y = 2;
-- CTE in CTE definition
WITH t AS (WITH t2 AS (SELECT 1) SELECT * FROM t2) SELECT * FROM t;
-- CTE in subquery expression
SELECT (WITH t AS (SELECT 1) SELECT * FROM t);
-- CTE in CREATE VIEW statement
CREATE VIEW v AS WITH t(a, b, c, d) AS (SELECT 1, 2, 3, 4) SELECT * FROM t;
SELECT * FROM v;
-- If name conflict is detected in nested CTE, then AnalysisException is thrown by default.
-- SET spark.sql.legacy.ctePrecedencePolicy = CORRECTED (which is recommended),
-- inner CTE definitions take precedence over outer definitions.
SET spark.sql.legacy.ctePrecedencePolicy = CORRECTED;
WITH
t AS (SELECT 1),
t2 AS (
WITH t AS (SELECT 2)
SELECT * FROM t
)
SELECT * FROM t2;