summaryrefslogtreecommitdiffstats
path: root/tests/fixtures/optimizer
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-10-22 17:00:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-10-22 17:00:19 +0000
commit357f4c323239b9ba9b604c444fe3c2e1991e46ec (patch)
tree739aa7ddca96a60c9148554b35bb1b231cb9888f /tests/fixtures/optimizer
parentReleasing debian version 25.24.5-1. (diff)
downloadsqlglot-357f4c323239b9ba9b604c444fe3c2e1991e46ec.tar.xz
sqlglot-357f4c323239b9ba9b604c444fe3c2e1991e46ec.zip
Merging upstream version 25.26.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/fixtures/optimizer')
-rw-r--r--tests/fixtures/optimizer/annotate_functions.sql122
-rw-r--r--tests/fixtures/optimizer/merge_subqueries.sql18
-rw-r--r--tests/fixtures/optimizer/qualify_columns.sql11
-rw-r--r--tests/fixtures/optimizer/qualify_tables.sql3
-rw-r--r--tests/fixtures/optimizer/simplify.sql3
5 files changed, 156 insertions, 1 deletions
diff --git a/tests/fixtures/optimizer/annotate_functions.sql b/tests/fixtures/optimizer/annotate_functions.sql
index 8aa77d4..1f59a5a 100644
--- a/tests/fixtures/optimizer/annotate_functions.sql
+++ b/tests/fixtures/optimizer/annotate_functions.sql
@@ -186,4 +186,124 @@ DOUBLE;
# dialect: bigquery
EXP(tbl.bignum_col);
-BIGDECIMAL; \ No newline at end of file
+BIGDECIMAL;
+
+# dialect: bigquery
+CONCAT(tbl.str_col, tbl.str_col);
+STRING;
+
+# dialect: bigquery
+CONCAT(tbl.bin_col, tbl.bin_col);
+BINARY;
+
+# dialect: bigquery
+LEFT(tbl.str_col, 1);
+STRING;
+
+# dialect: bigquery
+LEFT(tbl.bin_col, 1);
+BINARY;
+
+# dialect: bigquery
+RIGHT(tbl.str_col, 1);
+STRING;
+
+# dialect: bigquery
+RIGHT(tbl.bin_col, 1);
+BINARY;
+
+# dialect: bigquery
+LOWER(tbl.str_col);
+STRING;
+
+# dialect: bigquery
+LOWER(tbl.bin_col);
+BINARY;
+
+# dialect: bigquery
+UPPER(tbl.str_col);
+STRING;
+
+# dialect: bigquery
+UPPER(tbl.bin_col);
+BINARY;
+
+# dialect: bigquery
+LPAD(tbl.str_col, 1, tbl.str_col);
+STRING;
+
+# dialect: bigquery
+LPAD(tbl.bin_col, 1, tbl.bin_col);
+BINARY;
+
+# dialect: bigquery
+RPAD(tbl.str_col, 1, tbl.str_col);
+STRING;
+
+# dialect: bigquery
+RPAD(tbl.bin_col, 1, tbl.bin_col);
+BINARY;
+
+# dialect: bigquery
+LTRIM(tbl.str_col);
+STRING;
+
+# dialect: bigquery
+LTRIM(tbl.bin_col, tbl.bin_col);
+BINARY;
+
+# dialect: bigquery
+RTRIM(tbl.str_col);
+STRING;
+
+# dialect: bigquery
+RTRIM(tbl.bin_col, tbl.bin_col);
+BINARY;
+
+# dialect: bigquery
+TRIM(tbl.str_col);
+STRING;
+
+# dialect: bigquery
+TRIM(tbl.bin_col, tbl.bin_col);
+BINARY;
+
+# dialect: bigquery
+REGEXP_EXTRACT(tbl.str_col, pattern);
+STRING;
+
+# dialect: bigquery
+REGEXP_EXTRACT(tbl.bin_col, pattern);
+BINARY;
+
+# dialect: bigquery
+REGEXP_REPLACE(tbl.str_col, pattern, replacement);
+STRING;
+
+# dialect: bigquery
+REGEXP_REPLACE(tbl.bin_col, pattern, replacement);
+BINARY;
+
+# dialect: bigquery
+REPEAT(tbl.str_col, 1);
+STRING;
+
+# dialect: bigquery
+REPEAT(tbl.bin_col, 1);
+BINARY;
+
+# dialect: bigquery
+SUBSTRING(tbl.str_col, 1);
+STRING;
+
+# dialect: bigquery
+SUBSTRING(tbl.bin_col, 1);
+BINARY;
+
+# dialect: bigquery
+SPLIT(tbl.str_col, delim);
+ARRAY<STRING>;
+
+# dialect: bigquery
+SPLIT(tbl.bin_col, delim);
+ARRAY<BINARY>;
diff --git a/tests/fixtures/optimizer/merge_subqueries.sql b/tests/fixtures/optimizer/merge_subqueries.sql
index ce5a435..e39e7d1 100644
--- a/tests/fixtures/optimizer/merge_subqueries.sql
+++ b/tests/fixtures/optimizer/merge_subqueries.sql
@@ -446,3 +446,21 @@ SELECT
1 AS a;
WITH q AS (SELECT x.a AS a FROM x AS x ORDER BY x.a) SELECT q.a AS a FROM q AS q UNION ALL SELECT 1 AS a;
+# title: Consecutive inner - outer conflicting names
+WITH tbl AS (select 1 as id)
+SELECT
+ id
+FROM (
+ SELECT OTBL.id
+ FROM (
+ SELECT OTBL.id
+ FROM (
+ SELECT OTBL.id
+ FROM tbl AS OTBL
+ LEFT OUTER JOIN tbl AS ITBL ON OTBL.id = ITBL.id
+ ) AS OTBL
+ LEFT OUTER JOIN tbl AS ITBL ON OTBL.id = ITBL.id
+ ) AS OTBL
+ LEFT OUTER JOIN tbl AS ITBL ON OTBL.id = ITBL.id
+) AS ITBL;
+WITH tbl AS (SELECT 1 AS id) SELECT OTBL.id AS id FROM tbl AS OTBL LEFT OUTER JOIN tbl AS ITBL_2 ON OTBL.id = ITBL_2.id LEFT OUTER JOIN tbl AS ITBL_3 ON OTBL.id = ITBL_3.id LEFT OUTER JOIN tbl AS ITBL ON OTBL.id = ITBL.id;
diff --git a/tests/fixtures/optimizer/qualify_columns.sql b/tests/fixtures/optimizer/qualify_columns.sql
index 68c0caa..7c901ce 100644
--- a/tests/fixtures/optimizer/qualify_columns.sql
+++ b/tests/fixtures/optimizer/qualify_columns.sql
@@ -190,6 +190,17 @@ SELECT x._col_0 AS _col_0, x._col_1 AS _col_1 FROM (VALUES (1, 2)) AS x(_col_0,
SELECT SOME_UDF(data).* FROM t;
SELECT SOME_UDF(t.data).* FROM t AS t;
+# execute: false
+# allow_partial_qualification: true
+# validate_qualify_columns: false
+SELECT a + 1 AS i, missing_column FROM x;
+SELECT x.a + 1 AS i, missing_column AS missing_column FROM x AS x;
+
+# execute: false
+# dialect: clickhouse
+SELECT s, arr1, arr2 FROM arrays_test LEFT ARRAY JOIN arr1, arrays_test.arr2;
+SELECT arrays_test.s AS s, arrays_test.arr1 AS arr1, arrays_test.arr2 AS arr2 FROM arrays_test AS arrays_test LEFT ARRAY JOIN arrays_test.arr1, arrays_test.arr2;
+
--------------------------------------
-- Derived tables
--------------------------------------
diff --git a/tests/fixtures/optimizer/qualify_tables.sql b/tests/fixtures/optimizer/qualify_tables.sql
index 61d0b96..49e07fa 100644
--- a/tests/fixtures/optimizer/qualify_tables.sql
+++ b/tests/fixtures/optimizer/qualify_tables.sql
@@ -184,3 +184,6 @@ COPY INTO (SELECT * FROM c.db.x AS x) TO 'data' WITH (FORMAT 'CSV');
# title: tablesample
SELECT 1 FROM x TABLESAMPLE SYSTEM (10 PERCENT) CROSS JOIN y TABLESAMPLE SYSTEM (10 PERCENT);
SELECT 1 FROM c.db.x AS x TABLESAMPLE SYSTEM (10 PERCENT) CROSS JOIN c.db.y AS y TABLESAMPLE SYSTEM (10 PERCENT);
+
+WITH cte_tbl AS (SELECT 1 AS col2) UPDATE y SET col1 = (SELECT * FROM x) WHERE EXISTS(SELECT 1 FROM cte_tbl);
+WITH cte_tbl AS (SELECT 1 AS col2) UPDATE c.db.y SET col1 = (SELECT * FROM c.db.x AS x) WHERE EXISTS(SELECT 1 FROM cte_tbl AS cte_tbl);
diff --git a/tests/fixtures/optimizer/simplify.sql b/tests/fixtures/optimizer/simplify.sql
index fa2dc79..1842e55 100644
--- a/tests/fixtures/optimizer/simplify.sql
+++ b/tests/fixtures/optimizer/simplify.sql
@@ -140,6 +140,9 @@ TRUE;
COALESCE(x, y) <> ALL (SELECT z FROM w);
COALESCE(x, y) <> ALL (SELECT z FROM w);
+SELECT NOT (2 <> ALL (SELECT 2 UNION ALL SELECT 3));
+SELECT 2 = ANY(SELECT 2 UNION ALL SELECT 3);
+
--------------------------------------
-- Absorption
--------------------------------------