ydb-sqlglot-plugin 0.2.3__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ydb_sqlglot_plugin-0.2.3 → ydb_sqlglot_plugin-0.2.4}/PKG-INFO +29 -3
- {ydb_sqlglot_plugin-0.2.3 → ydb_sqlglot_plugin-0.2.4}/README.md +28 -2
- {ydb_sqlglot_plugin-0.2.3 → ydb_sqlglot_plugin-0.2.4}/pyproject.toml +1 -1
- ydb_sqlglot_plugin-0.2.4/ydb_sqlglot/version.py +1 -0
- {ydb_sqlglot_plugin-0.2.3 → ydb_sqlglot_plugin-0.2.4}/ydb_sqlglot/ydb.py +809 -37
- {ydb_sqlglot_plugin-0.2.3 → ydb_sqlglot_plugin-0.2.4}/ydb_sqlglot_plugin.egg-info/PKG-INFO +29 -3
- ydb_sqlglot_plugin-0.2.3/ydb_sqlglot/version.py +0 -1
- {ydb_sqlglot_plugin-0.2.3 → ydb_sqlglot_plugin-0.2.4}/LICENSE +0 -0
- {ydb_sqlglot_plugin-0.2.3 → ydb_sqlglot_plugin-0.2.4}/setup.cfg +0 -0
- {ydb_sqlglot_plugin-0.2.3 → ydb_sqlglot_plugin-0.2.4}/ydb_sqlglot/__init__.py +0 -0
- {ydb_sqlglot_plugin-0.2.3 → ydb_sqlglot_plugin-0.2.4}/ydb_sqlglot_plugin.egg-info/SOURCES.txt +0 -0
- {ydb_sqlglot_plugin-0.2.3 → ydb_sqlglot_plugin-0.2.4}/ydb_sqlglot_plugin.egg-info/dependency_links.txt +0 -0
- {ydb_sqlglot_plugin-0.2.3 → ydb_sqlglot_plugin-0.2.4}/ydb_sqlglot_plugin.egg-info/entry_points.txt +0 -0
- {ydb_sqlglot_plugin-0.2.3 → ydb_sqlglot_plugin-0.2.4}/ydb_sqlglot_plugin.egg-info/requires.txt +0 -0
- {ydb_sqlglot_plugin-0.2.3 → ydb_sqlglot_plugin-0.2.4}/ydb_sqlglot_plugin.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ydb-sqlglot-plugin
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: YDB dialect plugin for sqlglot
|
|
5
5
|
Author: YDB Team
|
|
6
6
|
License: Apache-2.0
|
|
@@ -140,18 +140,27 @@ The plugin parses YDB/YQL back into sqlglot's AST, enabling round-trips, YDB-to-
|
|
|
140
140
|
| `$variable` references | `SELECT * FROM $t AS t` |
|
|
141
141
|
| `Module::Function()` | `DateTime::GetYear(ts)` |
|
|
142
142
|
| `DECLARE $p AS Type` | `DECLARE $p AS Int32` |
|
|
143
|
-
| `FLATTEN [LIST\|DICT] BY
|
|
143
|
+
| `FLATTEN [LIST\|DICT\|OPTIONAL] BY ...` / `FLATTEN COLUMNS` | `FROM t FLATTEN LIST BY col AS item`, `FROM t FLATTEN BY (a, b)`, `FROM t FLATTEN COLUMNS` |
|
|
144
144
|
| `Optional<T>` / `T?` | `CAST(x AS Optional<Utf8>)` |
|
|
145
145
|
| Container types | `CAST(x AS List<Int32>)`, `Dict<Utf8, Int64>`, `Set<Utf8>`, `Tuple<Int32, Utf8>` |
|
|
146
146
|
| `ASSUME ORDER BY` | `SELECT * FROM t ASSUME ORDER BY id` |
|
|
147
|
-
| `GROUP BY expr AS alias` | `SELECT v, COUNT(*) FROM t GROUP BY v AS v` |
|
|
147
|
+
| `GROUP BY expr AS alias` / `GROUP COMPACT BY` | `SELECT v, COUNT(*) FROM t GROUP BY v AS v` |
|
|
148
|
+
| `LEFT ONLY JOIN` | `SELECT * FROM a LEFT ONLY JOIN b USING (id)` |
|
|
149
|
+
| `* WITHOUT (...)` projections | `SELECT b.* WITHOUT (b.id) FROM t AS b` |
|
|
148
150
|
| Named expressions | `$t = (SELECT 1 AS x)` |
|
|
149
151
|
| Lambda expressions | `($x, $y?) -> ($x + COALESCE($y, 0))`, `($y) -> { $p = "x"; RETURN $p \|\| $y }` |
|
|
152
|
+
| YQL struct literals | `AsList(<|user_id: "u1", description: NULL|>)` |
|
|
150
153
|
| `IN COMPACT` | `WHERE key IN COMPACT $values` |
|
|
151
154
|
| `PRAGMA` | `PRAGMA AnsiImplicitCrossJoin` |
|
|
155
|
+
| Table-valued functions | `SELECT * FROM AS_TABLE($Input) AS k` |
|
|
156
|
+
| Table source options and index views | ``FROM `t` WITH TabletId='...'``, ``FROM `t` VIEW PRIMARY KEY v`` |
|
|
157
|
+
| Function-valued expressions | `$grep(x)`, `DateTime::Format("%Y-%m-%d")(ts)`, `Interval("P7D")` |
|
|
152
158
|
|
|
153
159
|
Table names without backticks are accepted on input; the generator always produces backtick-quoted output.
|
|
154
160
|
|
|
161
|
+
The parser also tolerates case variants that appear in real YQL dumps, such as
|
|
162
|
+
`set<Utf8>`, `Tuple<Int32, Utf8>?`, and lowercase `return` in lambda blocks.
|
|
163
|
+
|
|
155
164
|
#### CTEs reassembly
|
|
156
165
|
|
|
157
166
|
YDB-style named expressions are automatically reassembled into standard `WITH` CTEs when targeting other dialects:
|
|
@@ -207,6 +216,7 @@ Functions below are recognized by sqlglot as standard SQL expressions and transl
|
|
|
207
216
|
| `INTERVAL n HOUR` (literal) | `DateTime::IntervalFromHours(n)` |
|
|
208
217
|
| `INTERVAL n MINUTE` (literal) | `DateTime::IntervalFromMinutes(n)` |
|
|
209
218
|
| `INTERVAL n SECOND` (literal) | `DateTime::IntervalFromSeconds(n)` |
|
|
219
|
+
| `Interval("P7D")` (YQL input) | passed through unchanged |
|
|
210
220
|
| `dateDiff('minute', a, b)` | `(CAST(b AS Int64) - CAST(a AS Int64)) / 60000000` |
|
|
211
221
|
| `dateDiff('hour', a, b)` | `(CAST(b AS Int64) - CAST(a AS Int64)) / 3600000000` |
|
|
212
222
|
| `dateDiff('day', a, b)` | `(CAST(b AS Int64) - CAST(a AS Int64)) / 86400000000` |
|
|
@@ -256,6 +266,10 @@ arguments and block bodies with local named expressions:
|
|
|
256
266
|
($y) -> { $prefix = "x"; RETURN $prefix || $y; };
|
|
257
267
|
```
|
|
258
268
|
|
|
269
|
+
ClickHouse `ARRAY JOIN` and simple `arrayJoin(...)` projections, and PostgreSQL
|
|
270
|
+
`LATERAL unnest(...)`, are converted to YDB `FLATTEN BY` when the operation is
|
|
271
|
+
directly tied to the source table.
|
|
272
|
+
|
|
259
273
|
### Conditional / math
|
|
260
274
|
|
|
261
275
|
| Input | YQL output |
|
|
@@ -270,6 +284,18 @@ arguments and block bodies with local named expressions:
|
|
|
270
284
|
|---|---|
|
|
271
285
|
| `jsonb_col @> value` (PostgreSQL) | `Yson::Contains(jsonb_col, value)` |
|
|
272
286
|
|
|
287
|
+
YDB JSON functions are parsed and round-tripped, including `PASSING`,
|
|
288
|
+
`RETURNING`, wrapper modes, and `ON EMPTY` / `ON ERROR` clauses:
|
|
289
|
+
|
|
290
|
+
```sql
|
|
291
|
+
JSON_VALUE(payload, '$.value + $delta' PASSING 1 AS delta RETURNING Int64 DEFAULT 0 ON EMPTY ERROR ON ERROR)
|
|
292
|
+
JSON_QUERY(payload, '$.items' WITH CONDITIONAL ARRAY WRAPPER NULL ON EMPTY ERROR ON ERROR)
|
|
293
|
+
JSON_EXISTS(payload, '$.items[$Index]' PASSING 0 AS "Index" FALSE ON ERROR)
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
JSON paths can contain quoted keys, for example
|
|
297
|
+
`JSON_EXISTS(item_result, "$.'P_008 device playback test'")`.
|
|
298
|
+
|
|
273
299
|
---
|
|
274
300
|
|
|
275
301
|
## Type mapping
|
|
@@ -113,18 +113,27 @@ The plugin parses YDB/YQL back into sqlglot's AST, enabling round-trips, YDB-to-
|
|
|
113
113
|
| `$variable` references | `SELECT * FROM $t AS t` |
|
|
114
114
|
| `Module::Function()` | `DateTime::GetYear(ts)` |
|
|
115
115
|
| `DECLARE $p AS Type` | `DECLARE $p AS Int32` |
|
|
116
|
-
| `FLATTEN [LIST\|DICT] BY
|
|
116
|
+
| `FLATTEN [LIST\|DICT\|OPTIONAL] BY ...` / `FLATTEN COLUMNS` | `FROM t FLATTEN LIST BY col AS item`, `FROM t FLATTEN BY (a, b)`, `FROM t FLATTEN COLUMNS` |
|
|
117
117
|
| `Optional<T>` / `T?` | `CAST(x AS Optional<Utf8>)` |
|
|
118
118
|
| Container types | `CAST(x AS List<Int32>)`, `Dict<Utf8, Int64>`, `Set<Utf8>`, `Tuple<Int32, Utf8>` |
|
|
119
119
|
| `ASSUME ORDER BY` | `SELECT * FROM t ASSUME ORDER BY id` |
|
|
120
|
-
| `GROUP BY expr AS alias` | `SELECT v, COUNT(*) FROM t GROUP BY v AS v` |
|
|
120
|
+
| `GROUP BY expr AS alias` / `GROUP COMPACT BY` | `SELECT v, COUNT(*) FROM t GROUP BY v AS v` |
|
|
121
|
+
| `LEFT ONLY JOIN` | `SELECT * FROM a LEFT ONLY JOIN b USING (id)` |
|
|
122
|
+
| `* WITHOUT (...)` projections | `SELECT b.* WITHOUT (b.id) FROM t AS b` |
|
|
121
123
|
| Named expressions | `$t = (SELECT 1 AS x)` |
|
|
122
124
|
| Lambda expressions | `($x, $y?) -> ($x + COALESCE($y, 0))`, `($y) -> { $p = "x"; RETURN $p \|\| $y }` |
|
|
125
|
+
| YQL struct literals | `AsList(<|user_id: "u1", description: NULL|>)` |
|
|
123
126
|
| `IN COMPACT` | `WHERE key IN COMPACT $values` |
|
|
124
127
|
| `PRAGMA` | `PRAGMA AnsiImplicitCrossJoin` |
|
|
128
|
+
| Table-valued functions | `SELECT * FROM AS_TABLE($Input) AS k` |
|
|
129
|
+
| Table source options and index views | ``FROM `t` WITH TabletId='...'``, ``FROM `t` VIEW PRIMARY KEY v`` |
|
|
130
|
+
| Function-valued expressions | `$grep(x)`, `DateTime::Format("%Y-%m-%d")(ts)`, `Interval("P7D")` |
|
|
125
131
|
|
|
126
132
|
Table names without backticks are accepted on input; the generator always produces backtick-quoted output.
|
|
127
133
|
|
|
134
|
+
The parser also tolerates case variants that appear in real YQL dumps, such as
|
|
135
|
+
`set<Utf8>`, `Tuple<Int32, Utf8>?`, and lowercase `return` in lambda blocks.
|
|
136
|
+
|
|
128
137
|
#### CTEs reassembly
|
|
129
138
|
|
|
130
139
|
YDB-style named expressions are automatically reassembled into standard `WITH` CTEs when targeting other dialects:
|
|
@@ -180,6 +189,7 @@ Functions below are recognized by sqlglot as standard SQL expressions and transl
|
|
|
180
189
|
| `INTERVAL n HOUR` (literal) | `DateTime::IntervalFromHours(n)` |
|
|
181
190
|
| `INTERVAL n MINUTE` (literal) | `DateTime::IntervalFromMinutes(n)` |
|
|
182
191
|
| `INTERVAL n SECOND` (literal) | `DateTime::IntervalFromSeconds(n)` |
|
|
192
|
+
| `Interval("P7D")` (YQL input) | passed through unchanged |
|
|
183
193
|
| `dateDiff('minute', a, b)` | `(CAST(b AS Int64) - CAST(a AS Int64)) / 60000000` |
|
|
184
194
|
| `dateDiff('hour', a, b)` | `(CAST(b AS Int64) - CAST(a AS Int64)) / 3600000000` |
|
|
185
195
|
| `dateDiff('day', a, b)` | `(CAST(b AS Int64) - CAST(a AS Int64)) / 86400000000` |
|
|
@@ -229,6 +239,10 @@ arguments and block bodies with local named expressions:
|
|
|
229
239
|
($y) -> { $prefix = "x"; RETURN $prefix || $y; };
|
|
230
240
|
```
|
|
231
241
|
|
|
242
|
+
ClickHouse `ARRAY JOIN` and simple `arrayJoin(...)` projections, and PostgreSQL
|
|
243
|
+
`LATERAL unnest(...)`, are converted to YDB `FLATTEN BY` when the operation is
|
|
244
|
+
directly tied to the source table.
|
|
245
|
+
|
|
232
246
|
### Conditional / math
|
|
233
247
|
|
|
234
248
|
| Input | YQL output |
|
|
@@ -243,6 +257,18 @@ arguments and block bodies with local named expressions:
|
|
|
243
257
|
|---|---|
|
|
244
258
|
| `jsonb_col @> value` (PostgreSQL) | `Yson::Contains(jsonb_col, value)` |
|
|
245
259
|
|
|
260
|
+
YDB JSON functions are parsed and round-tripped, including `PASSING`,
|
|
261
|
+
`RETURNING`, wrapper modes, and `ON EMPTY` / `ON ERROR` clauses:
|
|
262
|
+
|
|
263
|
+
```sql
|
|
264
|
+
JSON_VALUE(payload, '$.value + $delta' PASSING 1 AS delta RETURNING Int64 DEFAULT 0 ON EMPTY ERROR ON ERROR)
|
|
265
|
+
JSON_QUERY(payload, '$.items' WITH CONDITIONAL ARRAY WRAPPER NULL ON EMPTY ERROR ON ERROR)
|
|
266
|
+
JSON_EXISTS(payload, '$.items[$Index]' PASSING 0 AS "Index" FALSE ON ERROR)
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
JSON paths can contain quoted keys, for example
|
|
270
|
+
`JSON_EXISTS(item_result, "$.'P_008 device playback test'")`.
|
|
271
|
+
|
|
246
272
|
---
|
|
247
273
|
|
|
248
274
|
## Type mapping
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
VERSION = "0.2.4"
|