diff options
| author | vitya-smirnov <[email protected]> | 2025-10-14 09:30:10 +0300 |
|---|---|---|
| committer | vitya-smirnov <[email protected]> | 2025-10-14 09:48:40 +0300 |
| commit | e06bac75417cb26b5603d104e58a15aeda178d5e (patch) | |
| tree | 5a3cc5430cd0bc4fff262e5d37f41291914d6e70 /yql/essentials/tests/sql/sql2yql | |
| parent | 6afc58f5f8644b9e12b407cfa1341dacc1aaf5e2 (diff) | |
YQL-20436: Translate `SELECT .. FROM VALUES ..` to `YqlSelect`
Current `SQLv1` translation produces relatively low level `YQLs`
constructions that are hard to match during later optimizations, for
example, subqueries unnesting. Also it assumes that expressions are only
depend on corresponding source row, which is not true for correlated
subqueries. Both limitations blocks currelated subqueries implementation.
Although the problem exists for `SQLv1`, it is already solved for `PG`
syntax. There PostgreSQL-produced AST is converted to special `YQLs`
"bulk select" node called `PgSelect`. It is more declarative and
expanded later than translation. This fact helped to support correlated
subqueries, which with `PgSelect` are type-checkable and decorrelatable
(not generally, but heuristically).
This patch is the first step forward to "bulk select" translation
for `SQLv1`. As there are a lot of code already written for `PgSelect`
and `PG` and `SQLv1` relatively similar, I decided to rebrand `PgSelect`
into more general `SqlSelect` node. It seems that for some near future
goals `PgSelect` should be enough.
There was 2 problems solved:
1. `PgSelect` comes with `OrderedColumns` by default and its
implementation tightly coupled with it.
2. `PgSelect` does Pg type casts.
This patch contains following changes:
- Added pragma `YqlSelect = 'disable' | 'auto' | 'force'`
- Added `YqlSelect` (`PgSelect` alias) translation
- Changed `PgSelect` wrappers to support `YqlSelect`
- Changed `PgSelect` expanders to support `YqlSelect`
commit_hash:8a55d63e06c22592b2029dd260bbd259194e92dc
Diffstat (limited to 'yql/essentials/tests/sql/sql2yql')
8 files changed, 160 insertions, 0 deletions
diff --git a/yql/essentials/tests/sql/sql2yql/canondata/result.json b/yql/essentials/tests/sql/sql2yql/canondata/result.json index 4646fb26ee0..c3a4b4510ab 100644 --- a/yql/essentials/tests/sql/sql2yql/canondata/result.json +++ b/yql/essentials/tests/sql/sql2yql/canondata/result.json @@ -8154,6 +8154,55 @@ "uri": "https://{canondata_backend}/1942671/82ed7d067ef141d1fcef204dc3b89bf4e1c70c57/resource.tar.gz#test_sql2yql.test_select_op-select_op_precedence_named_node_/sql.yql" } ], + "test_sql2yql.test[select_yql-alias]": [ + { + "checksum": "33dc55c0790d7112a27e081a48a228ce", + "size": 1849, + "uri": "https://{canondata_backend}/1881367/bd3634d7029be128790526e9f6936e9d4e62611f/resource.tar.gz#test_sql2yql.test_select_yql-alias_/sql.yql" + } + ], + "test_sql2yql.test[select_yql-expr]": [ + { + "checksum": "c3970c80cdc82b4a685c8639427d3f0a", + "size": 751, + "uri": "https://{canondata_backend}/1881367/bd3634d7029be128790526e9f6936e9d4e62611f/resource.tar.gz#test_sql2yql.test_select_yql-expr_/sql.yql" + } + ], + "test_sql2yql.test[select_yql-from_anon_values]": [ + { + "checksum": "e5e204d08da35e20051a79a5476d7dcb", + "size": 763, + "uri": "https://{canondata_backend}/1881367/bd3634d7029be128790526e9f6936e9d4e62611f/resource.tar.gz#test_sql2yql.test_select_yql-from_anon_values_/sql.yql" + } + ], + "test_sql2yql.test[select_yql-from_values]": [ + { + "checksum": "0c824a5c49577fd20991e97f58b8f20f", + "size": 893, + "uri": "https://{canondata_backend}/1946324/49df8639d304dfe2c977bad20e3580e113ec0014/resource.tar.gz#test_sql2yql.test_select_yql-from_values_/sql.yql" + } + ], + "test_sql2yql.test[select_yql-from_values_ordered_columns]": [ + { + "checksum": "5126b24f43de5eb7717bef58a6a7d4e0", + "size": 965, + "uri": "https://{canondata_backend}/1946324/49df8639d304dfe2c977bad20e3580e113ec0014/resource.tar.gz#test_sql2yql.test_select_yql-from_values_ordered_columns_/sql.yql" + } + ], + "test_sql2yql.test[select_yql-minimal]": [ + { + "checksum": "45a1f9a2ca783e3861f51241f57039b0", + "size": 588, + "uri": "https://{canondata_backend}/1881367/bd3634d7029be128790526e9f6936e9d4e62611f/resource.tar.gz#test_sql2yql.test_select_yql-minimal_/sql.yql" + } + ], + "test_sql2yql.test[select_yql-minimal_ordered_columns]": [ + { + "checksum": "3f8a6c6437c3acb562c0a0adabc9aa0d", + "size": 660, + "uri": "https://{canondata_backend}/1130705/d43abb2de178f94a1126902afd1e77e6bd8e8734/resource.tar.gz#test_sql2yql.test_select_yql-minimal_ordered_columns_/sql.yql" + } + ], "test_sql2yql.test[seq_mode-shared_named_expr]": [ { "checksum": "1bc276a9cb08e31273e24da9ad90582d", @@ -13154,6 +13203,41 @@ "uri": "file://test_sql_format.test_select_op-select_op_precedence_named_node_/formatted.sql" } ], + "test_sql_format.test[select_yql-alias]": [ + { + "uri": "file://test_sql_format.test_select_yql-alias_/formatted.sql" + } + ], + "test_sql_format.test[select_yql-expr]": [ + { + "uri": "file://test_sql_format.test_select_yql-expr_/formatted.sql" + } + ], + "test_sql_format.test[select_yql-from_anon_values]": [ + { + "uri": "file://test_sql_format.test_select_yql-from_anon_values_/formatted.sql" + } + ], + "test_sql_format.test[select_yql-from_values]": [ + { + "uri": "file://test_sql_format.test_select_yql-from_values_/formatted.sql" + } + ], + "test_sql_format.test[select_yql-from_values_ordered_columns]": [ + { + "uri": "file://test_sql_format.test_select_yql-from_values_ordered_columns_/formatted.sql" + } + ], + "test_sql_format.test[select_yql-minimal]": [ + { + "uri": "file://test_sql_format.test_select_yql-minimal_/formatted.sql" + } + ], + "test_sql_format.test[select_yql-minimal_ordered_columns]": [ + { + "uri": "file://test_sql_format.test_select_yql-minimal_ordered_columns_/formatted.sql" + } + ], "test_sql_format.test[seq_mode-shared_named_expr]": [ { "uri": "file://test_sql_format.test_seq_mode-shared_named_expr_/formatted.sql" diff --git a/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-alias_/formatted.sql b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-alias_/formatted.sql new file mode 100644 index 00000000000..3959ed02ac0 --- /dev/null +++ b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-alias_/formatted.sql @@ -0,0 +1,21 @@ +PRAGMA YqlSelect = 'force'; + +SELECT + 1, + 2 +; + +SELECT + 1 AS x, + 2 +; + +SELECT + 1, + 2 AS y +; + +SELECT + 1 AS x, + 2 AS y +; diff --git a/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-expr_/formatted.sql b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-expr_/formatted.sql new file mode 100644 index 00000000000..f1c2ef44266 --- /dev/null +++ b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-expr_/formatted.sql @@ -0,0 +1,7 @@ +PRAGMA YqlSelect = 'force'; + +SELECT + 1 AS c1, + 2 * 2 - 2 AS c2, + Length('333') AS c3 +; diff --git a/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-from_anon_values_/formatted.sql b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-from_anon_values_/formatted.sql new file mode 100644 index 00000000000..cd0cfa7ecda --- /dev/null +++ b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-from_anon_values_/formatted.sql @@ -0,0 +1,8 @@ +PRAGMA YqlSelect = 'force'; + +SELECT + 1 +FROM ( + VALUES + (1) +); diff --git a/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-from_values_/formatted.sql b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-from_values_/formatted.sql new file mode 100644 index 00000000000..53f93c26d72 --- /dev/null +++ b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-from_values_/formatted.sql @@ -0,0 +1,14 @@ +PRAGMA YqlSelect = 'force'; + +SELECT + a, + b +FROM ( + VALUES + (1, '1'), + (2, '2'), + (3, '3') +) AS x ( + a, + b +); diff --git a/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-from_values_ordered_columns_/formatted.sql b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-from_values_ordered_columns_/formatted.sql new file mode 100644 index 00000000000..bd2f2188698 --- /dev/null +++ b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-from_values_ordered_columns_/formatted.sql @@ -0,0 +1,15 @@ +PRAGMA YqlSelect = 'force'; +PRAGMA OrderedColumns; + +SELECT + a, + b +FROM ( + VALUES + (1, '1'), + (2, '2'), + (3, '3') +) AS x ( + a, + b +); diff --git a/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-minimal_/formatted.sql b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-minimal_/formatted.sql new file mode 100644 index 00000000000..883e0d271da --- /dev/null +++ b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-minimal_/formatted.sql @@ -0,0 +1,5 @@ +PRAGMA YqlSelect = 'force'; + +SELECT + 1 +; diff --git a/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-minimal_ordered_columns_/formatted.sql b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-minimal_ordered_columns_/formatted.sql new file mode 100644 index 00000000000..b6e3e90e8e1 --- /dev/null +++ b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_select_yql-minimal_ordered_columns_/formatted.sql @@ -0,0 +1,6 @@ +PRAGMA YqlSelect = 'force'; +PRAGMA OrderedColumns; + +SELECT + 1 +; |
