sqlglotc 30.9.0__tar.gz → 30.10.0__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.
Files changed (112) hide show
  1. {sqlglotc-30.9.0/sqlglotc.egg-info → sqlglotc-30.10.0}/PKG-INFO +1 -1
  2. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/expressions/functions.py +6 -1
  3. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/expressions/properties.py +4 -0
  4. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/expressions/query.py +4 -4
  5. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generator.py +8 -0
  6. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/bigquery.py +6 -0
  7. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/databricks.py +4 -0
  8. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/duckdb.py +27 -1
  9. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/presto.py +2 -6
  10. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/snowflake.py +0 -3
  11. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/starrocks.py +5 -2
  12. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/optimizer/qualify_columns.py +2 -2
  13. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parser.py +13 -9
  14. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/bigquery.py +7 -0
  15. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/clickhouse.py +1 -0
  16. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/databricks.py +5 -0
  17. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/snowflake.py +9 -8
  18. {sqlglotc-30.9.0 → sqlglotc-30.10.0/sqlglotc.egg-info}/PKG-INFO +1 -1
  19. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/MANIFEST.in +0 -0
  20. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/pyproject.toml +0 -0
  21. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/setup.cfg +0 -0
  22. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/setup.py +0 -0
  23. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/errors.py +0 -0
  24. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/executor/table.py +0 -0
  25. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/expressions/aggregate.py +0 -0
  26. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/expressions/array.py +0 -0
  27. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/expressions/builders.py +0 -0
  28. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/expressions/constraints.py +0 -0
  29. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/expressions/core.py +0 -0
  30. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/expressions/datatypes.py +0 -0
  31. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/expressions/ddl.py +0 -0
  32. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/expressions/dml.py +0 -0
  33. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/expressions/json.py +0 -0
  34. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/expressions/math.py +0 -0
  35. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/expressions/string.py +0 -0
  36. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/expressions/temporal.py +0 -0
  37. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/athena.py +0 -0
  38. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/clickhouse.py +0 -0
  39. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/doris.py +0 -0
  40. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/dremio.py +0 -0
  41. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/drill.py +0 -0
  42. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/druid.py +0 -0
  43. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/dune.py +0 -0
  44. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/exasol.py +0 -0
  45. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/fabric.py +0 -0
  46. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/hive.py +0 -0
  47. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/materialize.py +0 -0
  48. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/mysql.py +0 -0
  49. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/oracle.py +0 -0
  50. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/postgres.py +0 -0
  51. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/prql.py +0 -0
  52. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/python.py +0 -0
  53. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/redshift.py +0 -0
  54. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/risingwave.py +0 -0
  55. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/singlestore.py +0 -0
  56. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/solr.py +0 -0
  57. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/spark.py +0 -0
  58. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/spark2.py +0 -0
  59. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/sqlite.py +0 -0
  60. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/tableau.py +0 -0
  61. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/teradata.py +0 -0
  62. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/trino.py +0 -0
  63. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/generators/tsql.py +0 -0
  64. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/helper.py +0 -0
  65. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/lineage.py +0 -0
  66. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/optimizer/annotate_types.py +0 -0
  67. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/optimizer/canonicalize_internal_names.py +0 -0
  68. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/optimizer/isolate_table_selects.py +0 -0
  69. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/optimizer/normalize_identifiers.py +0 -0
  70. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/optimizer/qualify.py +0 -0
  71. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/optimizer/qualify_tables.py +0 -0
  72. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/optimizer/resolver.py +0 -0
  73. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/optimizer/scope.py +0 -0
  74. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/optimizer/simplify.py +0 -0
  75. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/athena.py +0 -0
  76. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/base.py +0 -0
  77. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/doris.py +0 -0
  78. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/dremio.py +0 -0
  79. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/drill.py +0 -0
  80. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/druid.py +0 -0
  81. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/duckdb.py +0 -0
  82. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/dune.py +0 -0
  83. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/exasol.py +0 -0
  84. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/fabric.py +0 -0
  85. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/hive.py +0 -0
  86. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/materialize.py +0 -0
  87. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/mysql.py +0 -0
  88. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/oracle.py +0 -0
  89. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/postgres.py +0 -0
  90. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/presto.py +0 -0
  91. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/prql.py +0 -0
  92. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/redshift.py +0 -0
  93. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/risingwave.py +0 -0
  94. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/singlestore.py +0 -0
  95. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/solr.py +0 -0
  96. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/spark.py +0 -0
  97. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/spark2.py +0 -0
  98. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/sqlite.py +0 -0
  99. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/starrocks.py +0 -0
  100. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/tableau.py +0 -0
  101. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/teradata.py +0 -0
  102. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/trino.py +0 -0
  103. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/parsers/tsql.py +0 -0
  104. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/schema.py +0 -0
  105. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/serde.py +0 -0
  106. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/time.py +0 -0
  107. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/tokenizer_core.py +0 -0
  108. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglot/trie.py +0 -0
  109. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglotc.egg-info/SOURCES.txt +0 -0
  110. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglotc.egg-info/dependency_links.txt +0 -0
  111. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglotc.egg-info/requires.txt +0 -0
  112. {sqlglotc-30.9.0 → sqlglotc-30.10.0}/sqlglotc.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlglotc
3
- Version: 30.9.0
3
+ Version: 30.10.0
4
4
  Summary: mypyc-compiled extensions for sqlglot
5
5
  Author-email: Toby Mao <toby.mao@gmail.com>
6
6
  License-Expression: MIT
@@ -70,7 +70,12 @@ class Cast(Expression, Func):
70
70
 
71
71
 
72
72
  class TryCast(Cast):
73
- arg_types = {**Cast.arg_types, "requires_string": False, "null_on_text_overflow": False}
73
+ arg_types = {
74
+ **Cast.arg_types,
75
+ "requires_string": False,
76
+ "null_on_text_overflow": False,
77
+ "probe_date_format": False,
78
+ }
74
79
 
75
80
 
76
81
  class JSONCast(Cast):
@@ -75,6 +75,10 @@ class ChecksumProperty(Property):
75
75
  arg_types = {"on": False, "default": False}
76
76
 
77
77
 
78
+ class ClusterProperty(Property):
79
+ arg_types = {"this": False, "expressions": False}
80
+
81
+
78
82
  class CollateProperty(Property):
79
83
  arg_types = {"this": True, "default": False}
80
84
 
@@ -859,8 +859,8 @@ class SkipJSONColumn(Expression):
859
859
  arg_types = {"regexp": False, "expression": True}
860
860
 
861
861
 
862
- class Cluster(Order):
863
- pass
862
+ class Cluster(Expression):
863
+ arg_types = {"expressions": True}
864
864
 
865
865
 
866
866
  class Distribute(Order):
@@ -1271,8 +1271,8 @@ class Select(Expression, Query):
1271
1271
  Set the CLUSTER BY expression.
1272
1272
 
1273
1273
  Example:
1274
- >>> Select().from_("tbl").select("x").cluster_by("x DESC").sql(dialect="hive")
1275
- 'SELECT x FROM tbl CLUSTER BY x DESC'
1274
+ >>> Select().from_("tbl").select("x").cluster_by("x").sql(dialect="hive")
1275
+ 'SELECT x FROM tbl CLUSTER BY x'
1276
1276
 
1277
1277
  Args:
1278
1278
  *expressions: the SQL code strings to parse.
@@ -676,6 +676,7 @@ class Generator:
676
676
  exp.CopyGrantsProperty: exp.Properties.Location.POST_SCHEMA,
677
677
  exp.Cluster: exp.Properties.Location.POST_SCHEMA,
678
678
  exp.ClusteredByProperty: exp.Properties.Location.POST_SCHEMA,
679
+ exp.ClusterProperty: exp.Properties.Location.POST_SCHEMA,
679
680
  exp.DistributedByProperty: exp.Properties.Location.POST_SCHEMA,
680
681
  exp.DuplicateKeyProperty: exp.Properties.Location.POST_SCHEMA,
681
682
  exp.DataBlocksizeProperty: exp.Properties.Location.POST_NAME,
@@ -3042,6 +3043,13 @@ class Generator:
3042
3043
  def cluster_sql(self, expression: exp.Cluster) -> str:
3043
3044
  return self.op_expressions("CLUSTER BY", expression)
3044
3045
 
3046
+ def clusterproperty_sql(self, expression: exp.ClusterProperty) -> str:
3047
+ if expression.this:
3048
+ self.unsupported(f"Unsupported CLUSTER BY {self.sql(expression, 'this')}")
3049
+ return ""
3050
+ expressions = self.expressions(expression, flat=True)
3051
+ return f"CLUSTER BY ({expressions})"
3052
+
3045
3053
  def distribute_sql(self, expression: exp.Distribute) -> str:
3046
3054
  return self.op_expressions("DISTRIBUTE BY", expression)
3047
3055
 
@@ -688,3 +688,9 @@ class BigQueryGenerator(generator.Generator):
688
688
  return f"{self.sql(expression, 'to')}{self.sql(this)}"
689
689
 
690
690
  return super().cast_sql(expression, safe_prefix=safe_prefix)
691
+
692
+ def clusterproperty_sql(self, expression: exp.ClusterProperty) -> str:
693
+ if expression.this:
694
+ self.unsupported(f"Unsupported CLUSTER BY {self.sql(expression, 'this')}")
695
+ return ""
696
+ return self.op_expressions("CLUSTER BY", expression)
@@ -109,3 +109,7 @@ class DatabricksGenerator(SparkGenerator):
109
109
  seed = gen.this
110
110
 
111
111
  return self.func("UNIFORM", expression.this, expression.expression, seed)
112
+
113
+ def clusterproperty_sql(self, expression):
114
+ this = self.sql(expression, "this") or f"({self.expressions(expression, flat=True)})"
115
+ return f"CLUSTER BY {this}"
@@ -2181,6 +2181,14 @@ class DuckDBGenerator(generator.Generator):
2181
2181
  """
2182
2182
  )
2183
2183
 
2184
+ # Snowflake AUTO detects 3 DATE formats: YYYY-MM-DD (ISO-8601), MM/DD/YYYY, DD-MON-YYYY.
2185
+ # DuckDB TRY_CAST handles ISO-8601 natively. For the other two formats we use CONTAINS('/')
2186
+ # and REGEXP_MATCHES('[A-Za-z]') as heuristics — these correctly handle single-digit months
2187
+ # and days (e.g. 1/5/2020, 5-JAN-2020) where a positional char check would fail.
2188
+ # Ref: https://docs.snowflake.com/en/sql-reference/date-time-input-output#date-formats
2189
+ _TRYCAST_DATE_SLASH_FMT = "%m/%d/%Y"
2190
+ _TRYCAST_DATE_MON_FMT = "%d-%b-%Y"
2191
+
2184
2192
  def _array_bag_sql(self, condition: exp.Expr, arr1: exp.Expr, arr2: exp.Expr) -> str:
2185
2193
  cond = exp.Paren(this=exp.replace_placeholders(condition, arr1=arr1, arr2=arr2))
2186
2194
  return self.sql(
@@ -4329,13 +4337,13 @@ class DuckDBGenerator(generator.Generator):
4329
4337
  def trycast_sql(self, expression: exp.TryCast) -> str:
4330
4338
  to = expression.to
4331
4339
  to_type = to.this
4340
+ src = expression.this
4332
4341
 
4333
4342
  if (
4334
4343
  expression.args.get("null_on_text_overflow")
4335
4344
  and to_type in exp.DataType.TEXT_TYPES
4336
4345
  and to.expressions
4337
4346
  ):
4338
- src = expression.this
4339
4347
  return self.sql(
4340
4348
  exp.case()
4341
4349
  .when(
@@ -4344,6 +4352,24 @@ class DuckDBGenerator(generator.Generator):
4344
4352
  )
4345
4353
  .else_(exp.Null())
4346
4354
  )
4355
+ elif to_type == exp.DType.DATE and expression.args.get("probe_date_format"):
4356
+ slash_strptime = exp.cast(
4357
+ exp.func("TRY_STRPTIME", src, exp.Literal.string(self._TRYCAST_DATE_SLASH_FMT)),
4358
+ "DATE",
4359
+ )
4360
+ mon_strptime = exp.cast(
4361
+ exp.func("TRY_STRPTIME", src, exp.Literal.string(self._TRYCAST_DATE_MON_FMT)),
4362
+ "DATE",
4363
+ )
4364
+ return self.sql(
4365
+ exp.case()
4366
+ .when(exp.func("CONTAINS", src, exp.Literal.string("/")), slash_strptime)
4367
+ .when(
4368
+ exp.RegexpLike(this=src, expression=exp.Literal.string("[A-Za-z]")),
4369
+ mon_strptime,
4370
+ )
4371
+ .else_(exp.TryCast(this=src, to=to))
4372
+ )
4347
4373
 
4348
4374
  return super().trycast_sql(expression)
4349
4375
 
@@ -279,14 +279,10 @@ class PrestoGenerator(generator.Generator):
279
279
  exp.ArraySlice: rename_func("SLICE"),
280
280
  exp.AtTimeZone: rename_func("AT_TIMEZONE"),
281
281
  exp.BitwiseAnd: lambda self, e: self.func("BITWISE_AND", e.this, e.expression),
282
- exp.BitwiseLeftShift: lambda self, e: self.func(
283
- "BITWISE_ARITHMETIC_SHIFT_LEFT", e.this, e.expression
284
- ),
282
+ exp.BitwiseLeftShift: rename_func("BITWISE_LEFT_SHIFT"),
285
283
  exp.BitwiseNot: lambda self, e: self.func("BITWISE_NOT", e.this),
286
284
  exp.BitwiseOr: lambda self, e: self.func("BITWISE_OR", e.this, e.expression),
287
- exp.BitwiseRightShift: lambda self, e: self.func(
288
- "BITWISE_ARITHMETIC_SHIFT_RIGHT", e.this, e.expression
289
- ),
285
+ exp.BitwiseRightShift: rename_func("BITWISE_RIGHT_SHIFT"),
290
286
  exp.BitwiseXor: lambda self, e: self.func("BITWISE_XOR", e.this, e.expression),
291
287
  exp.Cast: transforms.preprocess([transforms.epoch_cast_to_ts]),
292
288
  exp.CurrentTime: lambda *_: "CURRENT_TIME",
@@ -903,9 +903,6 @@ class SnowflakeGenerator(generator.Generator):
903
903
 
904
904
  return f"AUTOINCREMENT{start}{increment}{order_clause}"
905
905
 
906
- def cluster_sql(self, expression: exp.Cluster) -> str:
907
- return f"CLUSTER BY ({self.expressions(expression, flat=True)})"
908
-
909
906
  def struct_sql(self, expression: exp.Struct) -> str:
910
907
  if len(expression.expressions) == 1:
911
908
  arg = expression.expressions[0]
@@ -310,10 +310,13 @@ class StarRocksGenerator(MySQLGenerator):
310
310
 
311
311
  return f"PARTITION BY {self.sql(this)}"
312
312
 
313
- def cluster_sql(self, expression: exp.Cluster) -> str:
313
+ def clusterproperty_sql(self, expression: exp.ClusterProperty) -> str:
314
314
  """Generate StarRocks ORDER BY clause for clustering."""
315
+ if expression.this:
316
+ self.unsupported(f"Unsupported CLUSTER BY {self.sql(expression, 'this')}")
317
+ return ""
315
318
  expressions = self.expressions(expression, flat=True)
316
- return f"ORDER BY ({expressions})" if expressions else ""
319
+ return f"ORDER BY ({expressions})"
317
320
 
318
321
  def refreshtriggerproperty_sql(self, expression: exp.RefreshTriggerProperty) -> str:
319
322
  """Generate StarRocks REFRESH clause for materialized views.
@@ -544,7 +544,7 @@ def _convert_columns_to_dots(scope: Scope, resolver: Resolver) -> None:
544
544
  dot_parts = column.meta.pop("dot_parts", [])
545
545
  if (
546
546
  column_table
547
- and column_table not in scope.sources
547
+ and column_table not in scope.selected_sources
548
548
  and (
549
549
  not scope.parent
550
550
  or column_table not in scope.parent.sources
@@ -553,7 +553,7 @@ def _convert_columns_to_dots(scope: Scope, resolver: Resolver) -> None:
553
553
  ):
554
554
  root, *parts = column.parts
555
555
 
556
- if isinstance(root, exp.Identifier) and root.name in scope.sources:
556
+ if isinstance(root, exp.Identifier) and root.name in scope.selected_sources:
557
557
  # The struct is already qualified, but we still need to change the AST
558
558
  column_table = root
559
559
  root, *parts = parts
@@ -1238,7 +1238,7 @@ class Parser:
1238
1238
  "CHARSET": lambda self, **kwargs: self._parse_character_set(**kwargs),
1239
1239
  "CHARACTER SET": lambda self, **kwargs: self._parse_character_set(**kwargs),
1240
1240
  "CHECKSUM": lambda self: self._parse_checksum(),
1241
- "CLUSTER BY": lambda self: self._parse_cluster(),
1241
+ "CLUSTER BY": lambda self: self._parse_cluster_property(),
1242
1242
  "CLUSTERED": lambda self: self._parse_clustered_by(),
1243
1243
  "COLLATE": lambda self, **kwargs: self._parse_property_assignment(
1244
1244
  exp.CollateProperty, **kwargs
@@ -1437,7 +1437,7 @@ class Parser:
1437
1437
  "ADD": lambda self: self._parse_alter_table_add(),
1438
1438
  "AS": lambda self: self._parse_select(),
1439
1439
  "ALTER": lambda self: self._parse_alter_table_alter(),
1440
- "CLUSTER BY": lambda self: self._parse_cluster(wrapped=True),
1440
+ "CLUSTER BY": lambda self: self._parse_cluster_property(),
1441
1441
  "DELETE": lambda self: self.expression(exp.Delete(where=self._parse_where())),
1442
1442
  "DROP": lambda self: self._parse_alter_table_drop(),
1443
1443
  "RENAME": lambda self: self._parse_alter_table_rename(),
@@ -1537,7 +1537,7 @@ class Parser:
1537
1537
  TokenType.USING: lambda self: ("sample", self._parse_table_sample(as_modifier=True)),
1538
1538
  TokenType.CLUSTER_BY: lambda self: (
1539
1539
  "cluster",
1540
- self._parse_sort(exp.Cluster, TokenType.CLUSTER_BY),
1540
+ self._parse_cluster(),
1541
1541
  ),
1542
1542
  TokenType.DISTRIBUTE_BY: lambda self: (
1543
1543
  "distribute",
@@ -3064,14 +3064,18 @@ class Parser:
3064
3064
 
3065
3065
  return self.expression(exp.ChecksumProperty(on=on, default=self._match(TokenType.DEFAULT)))
3066
3066
 
3067
- def _parse_cluster(self, wrapped: bool = False) -> exp.Cluster:
3067
+ def _parse_cluster(self) -> exp.Cluster:
3068
+ self._match(TokenType.CLUSTER_BY)
3068
3069
  return self.expression(
3069
3070
  exp.Cluster(
3070
- expressions=(
3071
- self._parse_wrapped_csv(self._parse_ordered)
3072
- if wrapped
3073
- else self._parse_csv(self._parse_ordered)
3074
- )
3071
+ expressions=self._parse_csv(self._parse_column),
3072
+ )
3073
+ )
3074
+
3075
+ def _parse_cluster_property(self) -> exp.ClusterProperty:
3076
+ return self.expression(
3077
+ exp.ClusterProperty(
3078
+ expressions=self._parse_wrapped_csv(self._parse_column),
3075
3079
  )
3076
3080
  )
3077
3081
 
@@ -509,6 +509,13 @@ class BigQueryParser(parser.Parser):
509
509
 
510
510
  return column
511
511
 
512
+ def _parse_cluster_property(self) -> exp.ClusterProperty:
513
+ return self.expression(
514
+ exp.ClusterProperty(
515
+ expressions=self._parse_csv(self._parse_column),
516
+ )
517
+ )
518
+
512
519
  @t.overload
513
520
  def _parse_json_object(self, agg: t.Literal[False]) -> exp.JSONObject: ...
514
521
 
@@ -316,6 +316,7 @@ class ClickHouseParser(parser.Parser):
316
316
  FUNC_TOKENS = {
317
317
  *parser.Parser.FUNC_TOKENS,
318
318
  TokenType.AND,
319
+ TokenType.FILE,
319
320
  TokenType.OR,
320
321
  TokenType.SET,
321
322
  }
@@ -53,3 +53,8 @@ class DatabricksParser(SparkParser):
53
53
  if self._match(TokenType.L_PAREN):
54
54
  self._match_r_paren()
55
55
  return self.expression(exp.CurrentDate())
56
+
57
+ def _parse_cluster_property(self):
58
+ if self._match_texts(("AUTO", "NONE")):
59
+ return self.expression(exp.ClusterProperty(this=self._prev.text.upper()))
60
+ return super()._parse_cluster_property()
@@ -89,11 +89,14 @@ def _build_datetime(name: str, kind: exp.DType, safe: bool = False) -> t.Callabl
89
89
  if isinstance(value, (exp.Literal, exp.Neg)) or (value and scale_or_fmt):
90
90
  # Converts calls like `TO_TIME('01:02:03')` into casts
91
91
  if len(args) == 1 and value.is_string and not int_value:
92
- return (
92
+ cast = (
93
93
  exp.TryCast(this=value, to=kind.into_expr(), requires_string=True)
94
94
  if safe
95
95
  else exp.cast(value, kind)
96
96
  )
97
+ if safe and kind == exp.DType.DATE:
98
+ cast.set("probe_date_format", True)
99
+ return cast
97
100
 
98
101
  # Handles `TO_TIMESTAMP(str, fmt)` and `TO_TIMESTAMP(num, scale)` as special
99
102
  # cases so we can transpile them, since they're relatively common
@@ -1308,13 +1311,11 @@ class SnowflakeParser(parser.Parser):
1308
1311
  if not strict and to and to.this == exp.DataType.Type.BOOLEAN:
1309
1312
  return self.expression(exp.ToBoolean(this=kwargs.get("this"), safe=True))
1310
1313
  cast = super().build_cast(strict, **kwargs)
1311
- if (
1312
- isinstance(cast, exp.TryCast)
1313
- and to
1314
- and to.this in exp.DataType.TEXT_TYPES
1315
- and to.expressions
1316
- ):
1317
- cast.set("null_on_text_overflow", True)
1314
+ if isinstance(cast, exp.TryCast) and to:
1315
+ if to.this in exp.DataType.TEXT_TYPES and to.expressions:
1316
+ cast.set("null_on_text_overflow", True)
1317
+ elif to.this == exp.DType.DATE and cast.this.is_string:
1318
+ cast.set("probe_date_format", True)
1318
1319
  return cast
1319
1320
 
1320
1321
  def _parse_window(self, this: exp.Expr | None, alias: bool = False) -> exp.Expr | None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlglotc
3
- Version: 30.9.0
3
+ Version: 30.10.0
4
4
  Summary: mypyc-compiled extensions for sqlglot
5
5
  Author-email: Toby Mao <toby.mao@gmail.com>
6
6
  License-Expression: MIT
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes