ydb-sqlglot-plugin 0.2.0__tar.gz → 0.2.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ydb-sqlglot-plugin
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: YDB dialect plugin for sqlglot
5
5
  Author: YDB Team
6
6
  License: Apache-2.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "ydb-sqlglot-plugin"
7
- version = "0.2.0" # AUTOVERSION
7
+ version = "0.2.1" # AUTOVERSION
8
8
  description = "YDB dialect plugin for sqlglot"
9
9
  readme = "README.md"
10
10
  license = {text = "Apache-2.0"}
@@ -0,0 +1 @@
1
+ VERSION = "0.2.1"
@@ -403,26 +403,6 @@ def _apply_subquery_alias_columns(expression: exp.Expression) -> None:
403
403
  alias.set("columns", [])
404
404
 
405
405
 
406
- def _has_implicit_cross_join(expression: exp.Expression) -> bool:
407
- """Return True if the expression tree contains an implicit cross join.
408
-
409
- An implicit cross join arises from comma-separated FROM tables, e.g.
410
- ``FROM t1, t2``. In the sqlglot AST this appears as a ``Join`` node
411
- with no ``kind``, no ``on`` clause, and no ``using`` clause.
412
- YDB disables implicit cross joins by default; callers can prepend
413
- ``PRAGMA AnsiImplicitCrossJoin;`` when this returns True.
414
- """
415
- for node in expression.walk():
416
- if isinstance(node, exp.Join):
417
- if (
418
- not node.args.get("kind")
419
- and not node.args.get("on")
420
- and not node.args.get("using")
421
- ):
422
- return True
423
- return False
424
-
425
-
426
406
  class FlattenBy(exp.Expression):
427
407
  """YDB-specific FLATTEN [LIST|DICT] BY clause on a table reference."""
428
408
  arg_types = {"this": True, "expressions": True, "kind": False}
@@ -1384,12 +1364,6 @@ class YDB(Dialect):
1384
1364
  else:
1385
1365
  sql = self._generate_create_table(expression)
1386
1366
 
1387
- # Prepend PRAGMA AnsiImplicitCrossJoin only when the query contains
1388
- # implicit cross joins (FROM t1, t2 syntax). YDB disables them by
1389
- # default; the pragma restores standard SQL semantics.
1390
- if _has_implicit_cross_join(expression):
1391
- sql = "PRAGMA AnsiImplicitCrossJoin;\n" + sql
1392
-
1393
1367
  return sql
1394
1368
 
1395
1369
  def unnest_subqueries(self, expression):
@@ -2180,15 +2154,15 @@ class YDB(Dialect):
2180
2154
  # we move the WHERE expression from ON, using literals
2181
2155
  def join_sql(self, expression: exp.Join) -> str:
2182
2156
  on_condition = expression.args.get("on")
2183
- join_kind = expression.kind or ""
2184
-
2185
- # If LEFT/RIGHT/FULL JOIN has no ON clause, convert to CROSS JOIN
2186
- # YDB requires LEFT JOINs to have an ON clause
2187
- if not on_condition and any(
2188
- kind in join_kind.upper() for kind in ["LEFT", "RIGHT", "FULL", "OUTER", ""]
2189
- ):
2190
- expression.set("kind", None)
2191
- expression.set("on", None)
2157
+ using = expression.args.get("using")
2158
+
2159
+ # Any join with no ON/USING clause becomes an explicit CROSS JOIN.
2160
+ # YDB requires an ON clause for outer joins, and emitting CROSS JOIN
2161
+ # explicitly (instead of the comma-separated form) keeps the output
2162
+ # valid without any extra pragma.
2163
+ if not on_condition and not using:
2164
+ expression.set("kind", "CROSS")
2165
+ expression.set("side", None)
2192
2166
  return super().join_sql(expression)
2193
2167
 
2194
2168
  if on_condition:
@@ -2256,18 +2230,11 @@ class YDB(Dialect):
2256
2230
  on_condition = exp.and_(on_condition, cond)
2257
2231
  expression.set("on", on_condition)
2258
2232
  else:
2259
- # No valid equality conditions
2260
- # For LEFT/RIGHT/FULL JOINs, YDB requires ON clause, so convert to CROSS JOIN
2261
- join_kind = expression.side or ""
2262
- if any(
2263
- kind in join_kind.upper() for kind in ["LEFT", "RIGHT", "FULL", "OUTER"]
2264
- ):
2265
- # Convert to CROSS JOIN by removing kind and ON
2266
- expression.set("kind", None)
2267
- expression.set("on", None)
2268
- expression.set("side", "CROSS")
2269
- else:
2270
- expression.set("on", None)
2233
+ # No valid equality conditions remain on the JOIN — fall back
2234
+ # to an explicit CROSS JOIN regardless of the original kind.
2235
+ expression.set("kind", "CROSS")
2236
+ expression.set("on", None)
2237
+ expression.set("side", None)
2271
2238
 
2272
2239
  if conditions_to_move:
2273
2240
  select_stmt = expression.find_ancestor(exp.Select)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ydb-sqlglot-plugin
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: YDB dialect plugin for sqlglot
5
5
  Author: YDB Team
6
6
  License: Apache-2.0
@@ -1 +0,0 @@
1
- VERSION = "0.2.0"