sqlglot.generators.hive
1from __future__ import annotations 2 3import re 4from functools import partial 5 6from sqlglot import exp, generator, transforms 7from sqlglot.dialects.dialect import ( 8 DATE_ADD_OR_SUB, 9 approx_count_distinct_sql, 10 arg_max_or_min_no_count, 11 datestrtodate_sql, 12 if_sql, 13 left_to_substring_sql, 14 max_or_greatest, 15 min_or_least, 16 no_ilike_sql, 17 no_recursive_cte_sql, 18 no_trycast_sql, 19 regexp_extract_sql, 20 regexp_replace_sql, 21 rename_func, 22 right_to_substring_sql, 23 strposition_sql, 24 struct_extract_sql, 25 time_format, 26 timestrtotime_sql, 27 trim_sql, 28 weekstart_unit_to_str, 29 var_map_sql, 30 sequence_sql, 31 property_sql, 32) 33from sqlglot.transforms import ( 34 remove_unique_constraints, 35 ctas_with_tmp_tables_to_create_tmp_view, 36 preprocess, 37 move_schema_columns_to_partitioned_by, 38) 39from sqlglot.generator import unsupported_args 40from sqlglot.time import format_time 41 42# These constants are duplicated from the Hive dialect class to avoid circular imports. 43# They must be kept in sync with Hive.TIME_FORMAT, Hive.DATE_FORMAT, Hive.DATEINT_FORMAT. 44HIVE_TIME_FORMAT = "'yyyy-MM-dd HH:mm:ss'" 45HIVE_DATE_FORMAT = "'yyyy-MM-dd'" 46HIVE_DATEINT_FORMAT = "'yyyyMMdd'" 47 48# The default formats above, as rendered by the lenient rewrite (non-padded month/day/time) 49HIVE_NON_PADDED_TIME_FORMATS = ("'yyyy-M-d H:m:s'", "'yyyy-M-d'") 50 51# Expressions that parse a string with a format (vs. formatting one, like TimeToStr). 52PARSE_TIME_EXPRESSIONS = (exp.StrToTime, exp.StrToDate, exp.StrToUnix, exp.TsOrDsToDate) 53 54CANONICAL_TIME_FORMAT = re.compile(r"%(?:[mdHIMS]strict|[-:].|.)") 55 56LAX_TO_NON_PADDED_FORMATS = { 57 "%m": "%-m", 58 "%d": "%-d", 59 "%H": "%-H", 60 "%I": "%-I", 61 "%M": "%-M", 62 "%S": "%-S", 63} 64 65 66def _lenient_parse_format(fmt: str) -> str: 67 """ 68 Changes a lax month/day/hour/minute/second in a canonical format to its non-padded form 69 (e.g. %m -> %-m), which java.time parses with or without a leading zero. This is only safe 70 for delimited specifiers, because adjacent fields parse greedily, so e.g. 'yyyyMd' (from 71 '%Y%m%d') can't even parse '20200101'. 72 73 The format is decomposed into specifiers (`formats`) and the interleaved literal text (`parts`). 74 Specifier i sits between parts[i] and parts[i + 1]. A specifier is changed only when its 75 neighbors don't touch a digit run, i.e., neither side is another specifier or a literal digit. 76 At the end, the pieces are zipped back together to produce the rewritten canonical format. 77 """ 78 parts = CANONICAL_TIME_FORMAT.split(fmt) 79 formats = CANONICAL_TIME_FORMAT.findall(fmt) 80 81 for i, fmt_ in enumerate(formats): 82 if fmt_ in LAX_TO_NON_PADDED_FORMATS: 83 left, right = parts[i], parts[i + 1] 84 left_adjacent = (not left and i > 0) or (left and left[-1].isdigit()) 85 right_adjacent = (not right and i < len(formats) - 1) or (right and right[0].isdigit()) 86 if not left_adjacent and not right_adjacent: 87 formats[i] = LAX_TO_NON_PADDED_FORMATS[fmt_] 88 89 return "".join(part + fmt_ for part, fmt_ in zip(parts, formats + [""])) 90 91 92# (FuncType, Multiplier) 93DATE_DELTA_INTERVAL = { 94 "YEAR": ("ADD_MONTHS", 12), 95 "MONTH": ("ADD_MONTHS", 1), 96 "QUARTER": ("ADD_MONTHS", 3), 97 "WEEK": ("DATE_ADD", 7), 98 "DAY": ("DATE_ADD", 1), 99} 100 101TIME_DIFF_FACTOR = { 102 "MILLISECOND": " * 1000", 103 "SECOND": "", 104 "MINUTE": " / 60", 105 "HOUR": " / 3600", 106} 107 108DIFF_MONTH_SWITCH = ("YEAR", "QUARTER", "MONTH") 109 110HIVE_TS_OR_DS_EXPRESSIONS: tuple[type[exp.Expr], ...] = ( 111 exp.DateDiff, 112 exp.Day, 113 exp.Month, 114 exp.Year, 115) 116 117 118def _add_date_sql(self: HiveGenerator, expression: DATE_ADD_OR_SUB) -> str: 119 if isinstance(expression, exp.TsOrDsAdd) and not expression.unit: 120 return self.func("DATE_ADD", expression.this, expression.expression) 121 122 unit = expression.text("unit").upper() 123 func, multiplier = DATE_DELTA_INTERVAL.get(unit, ("DATE_ADD", 1)) 124 125 if isinstance(expression, exp.DateSub): 126 multiplier *= -1 127 128 increment = expression.expression 129 if isinstance(increment, exp.Literal): 130 value = increment.to_py() if increment.is_number else int(increment.name) 131 increment = exp.Literal.number(value * multiplier) 132 elif multiplier != 1: 133 increment *= exp.Literal.number(multiplier) 134 135 return self.func(func, expression.this, increment) 136 137 138def _date_diff_sql(self: HiveGenerator, expression: exp.DateDiff | exp.TsOrDsDiff) -> str: 139 unit = expression.text("unit").upper() 140 141 factor = TIME_DIFF_FACTOR.get(unit) 142 if factor is not None: 143 left = self.sql(expression, "this") 144 right = self.sql(expression, "expression") 145 sec_diff = f"UNIX_TIMESTAMP({left}) - UNIX_TIMESTAMP({right})" 146 return f"({sec_diff}){factor}" if factor else sec_diff 147 148 months_between = unit in DIFF_MONTH_SWITCH 149 sql_func = "MONTHS_BETWEEN" if months_between else "DATEDIFF" 150 _, multiplier = DATE_DELTA_INTERVAL.get(unit, ("", 1)) 151 multiplier_sql = f" / {multiplier}" if multiplier > 1 else "" 152 diff_sql = f"{sql_func}({self.format_args(expression.this, expression.expression)})" 153 154 if months_between or multiplier_sql: 155 # MONTHS_BETWEEN returns a float, so we need to truncate the fractional part. 156 # For the same reason, we want to truncate if there's a divisor present. 157 diff_sql = f"CAST({diff_sql}{multiplier_sql} AS INT)" 158 159 return diff_sql 160 161 162@generator.unsupported_args(("expression", "Hive's SORT_ARRAY does not support a comparator.")) 163def _array_sort_sql(self: HiveGenerator, expression: exp.ArraySort) -> str: 164 return self.func("SORT_ARRAY", expression.this) 165 166 167def _str_to_unix_sql(self: HiveGenerator, expression: exp.StrToUnix) -> str: 168 return self.func("UNIX_TIMESTAMP", expression.this, time_format("hive")(self, expression)) 169 170 171def _unix_to_time_sql(self: HiveGenerator, expression: exp.UnixToTime) -> str: 172 timestamp = self.sql(expression, "this") 173 scale = expression.args.get("scale") 174 if scale in (None, exp.UnixToTime.SECONDS): 175 return rename_func("FROM_UNIXTIME")(self, expression) 176 177 return f"FROM_UNIXTIME({timestamp} / POW(10, {scale}))" 178 179 180def _is_cast_time_format(self: HiveGenerator, expression: exp.Expr, time_format: str) -> bool: 181 """Checks whether CAST subsumes the expression's parse format.""" 182 if time_format in (HIVE_TIME_FORMAT, HIVE_DATE_FORMAT): 183 return True 184 185 if time_format in HIVE_NON_PADDED_TIME_FORMATS: 186 # The base render skips the lenient rewrite: a lax specifier pads back (e.g. %m -> MM), 187 # an explicit non-padded specifier (e.g. %-m) doesn't 188 padded_format = generator.Generator.format_time(self, expression) 189 return padded_format in (HIVE_TIME_FORMAT, HIVE_DATE_FORMAT) 190 191 return False 192 193 194def _str_to_date_sql(self: HiveGenerator, expression: exp.StrToDate) -> str: 195 this = self.sql(expression, "this") 196 time_format = self.format_time(expression) 197 if time_format and not _is_cast_time_format(self, expression, time_format): 198 this = f"FROM_UNIXTIME(UNIX_TIMESTAMP({this}, {time_format}))" 199 return f"CAST({this} AS DATE)" 200 201 202def _str_to_time_sql(self: HiveGenerator, expression: exp.StrToTime) -> str: 203 this = self.sql(expression, "this") 204 time_format = self.format_time(expression) 205 if time_format and not _is_cast_time_format(self, expression, time_format): 206 this = f"FROM_UNIXTIME(UNIX_TIMESTAMP({this}, {time_format}))" 207 return f"CAST({this} AS TIMESTAMP)" 208 209 210def _to_date_sql(self: HiveGenerator, expression: exp.TsOrDsToDate) -> str: 211 time_format = self.format_time(expression) 212 if time_format and not _is_cast_time_format(self, expression, time_format): 213 return self.func("TO_DATE", expression.this, time_format) 214 215 if isinstance(expression.parent, self.TS_OR_DS_EXPRESSIONS): 216 return self.sql(expression, "this") 217 218 return self.func("TO_DATE", expression.this) 219 220 221class HiveGenerator(generator.Generator): 222 SELECT_KINDS: tuple[str, ...] = () 223 TRY_SUPPORTED = False 224 SUPPORTS_UESCAPE = False 225 SUPPORTS_DECODE_CASE = False 226 LIMIT_FETCH = "LIMIT" 227 TABLESAMPLE_WITH_METHOD = False 228 JOIN_HINTS = False 229 TABLE_HINTS = False 230 QUERY_HINTS = False 231 INDEX_ON = "ON TABLE" 232 EXTRACT_ALLOWS_QUOTES = False 233 NVL2_SUPPORTED = False 234 LAST_DAY_SUPPORTS_DATE_PART = False 235 JSON_PATH_SINGLE_QUOTE_ESCAPE = True 236 SAFE_JSON_PATH_KEY_RE = re.compile(r"^[_\-a-zA-Z][\-\w]*$") 237 SUPPORTS_TO_NUMBER = False 238 WITH_PROPERTIES_PREFIX = "TBLPROPERTIES" 239 PARSE_JSON_NAME: str | None = "PARSE_JSON" 240 PAD_FILL_PATTERN_IS_REQUIRED = True 241 SUPPORTS_MEDIAN = False 242 ARRAY_SIZE_NAME = "SIZE" 243 ALTER_SET_TYPE = "" 244 245 EXPRESSIONS_WITHOUT_NESTED_CTES = { 246 exp.Insert, 247 exp.Select, 248 exp.Subquery, 249 exp.SetOperation, 250 } 251 252 SUPPORTED_JSON_PATH_PARTS = { 253 exp.JSONPathKey, 254 exp.JSONPathRoot, 255 exp.JSONPathSubscript, 256 exp.JSONPathWildcard, 257 } 258 259 TYPE_MAPPING = { 260 **generator.Generator.TYPE_MAPPING, 261 exp.DType.BIT: "BOOLEAN", 262 exp.DType.BLOB: "BINARY", 263 exp.DType.DATETIME: "TIMESTAMP", 264 exp.DType.ROWVERSION: "BINARY", 265 exp.DType.TEXT: "STRING", 266 exp.DType.TIME: "TIMESTAMP", 267 exp.DType.TIMESTAMPNTZ: "TIMESTAMP", 268 exp.DType.TIMESTAMPTZ: "TIMESTAMP", 269 exp.DType.UTINYINT: "SMALLINT", 270 exp.DType.VARBINARY: "BINARY", 271 } 272 273 TRANSFORMS = { 274 **generator.Generator.TRANSFORMS, 275 exp.Property: property_sql, 276 exp.AnyValue: rename_func("FIRST"), 277 exp.ApproxDistinct: approx_count_distinct_sql, 278 exp.ArgMax: arg_max_or_min_no_count("MAX_BY"), 279 exp.ArgMin: arg_max_or_min_no_count("MIN_BY"), 280 exp.Array: transforms.preprocess([transforms.inherit_struct_field_names]), 281 exp.ArrayConcat: rename_func("CONCAT"), 282 exp.ArrayToString: lambda self, e: self.func("CONCAT_WS", e.expression, e.this), 283 exp.ArraySort: _array_sort_sql, 284 exp.With: no_recursive_cte_sql, 285 exp.DateAdd: _add_date_sql, 286 exp.DateDiff: _date_diff_sql, 287 exp.DateStrToDate: datestrtodate_sql, 288 exp.DateSub: _add_date_sql, 289 exp.DateToDi: lambda self, e: ( 290 f"CAST(DATE_FORMAT({self.sql(e, 'this')}, {HIVE_DATEINT_FORMAT}) AS INT)" 291 ), 292 exp.DiToDate: lambda self, e: ( 293 f"TO_DATE(CAST({self.sql(e, 'this')} AS STRING), {HIVE_DATEINT_FORMAT})" 294 ), 295 exp.StorageHandlerProperty: lambda self, e: f"STORED BY {self.sql(e, 'this')}", 296 exp.FromBase64: rename_func("UNBASE64"), 297 exp.GenerateSeries: sequence_sql, 298 exp.GenerateDateArray: sequence_sql, 299 exp.If: if_sql(), 300 exp.ILike: no_ilike_sql, 301 exp.IntDiv: lambda self, e: self.binary(e, "DIV"), 302 exp.IsNan: rename_func("ISNAN"), 303 exp.JSONExtract: lambda self, e: self.func("GET_JSON_OBJECT", e.this, e.expression), 304 exp.JSONExtractScalar: lambda self, e: self.func("GET_JSON_OBJECT", e.this, e.expression), 305 exp.JSONFormat: rename_func("TO_JSON"), 306 exp.Left: left_to_substring_sql, 307 exp.Map: var_map_sql, 308 exp.Max: max_or_greatest, 309 exp.MD5Digest: lambda self, e: self.func("UNHEX", self.func("MD5", e.this)), 310 exp.Min: min_or_least, 311 exp.MonthsBetween: lambda self, e: self.func("MONTHS_BETWEEN", e.this, e.expression), 312 exp.NotNullColumnConstraint: lambda _, e: "" if e.args.get("allow_null") else "NOT NULL", 313 exp.VarMap: var_map_sql, 314 exp.Create: preprocess( 315 [ 316 remove_unique_constraints, 317 ctas_with_tmp_tables_to_create_tmp_view, 318 move_schema_columns_to_partitioned_by, 319 ] 320 ), 321 exp.Quantile: rename_func("PERCENTILE"), 322 exp.ApproxQuantile: rename_func("PERCENTILE_APPROX"), 323 exp.RegexpExtract: regexp_extract_sql, 324 exp.RegexpExtractAll: regexp_extract_sql, 325 exp.RegexpReplace: regexp_replace_sql, 326 exp.RegexpLike: lambda self, e: self.binary(e, "RLIKE"), 327 exp.RegexpSplit: rename_func("SPLIT"), 328 exp.Right: right_to_substring_sql, 329 exp.SchemaCommentProperty: lambda self, e: self.naked_property(e), 330 exp.ArrayUniqueAgg: rename_func("COLLECT_SET"), 331 exp.Split: lambda self, e: self.func( 332 "SPLIT", e.this, self.func("CONCAT", "'\\\\Q'", e.expression, "'\\\\E'") 333 ), 334 exp.Select: transforms.preprocess( 335 [ 336 transforms.eliminate_qualify, 337 transforms.eliminate_distinct_on, 338 partial(transforms.unnest_to_explode, unnest_using_arrays_zip=False), 339 transforms.any_to_exists, 340 ] 341 ), 342 exp.StrPosition: lambda self, e: strposition_sql( 343 self, e, func_name="LOCATE", supports_position=True 344 ), 345 exp.StrToDate: _str_to_date_sql, 346 exp.StrToTime: _str_to_time_sql, 347 exp.StrToUnix: _str_to_unix_sql, 348 exp.StructExtract: struct_extract_sql, 349 exp.StarMap: rename_func("MAP"), 350 exp.Table: transforms.preprocess([transforms.unnest_generate_series]), 351 exp.TimeStrToDate: rename_func("TO_DATE"), 352 exp.TimeStrToTime: timestrtotime_sql, 353 exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"), 354 exp.TimestampTrunc: lambda self, e: self.func( 355 "TRUNC", e.this, weekstart_unit_to_str(self, e) 356 ), 357 exp.TimeToUnix: rename_func("UNIX_TIMESTAMP"), 358 exp.ToBase64: rename_func("BASE64"), 359 exp.TsOrDiToDi: lambda self, e: ( 360 f"CAST(SUBSTR(REPLACE(CAST({self.sql(e, 'this')} AS STRING), '-', ''), 1, 8) AS INT)" 361 ), 362 exp.TsOrDsAdd: _add_date_sql, 363 exp.TsOrDsDiff: _date_diff_sql, 364 exp.TsOrDsToDate: _to_date_sql, 365 exp.TryCast: no_trycast_sql, 366 exp.Trim: trim_sql, 367 exp.Unicode: rename_func("ASCII"), 368 exp.UnixToStr: lambda self, e: self.func( 369 "FROM_UNIXTIME", e.this, time_format("hive")(self, e) 370 ), 371 exp.UnixToTime: _unix_to_time_sql, 372 exp.UnixToTimeStr: rename_func("FROM_UNIXTIME"), 373 exp.Unnest: rename_func("EXPLODE"), 374 exp.PartitionedByProperty: lambda self, e: f"PARTITIONED BY {self.sql(e, 'this')}", 375 exp.NumberToStr: rename_func("FORMAT_NUMBER"), 376 exp.National: lambda self, e: self.national_sql(e, prefix=""), 377 exp.ClusteredColumnConstraint: lambda self, e: ( 378 f"({self.expressions(e, 'this', indent=False)})" 379 ), 380 exp.NonClusteredColumnConstraint: lambda self, e: ( 381 f"({self.expressions(e, 'this', indent=False)})" 382 ), 383 exp.NotForReplicationColumnConstraint: lambda *_: "", 384 exp.OnProperty: lambda *_: "", 385 exp.PartitionedByBucket: lambda self, e: self.func("BUCKET", e.expression, e.this), 386 exp.PartitionByTruncate: lambda self, e: self.func("TRUNCATE", e.expression, e.this), 387 exp.PrimaryKeyColumnConstraint: lambda *_: "PRIMARY KEY", 388 exp.WeekOfYear: rename_func("WEEKOFYEAR"), 389 exp.DayOfMonth: rename_func("DAYOFMONTH"), 390 exp.DayOfWeek: rename_func("DAYOFWEEK"), 391 exp.Levenshtein: unsupported_args("ins_cost", "del_cost", "sub_cost", "max_dist")( 392 rename_func("LEVENSHTEIN") 393 ), 394 } 395 396 PROPERTIES_LOCATION = { 397 **generator.Generator.PROPERTIES_LOCATION, 398 exp.FileFormatProperty: exp.Properties.Location.POST_SCHEMA, 399 exp.PartitionedByProperty: exp.Properties.Location.POST_SCHEMA, 400 exp.VolatileProperty: exp.Properties.Location.UNSUPPORTED, 401 exp.WithDataProperty: exp.Properties.Location.UNSUPPORTED, 402 } 403 404 TS_OR_DS_EXPRESSIONS = HIVE_TS_OR_DS_EXPRESSIONS 405 406 IGNORE_NULLS_FUNCS = (exp.First, exp.Last, exp.FirstValue, exp.LastValue) 407 408 def format_time( 409 self, 410 expression: exp.Expr, 411 inverse_time_mapping: dict[str, str] | None = None, 412 inverse_time_trie: dict | None = None, 413 ) -> str | None: 414 # Inferred property because this method is reused by other dialects under Hive 415 is_dialect_strict = self.dialect.TIME_MAPPING.get("MM") == "%mstrict" 416 417 if ( 418 is_dialect_strict 419 and inverse_time_mapping is None 420 and isinstance(expression, PARSE_TIME_EXPRESSIONS) 421 ): 422 # Render a lenient %m/%d non-padded (M/d) so single-digit sources stay parseable 423 return format_time( 424 _lenient_parse_format(self.sql(expression, "format")), 425 self.dialect.INVERSE_TIME_MAPPING, 426 self.dialect.INVERSE_TIME_TRIE, 427 ) 428 429 return super().format_time(expression, inverse_time_mapping, inverse_time_trie) 430 431 def ignorenulls_sql(self, expression: exp.IgnoreNulls) -> str: 432 this = expression.this 433 if isinstance(this, self.IGNORE_NULLS_FUNCS): 434 return self.func(this.sql_name(), this.this, exp.true()) 435 436 return super().ignorenulls_sql(expression) 437 438 def unnest_sql(self, expression: exp.Unnest) -> str: 439 return rename_func("EXPLODE")(self, expression) 440 441 def _jsonpathkey_sql(self, expression: exp.JSONPathKey) -> str: 442 if isinstance(expression.this, exp.JSONPathWildcard): 443 self.unsupported("Unsupported wildcard in JSONPathKey expression") 444 return "" 445 446 return super()._jsonpathkey_sql(expression) 447 448 def parameter_sql(self, expression: exp.Parameter) -> str: 449 this = self.sql(expression, "this") 450 expression_sql = self.sql(expression, "expression") 451 452 parent = expression.parent 453 this = f"{this}:{expression_sql}" if expression_sql else this 454 455 if isinstance(parent, exp.EQ) and isinstance(parent.parent, exp.SetItem): 456 # We need to produce SET key = value instead of SET ${key} = value 457 return this 458 459 return f"${{{this}}}" 460 461 def schema_sql(self, expression: exp.Schema) -> str: 462 for ordered in expression.find_all(exp.Ordered): 463 if ordered.args.get("desc") is False: 464 ordered.set("desc", None) 465 466 return super().schema_sql(expression) 467 468 def constraint_sql(self, expression: exp.Constraint) -> str: 469 for prop in list(expression.find_all(exp.Properties)): 470 prop.pop() 471 472 this = self.sql(expression, "this") 473 expressions = self.expressions(expression, sep=" ", flat=True) 474 return f"CONSTRAINT {this} {expressions}" 475 476 def rowformatserdeproperty_sql(self, expression: exp.RowFormatSerdeProperty) -> str: 477 serde_props = self.sql(expression, "serde_properties") 478 serde_props = f" {serde_props}" if serde_props else "" 479 return f"ROW FORMAT SERDE {self.sql(expression, 'this')}{serde_props}" 480 481 def arrayagg_sql(self, expression: exp.ArrayAgg) -> str: 482 return self.func( 483 "COLLECT_LIST", 484 expression.this.this if isinstance(expression.this, exp.Order) else expression.this, 485 ) 486 487 # Hive/Spark lack native numeric TRUNC. CAST to BIGINT truncates toward zero (not rounds). 488 # Potential enhancement: a TRUNC_TEMPLATE using FLOOR/CEIL with scale (Spark 3.3+) 489 # could preserve decimals: CASE WHEN x >= 0 THEN FLOOR(x, d) ELSE CEIL(x, d) END 490 @unsupported_args("decimals") 491 def trunc_sql(self, expression: exp.Trunc) -> str: 492 return self.sql(exp.cast(expression.this, exp.DType.BIGINT)) 493 494 def datatype_sql(self, expression: exp.DataType) -> str: 495 if expression.this in self.PARAMETERIZABLE_TEXT_TYPES and ( 496 not expression.expressions or expression.expressions[0].name == "MAX" 497 ): 498 expression.set("this", exp.DType.TEXT) 499 expression.set("expressions", None) 500 elif expression.is_type(exp.DType.TEXT) and expression.expressions: 501 expression.set("this", exp.DType.VARCHAR) 502 elif expression.this in exp.DataType.TEMPORAL_TYPES: 503 expression.set("expressions", None) 504 elif expression.is_type("float"): 505 size_expression = expression.find(exp.DataTypeParam) 506 if size_expression: 507 size = int(size_expression.name) 508 expression.set("this", exp.DType.FLOAT if size <= 32 else exp.DType.DOUBLE) 509 expression.set("expressions", None) 510 return super().datatype_sql(expression) 511 512 def version_sql(self, expression: exp.Version) -> str: 513 sql = super().version_sql(expression) 514 return sql.replace("FOR ", "", 1) 515 516 def struct_sql(self, expression: exp.Struct) -> str: 517 values = [] 518 519 for i, e in enumerate(expression.expressions): 520 if isinstance(e, exp.PropertyEQ): 521 self.unsupported("Hive does not support named structs.") 522 values.append(e.expression) 523 else: 524 values.append(e) 525 526 return self.func("STRUCT", *values) 527 528 def columndef_sql(self, expression: exp.ColumnDef, sep: str = " ") -> str: 529 return super().columndef_sql( 530 expression, 531 sep=( 532 ": " 533 if isinstance(expression.parent, exp.DataType) 534 and expression.parent.is_type("struct") 535 else sep 536 ), 537 ) 538 539 def altercolumn_sql(self, expression: exp.AlterColumn) -> str: 540 this = self.sql(expression, "this") 541 new_name = self.sql(expression, "rename_to") or this 542 dtype = self.sql(expression, "dtype") 543 comment = ( 544 f" COMMENT {self.sql(expression, 'comment')}" if self.sql(expression, "comment") else "" 545 ) 546 default = self.sql(expression, "default") 547 visible = expression.args.get("visible") 548 allow_null = expression.args.get("allow_null") 549 drop = expression.args.get("drop") 550 551 if any([default, drop, visible, allow_null, drop]): 552 self.unsupported("Unsupported CHANGE COLUMN syntax") 553 554 if not dtype: 555 self.unsupported("CHANGE COLUMN without a type is not supported") 556 557 return f"CHANGE COLUMN {this} {new_name} {dtype}{comment}" 558 559 def renamecolumn_sql(self, expression: exp.RenameColumn) -> str: 560 self.unsupported("Cannot rename columns without data type defined in Hive") 561 return "" 562 563 def alterset_sql(self, expression: exp.AlterSet) -> str: 564 exprs = self.expressions(expression, flat=True) 565 exprs = f" {exprs}" if exprs else "" 566 location = self.sql(expression, "location") 567 location = f" LOCATION {location}" if location else "" 568 file_format = self.expressions(expression, key="file_format", flat=True, sep=" ") 569 file_format = f" FILEFORMAT {file_format}" if file_format else "" 570 serde = self.sql(expression, "serde") 571 serde = f" SERDE {serde}" if serde else "" 572 tags = self.expressions(expression, key="tag", flat=True, sep="") 573 tags = f" TAGS {tags}" if tags else "" 574 575 return f"SET{serde}{exprs}{location}{file_format}{tags}" 576 577 def serdeproperties_sql(self, expression: exp.SerdeProperties) -> str: 578 prefix = "WITH " if expression.args.get("with_") else "" 579 exprs = self.expressions(expression, flat=True) 580 581 return f"{prefix}SERDEPROPERTIES ({exprs})" 582 583 def exists_sql(self, expression: exp.Exists) -> str: 584 if expression.expression: 585 return self.function_fallback_sql(expression) 586 587 return super().exists_sql(expression) 588 589 def timetostr_sql(self, expression: exp.TimeToStr) -> str: 590 this = expression.this 591 if isinstance(this, exp.TimeStrToTime): 592 this = this.this 593 594 return self.func("DATE_FORMAT", this, self.format_time(expression)) 595 596 def usingproperty_sql(self, expression: exp.UsingProperty) -> str: 597 kind = expression.args.get("kind") 598 return f"USING {kind} {self.sql(expression, 'this')}" 599 600 def fileformatproperty_sql(self, expression: exp.FileFormatProperty) -> str: 601 if isinstance(expression.this, exp.InputOutputFormat): 602 this = self.sql(expression, "this") 603 else: 604 this = expression.name.upper() 605 606 return f"STORED AS {this}"
HIVE_TIME_FORMAT =
"'yyyy-MM-dd HH:mm:ss'"
HIVE_DATE_FORMAT =
"'yyyy-MM-dd'"
HIVE_DATEINT_FORMAT =
"'yyyyMMdd'"
HIVE_NON_PADDED_TIME_FORMATS =
("'yyyy-M-d H:m:s'", "'yyyy-M-d'")
PARSE_TIME_EXPRESSIONS =
(<class 'sqlglot.expressions.temporal.StrToTime'>, <class 'sqlglot.expressions.temporal.StrToDate'>, <class 'sqlglot.expressions.temporal.StrToUnix'>, <class 'sqlglot.expressions.temporal.TsOrDsToDate'>)
CANONICAL_TIME_FORMAT =
re.compile('%(?:[mdHIMS]strict|[-:].|.)')
LAX_TO_NON_PADDED_FORMATS =
{'%m': '%-m', '%d': '%-d', '%H': '%-H', '%I': '%-I', '%M': '%-M', '%S': '%-S'}
DATE_DELTA_INTERVAL =
{'YEAR': ('ADD_MONTHS', 12), 'MONTH': ('ADD_MONTHS', 1), 'QUARTER': ('ADD_MONTHS', 3), 'WEEK': ('DATE_ADD', 7), 'DAY': ('DATE_ADD', 1)}
TIME_DIFF_FACTOR =
{'MILLISECOND': ' * 1000', 'SECOND': '', 'MINUTE': ' / 60', 'HOUR': ' / 3600'}
DIFF_MONTH_SWITCH =
('YEAR', 'QUARTER', 'MONTH')
HIVE_TS_OR_DS_EXPRESSIONS: tuple[type[sqlglot.expressions.core.Expr], ...] =
(<class 'sqlglot.expressions.temporal.DateDiff'>, <class 'sqlglot.expressions.temporal.Day'>, <class 'sqlglot.expressions.temporal.Month'>, <class 'sqlglot.expressions.temporal.Year'>)
222class HiveGenerator(generator.Generator): 223 SELECT_KINDS: tuple[str, ...] = () 224 TRY_SUPPORTED = False 225 SUPPORTS_UESCAPE = False 226 SUPPORTS_DECODE_CASE = False 227 LIMIT_FETCH = "LIMIT" 228 TABLESAMPLE_WITH_METHOD = False 229 JOIN_HINTS = False 230 TABLE_HINTS = False 231 QUERY_HINTS = False 232 INDEX_ON = "ON TABLE" 233 EXTRACT_ALLOWS_QUOTES = False 234 NVL2_SUPPORTED = False 235 LAST_DAY_SUPPORTS_DATE_PART = False 236 JSON_PATH_SINGLE_QUOTE_ESCAPE = True 237 SAFE_JSON_PATH_KEY_RE = re.compile(r"^[_\-a-zA-Z][\-\w]*$") 238 SUPPORTS_TO_NUMBER = False 239 WITH_PROPERTIES_PREFIX = "TBLPROPERTIES" 240 PARSE_JSON_NAME: str | None = "PARSE_JSON" 241 PAD_FILL_PATTERN_IS_REQUIRED = True 242 SUPPORTS_MEDIAN = False 243 ARRAY_SIZE_NAME = "SIZE" 244 ALTER_SET_TYPE = "" 245 246 EXPRESSIONS_WITHOUT_NESTED_CTES = { 247 exp.Insert, 248 exp.Select, 249 exp.Subquery, 250 exp.SetOperation, 251 } 252 253 SUPPORTED_JSON_PATH_PARTS = { 254 exp.JSONPathKey, 255 exp.JSONPathRoot, 256 exp.JSONPathSubscript, 257 exp.JSONPathWildcard, 258 } 259 260 TYPE_MAPPING = { 261 **generator.Generator.TYPE_MAPPING, 262 exp.DType.BIT: "BOOLEAN", 263 exp.DType.BLOB: "BINARY", 264 exp.DType.DATETIME: "TIMESTAMP", 265 exp.DType.ROWVERSION: "BINARY", 266 exp.DType.TEXT: "STRING", 267 exp.DType.TIME: "TIMESTAMP", 268 exp.DType.TIMESTAMPNTZ: "TIMESTAMP", 269 exp.DType.TIMESTAMPTZ: "TIMESTAMP", 270 exp.DType.UTINYINT: "SMALLINT", 271 exp.DType.VARBINARY: "BINARY", 272 } 273 274 TRANSFORMS = { 275 **generator.Generator.TRANSFORMS, 276 exp.Property: property_sql, 277 exp.AnyValue: rename_func("FIRST"), 278 exp.ApproxDistinct: approx_count_distinct_sql, 279 exp.ArgMax: arg_max_or_min_no_count("MAX_BY"), 280 exp.ArgMin: arg_max_or_min_no_count("MIN_BY"), 281 exp.Array: transforms.preprocess([transforms.inherit_struct_field_names]), 282 exp.ArrayConcat: rename_func("CONCAT"), 283 exp.ArrayToString: lambda self, e: self.func("CONCAT_WS", e.expression, e.this), 284 exp.ArraySort: _array_sort_sql, 285 exp.With: no_recursive_cte_sql, 286 exp.DateAdd: _add_date_sql, 287 exp.DateDiff: _date_diff_sql, 288 exp.DateStrToDate: datestrtodate_sql, 289 exp.DateSub: _add_date_sql, 290 exp.DateToDi: lambda self, e: ( 291 f"CAST(DATE_FORMAT({self.sql(e, 'this')}, {HIVE_DATEINT_FORMAT}) AS INT)" 292 ), 293 exp.DiToDate: lambda self, e: ( 294 f"TO_DATE(CAST({self.sql(e, 'this')} AS STRING), {HIVE_DATEINT_FORMAT})" 295 ), 296 exp.StorageHandlerProperty: lambda self, e: f"STORED BY {self.sql(e, 'this')}", 297 exp.FromBase64: rename_func("UNBASE64"), 298 exp.GenerateSeries: sequence_sql, 299 exp.GenerateDateArray: sequence_sql, 300 exp.If: if_sql(), 301 exp.ILike: no_ilike_sql, 302 exp.IntDiv: lambda self, e: self.binary(e, "DIV"), 303 exp.IsNan: rename_func("ISNAN"), 304 exp.JSONExtract: lambda self, e: self.func("GET_JSON_OBJECT", e.this, e.expression), 305 exp.JSONExtractScalar: lambda self, e: self.func("GET_JSON_OBJECT", e.this, e.expression), 306 exp.JSONFormat: rename_func("TO_JSON"), 307 exp.Left: left_to_substring_sql, 308 exp.Map: var_map_sql, 309 exp.Max: max_or_greatest, 310 exp.MD5Digest: lambda self, e: self.func("UNHEX", self.func("MD5", e.this)), 311 exp.Min: min_or_least, 312 exp.MonthsBetween: lambda self, e: self.func("MONTHS_BETWEEN", e.this, e.expression), 313 exp.NotNullColumnConstraint: lambda _, e: "" if e.args.get("allow_null") else "NOT NULL", 314 exp.VarMap: var_map_sql, 315 exp.Create: preprocess( 316 [ 317 remove_unique_constraints, 318 ctas_with_tmp_tables_to_create_tmp_view, 319 move_schema_columns_to_partitioned_by, 320 ] 321 ), 322 exp.Quantile: rename_func("PERCENTILE"), 323 exp.ApproxQuantile: rename_func("PERCENTILE_APPROX"), 324 exp.RegexpExtract: regexp_extract_sql, 325 exp.RegexpExtractAll: regexp_extract_sql, 326 exp.RegexpReplace: regexp_replace_sql, 327 exp.RegexpLike: lambda self, e: self.binary(e, "RLIKE"), 328 exp.RegexpSplit: rename_func("SPLIT"), 329 exp.Right: right_to_substring_sql, 330 exp.SchemaCommentProperty: lambda self, e: self.naked_property(e), 331 exp.ArrayUniqueAgg: rename_func("COLLECT_SET"), 332 exp.Split: lambda self, e: self.func( 333 "SPLIT", e.this, self.func("CONCAT", "'\\\\Q'", e.expression, "'\\\\E'") 334 ), 335 exp.Select: transforms.preprocess( 336 [ 337 transforms.eliminate_qualify, 338 transforms.eliminate_distinct_on, 339 partial(transforms.unnest_to_explode, unnest_using_arrays_zip=False), 340 transforms.any_to_exists, 341 ] 342 ), 343 exp.StrPosition: lambda self, e: strposition_sql( 344 self, e, func_name="LOCATE", supports_position=True 345 ), 346 exp.StrToDate: _str_to_date_sql, 347 exp.StrToTime: _str_to_time_sql, 348 exp.StrToUnix: _str_to_unix_sql, 349 exp.StructExtract: struct_extract_sql, 350 exp.StarMap: rename_func("MAP"), 351 exp.Table: transforms.preprocess([transforms.unnest_generate_series]), 352 exp.TimeStrToDate: rename_func("TO_DATE"), 353 exp.TimeStrToTime: timestrtotime_sql, 354 exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"), 355 exp.TimestampTrunc: lambda self, e: self.func( 356 "TRUNC", e.this, weekstart_unit_to_str(self, e) 357 ), 358 exp.TimeToUnix: rename_func("UNIX_TIMESTAMP"), 359 exp.ToBase64: rename_func("BASE64"), 360 exp.TsOrDiToDi: lambda self, e: ( 361 f"CAST(SUBSTR(REPLACE(CAST({self.sql(e, 'this')} AS STRING), '-', ''), 1, 8) AS INT)" 362 ), 363 exp.TsOrDsAdd: _add_date_sql, 364 exp.TsOrDsDiff: _date_diff_sql, 365 exp.TsOrDsToDate: _to_date_sql, 366 exp.TryCast: no_trycast_sql, 367 exp.Trim: trim_sql, 368 exp.Unicode: rename_func("ASCII"), 369 exp.UnixToStr: lambda self, e: self.func( 370 "FROM_UNIXTIME", e.this, time_format("hive")(self, e) 371 ), 372 exp.UnixToTime: _unix_to_time_sql, 373 exp.UnixToTimeStr: rename_func("FROM_UNIXTIME"), 374 exp.Unnest: rename_func("EXPLODE"), 375 exp.PartitionedByProperty: lambda self, e: f"PARTITIONED BY {self.sql(e, 'this')}", 376 exp.NumberToStr: rename_func("FORMAT_NUMBER"), 377 exp.National: lambda self, e: self.national_sql(e, prefix=""), 378 exp.ClusteredColumnConstraint: lambda self, e: ( 379 f"({self.expressions(e, 'this', indent=False)})" 380 ), 381 exp.NonClusteredColumnConstraint: lambda self, e: ( 382 f"({self.expressions(e, 'this', indent=False)})" 383 ), 384 exp.NotForReplicationColumnConstraint: lambda *_: "", 385 exp.OnProperty: lambda *_: "", 386 exp.PartitionedByBucket: lambda self, e: self.func("BUCKET", e.expression, e.this), 387 exp.PartitionByTruncate: lambda self, e: self.func("TRUNCATE", e.expression, e.this), 388 exp.PrimaryKeyColumnConstraint: lambda *_: "PRIMARY KEY", 389 exp.WeekOfYear: rename_func("WEEKOFYEAR"), 390 exp.DayOfMonth: rename_func("DAYOFMONTH"), 391 exp.DayOfWeek: rename_func("DAYOFWEEK"), 392 exp.Levenshtein: unsupported_args("ins_cost", "del_cost", "sub_cost", "max_dist")( 393 rename_func("LEVENSHTEIN") 394 ), 395 } 396 397 PROPERTIES_LOCATION = { 398 **generator.Generator.PROPERTIES_LOCATION, 399 exp.FileFormatProperty: exp.Properties.Location.POST_SCHEMA, 400 exp.PartitionedByProperty: exp.Properties.Location.POST_SCHEMA, 401 exp.VolatileProperty: exp.Properties.Location.UNSUPPORTED, 402 exp.WithDataProperty: exp.Properties.Location.UNSUPPORTED, 403 } 404 405 TS_OR_DS_EXPRESSIONS = HIVE_TS_OR_DS_EXPRESSIONS 406 407 IGNORE_NULLS_FUNCS = (exp.First, exp.Last, exp.FirstValue, exp.LastValue) 408 409 def format_time( 410 self, 411 expression: exp.Expr, 412 inverse_time_mapping: dict[str, str] | None = None, 413 inverse_time_trie: dict | None = None, 414 ) -> str | None: 415 # Inferred property because this method is reused by other dialects under Hive 416 is_dialect_strict = self.dialect.TIME_MAPPING.get("MM") == "%mstrict" 417 418 if ( 419 is_dialect_strict 420 and inverse_time_mapping is None 421 and isinstance(expression, PARSE_TIME_EXPRESSIONS) 422 ): 423 # Render a lenient %m/%d non-padded (M/d) so single-digit sources stay parseable 424 return format_time( 425 _lenient_parse_format(self.sql(expression, "format")), 426 self.dialect.INVERSE_TIME_MAPPING, 427 self.dialect.INVERSE_TIME_TRIE, 428 ) 429 430 return super().format_time(expression, inverse_time_mapping, inverse_time_trie) 431 432 def ignorenulls_sql(self, expression: exp.IgnoreNulls) -> str: 433 this = expression.this 434 if isinstance(this, self.IGNORE_NULLS_FUNCS): 435 return self.func(this.sql_name(), this.this, exp.true()) 436 437 return super().ignorenulls_sql(expression) 438 439 def unnest_sql(self, expression: exp.Unnest) -> str: 440 return rename_func("EXPLODE")(self, expression) 441 442 def _jsonpathkey_sql(self, expression: exp.JSONPathKey) -> str: 443 if isinstance(expression.this, exp.JSONPathWildcard): 444 self.unsupported("Unsupported wildcard in JSONPathKey expression") 445 return "" 446 447 return super()._jsonpathkey_sql(expression) 448 449 def parameter_sql(self, expression: exp.Parameter) -> str: 450 this = self.sql(expression, "this") 451 expression_sql = self.sql(expression, "expression") 452 453 parent = expression.parent 454 this = f"{this}:{expression_sql}" if expression_sql else this 455 456 if isinstance(parent, exp.EQ) and isinstance(parent.parent, exp.SetItem): 457 # We need to produce SET key = value instead of SET ${key} = value 458 return this 459 460 return f"${{{this}}}" 461 462 def schema_sql(self, expression: exp.Schema) -> str: 463 for ordered in expression.find_all(exp.Ordered): 464 if ordered.args.get("desc") is False: 465 ordered.set("desc", None) 466 467 return super().schema_sql(expression) 468 469 def constraint_sql(self, expression: exp.Constraint) -> str: 470 for prop in list(expression.find_all(exp.Properties)): 471 prop.pop() 472 473 this = self.sql(expression, "this") 474 expressions = self.expressions(expression, sep=" ", flat=True) 475 return f"CONSTRAINT {this} {expressions}" 476 477 def rowformatserdeproperty_sql(self, expression: exp.RowFormatSerdeProperty) -> str: 478 serde_props = self.sql(expression, "serde_properties") 479 serde_props = f" {serde_props}" if serde_props else "" 480 return f"ROW FORMAT SERDE {self.sql(expression, 'this')}{serde_props}" 481 482 def arrayagg_sql(self, expression: exp.ArrayAgg) -> str: 483 return self.func( 484 "COLLECT_LIST", 485 expression.this.this if isinstance(expression.this, exp.Order) else expression.this, 486 ) 487 488 # Hive/Spark lack native numeric TRUNC. CAST to BIGINT truncates toward zero (not rounds). 489 # Potential enhancement: a TRUNC_TEMPLATE using FLOOR/CEIL with scale (Spark 3.3+) 490 # could preserve decimals: CASE WHEN x >= 0 THEN FLOOR(x, d) ELSE CEIL(x, d) END 491 @unsupported_args("decimals") 492 def trunc_sql(self, expression: exp.Trunc) -> str: 493 return self.sql(exp.cast(expression.this, exp.DType.BIGINT)) 494 495 def datatype_sql(self, expression: exp.DataType) -> str: 496 if expression.this in self.PARAMETERIZABLE_TEXT_TYPES and ( 497 not expression.expressions or expression.expressions[0].name == "MAX" 498 ): 499 expression.set("this", exp.DType.TEXT) 500 expression.set("expressions", None) 501 elif expression.is_type(exp.DType.TEXT) and expression.expressions: 502 expression.set("this", exp.DType.VARCHAR) 503 elif expression.this in exp.DataType.TEMPORAL_TYPES: 504 expression.set("expressions", None) 505 elif expression.is_type("float"): 506 size_expression = expression.find(exp.DataTypeParam) 507 if size_expression: 508 size = int(size_expression.name) 509 expression.set("this", exp.DType.FLOAT if size <= 32 else exp.DType.DOUBLE) 510 expression.set("expressions", None) 511 return super().datatype_sql(expression) 512 513 def version_sql(self, expression: exp.Version) -> str: 514 sql = super().version_sql(expression) 515 return sql.replace("FOR ", "", 1) 516 517 def struct_sql(self, expression: exp.Struct) -> str: 518 values = [] 519 520 for i, e in enumerate(expression.expressions): 521 if isinstance(e, exp.PropertyEQ): 522 self.unsupported("Hive does not support named structs.") 523 values.append(e.expression) 524 else: 525 values.append(e) 526 527 return self.func("STRUCT", *values) 528 529 def columndef_sql(self, expression: exp.ColumnDef, sep: str = " ") -> str: 530 return super().columndef_sql( 531 expression, 532 sep=( 533 ": " 534 if isinstance(expression.parent, exp.DataType) 535 and expression.parent.is_type("struct") 536 else sep 537 ), 538 ) 539 540 def altercolumn_sql(self, expression: exp.AlterColumn) -> str: 541 this = self.sql(expression, "this") 542 new_name = self.sql(expression, "rename_to") or this 543 dtype = self.sql(expression, "dtype") 544 comment = ( 545 f" COMMENT {self.sql(expression, 'comment')}" if self.sql(expression, "comment") else "" 546 ) 547 default = self.sql(expression, "default") 548 visible = expression.args.get("visible") 549 allow_null = expression.args.get("allow_null") 550 drop = expression.args.get("drop") 551 552 if any([default, drop, visible, allow_null, drop]): 553 self.unsupported("Unsupported CHANGE COLUMN syntax") 554 555 if not dtype: 556 self.unsupported("CHANGE COLUMN without a type is not supported") 557 558 return f"CHANGE COLUMN {this} {new_name} {dtype}{comment}" 559 560 def renamecolumn_sql(self, expression: exp.RenameColumn) -> str: 561 self.unsupported("Cannot rename columns without data type defined in Hive") 562 return "" 563 564 def alterset_sql(self, expression: exp.AlterSet) -> str: 565 exprs = self.expressions(expression, flat=True) 566 exprs = f" {exprs}" if exprs else "" 567 location = self.sql(expression, "location") 568 location = f" LOCATION {location}" if location else "" 569 file_format = self.expressions(expression, key="file_format", flat=True, sep=" ") 570 file_format = f" FILEFORMAT {file_format}" if file_format else "" 571 serde = self.sql(expression, "serde") 572 serde = f" SERDE {serde}" if serde else "" 573 tags = self.expressions(expression, key="tag", flat=True, sep="") 574 tags = f" TAGS {tags}" if tags else "" 575 576 return f"SET{serde}{exprs}{location}{file_format}{tags}" 577 578 def serdeproperties_sql(self, expression: exp.SerdeProperties) -> str: 579 prefix = "WITH " if expression.args.get("with_") else "" 580 exprs = self.expressions(expression, flat=True) 581 582 return f"{prefix}SERDEPROPERTIES ({exprs})" 583 584 def exists_sql(self, expression: exp.Exists) -> str: 585 if expression.expression: 586 return self.function_fallback_sql(expression) 587 588 return super().exists_sql(expression) 589 590 def timetostr_sql(self, expression: exp.TimeToStr) -> str: 591 this = expression.this 592 if isinstance(this, exp.TimeStrToTime): 593 this = this.this 594 595 return self.func("DATE_FORMAT", this, self.format_time(expression)) 596 597 def usingproperty_sql(self, expression: exp.UsingProperty) -> str: 598 kind = expression.args.get("kind") 599 return f"USING {kind} {self.sql(expression, 'this')}" 600 601 def fileformatproperty_sql(self, expression: exp.FileFormatProperty) -> str: 602 if isinstance(expression.this, exp.InputOutputFormat): 603 this = self.sql(expression, "this") 604 else: 605 this = expression.name.upper() 606 607 return f"STORED AS {this}"
Generator converts a given syntax tree to the corresponding SQL string.
Arguments:
- pretty: Whether to format the produced SQL string. Default: False.
- identify: Determines when an identifier should be quoted. Possible values are: False (default): Never quote, except in cases where it's mandatory by the dialect. True: Always quote except for specials cases. 'safe': Only quote identifiers that are case insensitive.
- normalize: Whether to normalize identifiers to lowercase. Default: False.
- pad: The pad size in a formatted string. For example, this affects the indentation of a projection in a query, relative to its nesting level. Default: 2.
- indent: The indentation size in a formatted string. For example, this affects the
indentation of subqueries and filters under a
WHEREclause. Default: 2. - normalize_functions: How to normalize function names. Possible values are: "upper" or True (default): Convert names to uppercase. "lower": Convert names to lowercase. False: Disables function name normalization.
- unsupported_level: Determines the generator's behavior when it encounters unsupported expressions. Default ErrorLevel.WARN.
- max_unsupported: Maximum number of unsupported messages to include in a raised UnsupportedError. This is only relevant if unsupported_level is ErrorLevel.RAISE. Default: 3
- leading_comma: Whether the comma is leading or trailing in select expressions. This is only relevant when generating in pretty mode. Default: False
- max_text_width: The max number of characters in a segment before creating new lines in pretty mode. The default is on the smaller end because the length only represents a segment and not the true line length. Default: 80
- comments: Whether to preserve comments in the output SQL code. Default: True
EXPRESSIONS_WITHOUT_NESTED_CTES =
{<class 'sqlglot.expressions.query.SetOperation'>, <class 'sqlglot.expressions.query.Subquery'>, <class 'sqlglot.expressions.query.Select'>, <class 'sqlglot.expressions.dml.Insert'>}
SUPPORTED_JSON_PATH_PARTS =
{<class 'sqlglot.expressions.query.JSONPathKey'>, <class 'sqlglot.expressions.query.JSONPathRoot'>, <class 'sqlglot.expressions.query.JSONPathWildcard'>, <class 'sqlglot.expressions.query.JSONPathSubscript'>}
TYPE_MAPPING =
{<DType.DATETIME2: 'DATETIME2'>: 'TIMESTAMP', <DType.NCHAR: 'NCHAR'>: 'CHAR', <DType.NVARCHAR: 'NVARCHAR'>: 'VARCHAR', <DType.MEDIUMTEXT: 'MEDIUMTEXT'>: 'TEXT', <DType.LONGTEXT: 'LONGTEXT'>: 'TEXT', <DType.TINYTEXT: 'TINYTEXT'>: 'TEXT', <DType.BLOB: 'BLOB'>: 'BINARY', <DType.MEDIUMBLOB: 'MEDIUMBLOB'>: 'BLOB', <DType.LONGBLOB: 'LONGBLOB'>: 'BLOB', <DType.TINYBLOB: 'TINYBLOB'>: 'BLOB', <DType.INET: 'INET'>: 'INET', <DType.ROWVERSION: 'ROWVERSION'>: 'BINARY', <DType.SMALLDATETIME: 'SMALLDATETIME'>: 'TIMESTAMP', <DType.BIT: 'BIT'>: 'BOOLEAN', <DType.DATETIME: 'DATETIME'>: 'TIMESTAMP', <DType.TEXT: 'TEXT'>: 'STRING', <DType.TIME: 'TIME'>: 'TIMESTAMP', <DType.TIMESTAMPNTZ: 'TIMESTAMPNTZ'>: 'TIMESTAMP', <DType.TIMESTAMPTZ: 'TIMESTAMPTZ'>: 'TIMESTAMP', <DType.UTINYINT: 'UTINYINT'>: 'SMALLINT', <DType.VARBINARY: 'VARBINARY'>: 'BINARY'}
TRANSFORMS =
{<class 'sqlglot.expressions.query.JSONPathKey'>: <function <lambda>>, <class 'sqlglot.expressions.query.JSONPathRoot'>: <function <lambda>>, <class 'sqlglot.expressions.query.JSONPathSubscript'>: <function <lambda>>, <class 'sqlglot.expressions.query.JSONPathWildcard'>: <function <lambda>>, <class 'sqlglot.expressions.core.Adjacent'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.AllowedValuesProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.AnalyzeColumns'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.AnalyzeWith'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.array.ArrayContainedBy'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.array.ArrayContainsAll'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.array.ArrayOverlaps'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.AssumeColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.AutoRefreshProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.BackupProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.CaseSpecificColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.CalledOnNullInputProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.math.Ceil'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.CharacterSetColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.CharacterSetProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.ClusteredColumnConstraint'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.constraints.CollateColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.CommentColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.functions.ConnectByRoot'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.string.ConvertToCharset'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.CopyGrantsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.CredentialsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.functions.CurrentCatalog'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.functions.SessionUser'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.DateFormatColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.DefaultColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ApiProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ApplicationProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.CatalogProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ComputeProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.DatabaseProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.DynamicProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.EmptyProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.EncodeColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.EndStatement'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.EnviromentProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.HandlerProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ParameterStyleProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.EphemeralColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.ExcludeColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ExecuteAsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.Except'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ExternalProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.math.Floor'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.Get'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.GlobalProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.HeapProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.HybridProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.IcebergProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.InheritsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.InlineLengthColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.InputModelProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.Intersect'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.datatypes.IntervalSpan'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.functions.Int64'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.json.JSONBContainsAnyTopKeys'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.json.JSONBContainsAllTopKeys'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.json.JSONBDeleteAtPath'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.json.JSONBPathExists'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.json.JSONObject'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.json.JSONObjectAgg'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.LanguageProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.LocationProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.LogProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.MaskingProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.MaterializedProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.functions.NetFunc'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.NetworkProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.NonClusteredColumnConstraint'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.properties.NoPrimaryIndexProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.NotForReplicationColumnConstraint'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.properties.OnCommitProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.OnProperty'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.constraints.OnUpdateColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.core.Operator'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.OutputModelProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.core.ExtendsLeft'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.core.ExtendsRight'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.PathColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.PartitionedByBucket'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.properties.PartitionByTruncate'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.core.PivotAny'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.array.PositionalColumn'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.ProjectionPolicyColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.InvisibleColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.ZeroFillColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.Put'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.RemoteWithConnectionModelProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ReturnsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.RowAccessProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.core.SafeFunc'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SampleProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SecureProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SecurityIntegrationProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SetConfigProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SetProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SettingsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SharingProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SqlReadWriteProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SqlSecurityProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.StabilityProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.Stream'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.StreamingTableProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.StrictProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ddl.SwapTable'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.TableColumn'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.Tags'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.TemporaryProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.TitleColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.array.ToMap'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ToTableProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.TransformModelProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.TransientProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.VirtualProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ddl.TriggerExecute'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.Union'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.UnloggedProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.UsingTemplateProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.UsingData'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.UppercaseColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.temporal.UtcDate'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.temporal.UtcTime'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.temporal.UtcTimestamp'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.Variadic'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.array.VarMap'>: <function var_map_sql>, <class 'sqlglot.expressions.properties.ViewAttributeProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.VolatileProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.WithJournalTableProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.WithProcedureOptions'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.WithSchemaBindingProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.WithOperator'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ForceProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.Property'>: <function property_sql>, <class 'sqlglot.expressions.aggregate.AnyValue'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.core.ApproxDistinct'>: <function approx_count_distinct_sql>, <class 'sqlglot.expressions.aggregate.ArgMax'>: <function arg_max_or_min_no_count.<locals>._arg_max_or_min_sql>, <class 'sqlglot.expressions.aggregate.ArgMin'>: <function arg_max_or_min_no_count.<locals>._arg_max_or_min_sql>, <class 'sqlglot.expressions.array.Array'>: <function preprocess.<locals>._to_sql>, <class 'sqlglot.expressions.array.ArrayConcat'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.array.ArrayToString'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.array.ArraySort'>: <function _array_sort_sql>, <class 'sqlglot.expressions.query.With'>: <function no_recursive_cte_sql>, <class 'sqlglot.expressions.temporal.DateAdd'>: <function _add_date_sql>, <class 'sqlglot.expressions.temporal.DateDiff'>: <function _date_diff_sql>, <class 'sqlglot.expressions.temporal.DateStrToDate'>: <function datestrtodate_sql>, <class 'sqlglot.expressions.temporal.DateSub'>: <function _add_date_sql>, <class 'sqlglot.expressions.temporal.DateToDi'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.DiToDate'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.properties.StorageHandlerProperty'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.string.FromBase64'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.array.GenerateSeries'>: <function sequence_sql>, <class 'sqlglot.expressions.temporal.GenerateDateArray'>: <function sequence_sql>, <class 'sqlglot.expressions.functions.If'>: <function if_sql.<locals>._if_sql>, <class 'sqlglot.expressions.core.ILike'>: <function no_ilike_sql>, <class 'sqlglot.expressions.core.IntDiv'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.math.IsNan'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.json.JSONExtract'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.json.JSONExtractScalar'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.json.JSONFormat'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.string.Left'>: <function left_to_substring_sql>, <class 'sqlglot.expressions.array.Map'>: <function var_map_sql>, <class 'sqlglot.expressions.aggregate.Max'>: <function max_or_greatest>, <class 'sqlglot.expressions.string.MD5Digest'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.aggregate.Min'>: <function min_or_least>, <class 'sqlglot.expressions.temporal.MonthsBetween'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.constraints.NotNullColumnConstraint'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.ddl.Create'>: <function preprocess.<locals>._to_sql>, <class 'sqlglot.expressions.aggregate.Quantile'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.aggregate.ApproxQuantile'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.string.RegexpExtract'>: <function regexp_extract_sql>, <class 'sqlglot.expressions.string.RegexpExtractAll'>: <function regexp_extract_sql>, <class 'sqlglot.expressions.string.RegexpReplace'>: <function regexp_replace_sql>, <class 'sqlglot.expressions.core.RegexpLike'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.string.RegexpSplit'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.string.Right'>: <function right_to_substring_sql>, <class 'sqlglot.expressions.properties.SchemaCommentProperty'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.aggregate.ArrayUniqueAgg'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.string.Split'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.query.Select'>: <function preprocess.<locals>._to_sql>, <class 'sqlglot.expressions.string.StrPosition'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.StrToDate'>: <function _str_to_date_sql>, <class 'sqlglot.expressions.temporal.StrToTime'>: <function _str_to_time_sql>, <class 'sqlglot.expressions.temporal.StrToUnix'>: <function _str_to_unix_sql>, <class 'sqlglot.expressions.array.StructExtract'>: <function struct_extract_sql>, <class 'sqlglot.expressions.array.StarMap'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.query.Table'>: <function preprocess.<locals>._to_sql>, <class 'sqlglot.expressions.temporal.TimeStrToDate'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.temporal.TimeStrToTime'>: <function timestrtotime_sql>, <class 'sqlglot.expressions.temporal.TimeStrToUnix'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.temporal.TimestampTrunc'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.TimeToUnix'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.string.ToBase64'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.temporal.TsOrDiToDi'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.TsOrDsAdd'>: <function _add_date_sql>, <class 'sqlglot.expressions.temporal.TsOrDsDiff'>: <function _date_diff_sql>, <class 'sqlglot.expressions.temporal.TsOrDsToDate'>: <function _to_date_sql>, <class 'sqlglot.expressions.functions.TryCast'>: <function no_trycast_sql>, <class 'sqlglot.expressions.string.Trim'>: <function trim_sql>, <class 'sqlglot.expressions.string.Unicode'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.temporal.UnixToStr'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.UnixToTime'>: <function _unix_to_time_sql>, <class 'sqlglot.expressions.temporal.UnixToTimeStr'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.array.Unnest'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.properties.PartitionedByProperty'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.string.NumberToStr'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.query.National'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.constraints.PrimaryKeyColumnConstraint'>: <function HiveGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.WeekOfYear'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.temporal.DayOfMonth'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.temporal.DayOfWeek'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.string.Levenshtein'>: <function rename_func.<locals>.<lambda>>}
PROPERTIES_LOCATION =
{<class 'sqlglot.expressions.properties.AllowedValuesProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.AlgorithmProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.ApiProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.ApplicationProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.AutoIncrementProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.AutoRefreshProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.BackupProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.BlockCompressionProperty'>: <PropertiesLocation.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.properties.CalledOnNullInputProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.CatalogProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.CharacterSetProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.ChecksumProperty'>: <PropertiesLocation.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.properties.CollateProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.ComputeProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.CopyGrantsProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.query.Cluster'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.ClusteredByProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.ClusterProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.DistributedByProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.DuplicateKeyProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.DataBlocksizeProperty'>: <PropertiesLocation.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.properties.DatabaseProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.DataDeletionProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.DefinerProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.DictRange'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.DictProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.DynamicProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.DistKeyProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.DistStyleProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.EmptyProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.EncodeProperty'>: <PropertiesLocation.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.properties.EngineProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.EnviromentProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.HandlerProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.ParameterStyleProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.ExecuteAsProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.ExternalProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.FallbackProperty'>: <PropertiesLocation.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.properties.FileFormatProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.FreespaceProperty'>: <PropertiesLocation.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.properties.GlobalProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.HeapProperty'>: <PropertiesLocation.POST_WITH: 'POST_WITH'>, <class 'sqlglot.expressions.properties.HybridProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.InheritsProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.IcebergProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.IncludeProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.InputModelProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.IsolatedLoadingProperty'>: <PropertiesLocation.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.properties.JournalProperty'>: <PropertiesLocation.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.properties.LanguageProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.LikeProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.LocationProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.LockProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.LockingProperty'>: <PropertiesLocation.POST_ALIAS: 'POST_ALIAS'>, <class 'sqlglot.expressions.properties.LogProperty'>: <PropertiesLocation.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.properties.MaskingProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.MaterializedProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.MergeBlockRatioProperty'>: <PropertiesLocation.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.properties.ModuleProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.NetworkProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.NoPrimaryIndexProperty'>: <PropertiesLocation.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.properties.OnProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.OnCommitProperty'>: <PropertiesLocation.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.query.Order'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.OutputModelProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.PartitionedByProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.PartitionedOfProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.constraints.PrimaryKey'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.Property'>: <PropertiesLocation.POST_WITH: 'POST_WITH'>, <class 'sqlglot.expressions.properties.RefreshTriggerProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.RemoteWithConnectionModelProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.ReturnsProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.RollupProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.RowAccessProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.RowFormatProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.RowFormatDelimitedProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.RowFormatSerdeProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.SampleProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.SchemaCommentProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.SecureProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.SecurityIntegrationProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.SerdeProperties'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.ddl.Set'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.SettingsProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.SetProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.SetConfigProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.SharingProperty'>: <PropertiesLocation.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.ddl.SequenceProperties'>: <PropertiesLocation.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.ddl.TriggerProperties'>: <PropertiesLocation.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.properties.SortKeyProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.SqlReadWriteProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.SqlSecurityProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.StabilityProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.StorageHandlerProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.StreamingTableProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.StrictProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.Tags'>: <PropertiesLocation.POST_WITH: 'POST_WITH'>, <class 'sqlglot.expressions.properties.TemporaryProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.ToTableProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.TransientProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.TransformModelProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.ddl.MergeTreeTTL'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.UnloggedProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.UsingProperty'>: <PropertiesLocation.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.properties.UsingTemplateProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.ViewAttributeProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.VirtualProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.VolatileProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.WithDataProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.WithJournalTableProperty'>: <PropertiesLocation.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.properties.WithProcedureOptions'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.WithSchemaBindingProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.WithSystemVersioningProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.ForceProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>}
TS_OR_DS_EXPRESSIONS =
(<class 'sqlglot.expressions.temporal.DateDiff'>, <class 'sqlglot.expressions.temporal.Day'>, <class 'sqlglot.expressions.temporal.Month'>, <class 'sqlglot.expressions.temporal.Year'>)
IGNORE_NULLS_FUNCS =
(<class 'sqlglot.expressions.aggregate.First'>, <class 'sqlglot.expressions.aggregate.Last'>, <class 'sqlglot.expressions.aggregate.FirstValue'>, <class 'sqlglot.expressions.aggregate.LastValue'>)
def
format_time( self, expression: sqlglot.expressions.core.Expr, inverse_time_mapping: dict[str, str] | None = None, inverse_time_trie: dict | None = None) -> str | None:
409 def format_time( 410 self, 411 expression: exp.Expr, 412 inverse_time_mapping: dict[str, str] | None = None, 413 inverse_time_trie: dict | None = None, 414 ) -> str | None: 415 # Inferred property because this method is reused by other dialects under Hive 416 is_dialect_strict = self.dialect.TIME_MAPPING.get("MM") == "%mstrict" 417 418 if ( 419 is_dialect_strict 420 and inverse_time_mapping is None 421 and isinstance(expression, PARSE_TIME_EXPRESSIONS) 422 ): 423 # Render a lenient %m/%d non-padded (M/d) so single-digit sources stay parseable 424 return format_time( 425 _lenient_parse_format(self.sql(expression, "format")), 426 self.dialect.INVERSE_TIME_MAPPING, 427 self.dialect.INVERSE_TIME_TRIE, 428 ) 429 430 return super().format_time(expression, inverse_time_mapping, inverse_time_trie)
449 def parameter_sql(self, expression: exp.Parameter) -> str: 450 this = self.sql(expression, "this") 451 expression_sql = self.sql(expression, "expression") 452 453 parent = expression.parent 454 this = f"{this}:{expression_sql}" if expression_sql else this 455 456 if isinstance(parent, exp.EQ) and isinstance(parent.parent, exp.SetItem): 457 # We need to produce SET key = value instead of SET ${key} = value 458 return this 459 460 return f"${{{this}}}"
def
rowformatserdeproperty_sql( self, expression: sqlglot.expressions.properties.RowFormatSerdeProperty) -> str:
@unsupported_args('decimals')
def
trunc_sql(self, expression: sqlglot.expressions.math.Trunc) -> str:
495 def datatype_sql(self, expression: exp.DataType) -> str: 496 if expression.this in self.PARAMETERIZABLE_TEXT_TYPES and ( 497 not expression.expressions or expression.expressions[0].name == "MAX" 498 ): 499 expression.set("this", exp.DType.TEXT) 500 expression.set("expressions", None) 501 elif expression.is_type(exp.DType.TEXT) and expression.expressions: 502 expression.set("this", exp.DType.VARCHAR) 503 elif expression.this in exp.DataType.TEMPORAL_TYPES: 504 expression.set("expressions", None) 505 elif expression.is_type("float"): 506 size_expression = expression.find(exp.DataTypeParam) 507 if size_expression: 508 size = int(size_expression.name) 509 expression.set("this", exp.DType.FLOAT if size <= 32 else exp.DType.DOUBLE) 510 expression.set("expressions", None) 511 return super().datatype_sql(expression)
517 def struct_sql(self, expression: exp.Struct) -> str: 518 values = [] 519 520 for i, e in enumerate(expression.expressions): 521 if isinstance(e, exp.PropertyEQ): 522 self.unsupported("Hive does not support named structs.") 523 values.append(e.expression) 524 else: 525 values.append(e) 526 527 return self.func("STRUCT", *values)
540 def altercolumn_sql(self, expression: exp.AlterColumn) -> str: 541 this = self.sql(expression, "this") 542 new_name = self.sql(expression, "rename_to") or this 543 dtype = self.sql(expression, "dtype") 544 comment = ( 545 f" COMMENT {self.sql(expression, 'comment')}" if self.sql(expression, "comment") else "" 546 ) 547 default = self.sql(expression, "default") 548 visible = expression.args.get("visible") 549 allow_null = expression.args.get("allow_null") 550 drop = expression.args.get("drop") 551 552 if any([default, drop, visible, allow_null, drop]): 553 self.unsupported("Unsupported CHANGE COLUMN syntax") 554 555 if not dtype: 556 self.unsupported("CHANGE COLUMN without a type is not supported") 557 558 return f"CHANGE COLUMN {this} {new_name} {dtype}{comment}"
564 def alterset_sql(self, expression: exp.AlterSet) -> str: 565 exprs = self.expressions(expression, flat=True) 566 exprs = f" {exprs}" if exprs else "" 567 location = self.sql(expression, "location") 568 location = f" LOCATION {location}" if location else "" 569 file_format = self.expressions(expression, key="file_format", flat=True, sep=" ") 570 file_format = f" FILEFORMAT {file_format}" if file_format else "" 571 serde = self.sql(expression, "serde") 572 serde = f" SERDE {serde}" if serde else "" 573 tags = self.expressions(expression, key="tag", flat=True, sep="") 574 tags = f" TAGS {tags}" if tags else "" 575 576 return f"SET{serde}{exprs}{location}{file_format}{tags}"
def
fileformatproperty_sql( self, expression: sqlglot.expressions.properties.FileFormatProperty) -> str:
Inherited Members
- sqlglot.generator.Generator
- Generator
- NULL_ORDERING_SUPPORTED
- WINDOW_FUNCS_WITH_NULL_ORDERING
- IGNORE_NULLS_IN_FUNC
- IGNORE_NULLS_BEFORE_ORDER
- LOCKING_READS_SUPPORTED
- EXCEPT_INTERSECT_SUPPORT_ALL_CLAUSE
- WRAP_DERIVED_VALUES
- CREATE_FUNCTION_RETURN_AS
- MATCHED_BY_SOURCE
- SUPPORTS_MERGE_WHERE
- SINGLE_STRING_INTERVAL
- INTERVAL_ALLOWS_PLURAL_FORM
- AUTO_REFRESH_BARE_INTERVALS
- LIMIT_ONLY_LITERALS
- RENAME_TABLE_WITH_DB
- GROUPINGS_SEP
- INOUT_SEPARATOR
- DIRECTED_JOINS
- QUERY_HINT_SEP
- IS_BOOL_ALLOWED
- DUPLICATE_KEY_UPDATE_WITH_SET
- LIMIT_IS_TOP
- RETURNING_END
- TZ_TO_WITH_TIME_ZONE
- VALUES_AS_TABLE
- ALTER_TABLE_INCLUDE_COLUMN_KEYWORD
- UNNEST_WITH_ORDINALITY
- SEMI_ANTI_JOIN_WITH_SIDE
- COMPUTED_COLUMN_WITH_TYPE
- SUPPORTS_TABLE_COPY
- TABLESAMPLE_REQUIRES_PARENS
- TABLESAMPLE_SIZE_IS_ROWS
- TABLESAMPLE_KEYWORDS
- TABLESAMPLE_SEED_KEYWORD
- HISTORICAL_DATA_POST_ALIAS
- COLLATE_IS_FUNC
- DATA_TYPE_SPECIFIERS_ALLOWED
- ENSURE_BOOLS
- CTE_RECURSIVE_KEYWORD_REQUIRED
- SUPPORTS_SINGLE_ARG_CONCAT
- SUPPORTS_TABLE_ALIAS_COLUMNS
- SUPPORTS_NAMED_CTE_COLUMNS
- UNPIVOT_ALIASES_ARE_IDENTIFIERS
- PIVOT_ALIAS_WITH_AS
- JSON_KEY_VALUE_PAIR_SEP
- INSERT_OVERWRITE
- SUPPORTS_SELECT_INTO
- SUPPORTS_UNLOGGED_TABLES
- SUPPORTS_CREATE_TABLE_LIKE
- SUPPORTS_MODIFY_COLUMN
- SUPPORTS_CHANGE_COLUMN
- LIKE_PROPERTY_INSIDE_SCHEMA
- MULTI_ARG_DISTINCT
- JSON_TYPE_REQUIRED_FOR_EXTRACTION
- JSON_PATH_BRACKETED_KEY_SUPPORTED
- JSON_PATH_KEY_QUOTED_FORCES_BRACKETS
- CAN_IMPLEMENT_ARRAY_ANY
- SUPPORTS_WINDOW_EXCLUDE
- SET_OP_MODIFIERS
- COPY_PARAMS_ARE_WRAPPED
- COPY_PARAMS_EQ_REQUIRED
- COPY_HAS_INTO_KEYWORD
- UNICODE_SUBSTITUTE
- STAR_EXCEPT
- HEX_FUNC
- QUOTE_JSON_PATH
- SUPPORTS_EXPLODING_PROJECTIONS
- ARRAY_CONCAT_IS_VAR_LEN
- SUPPORTS_CONVERT_TIMEZONE
- SUPPORTS_UNIX_SECONDS
- ALTER_SET_WRAPPED
- NORMALIZE_EXTRACT_DATE_PARTS
- ARRAY_SIZE_DIM_REQUIRED
- SUPPORTS_BETWEEN_FLAGS
- SUPPORTS_LIKE_QUANTIFIERS
- MATCH_AGAINST_TABLE_PREFIX
- SET_ASSIGNMENT_REQUIRES_VARIABLE_KEYWORD
- DECLARE_DEFAULT_ASSIGNMENT
- UPDATE_STATEMENT_SUPPORTS_FROM
- STAR_EXCLUDE_REQUIRES_DERIVED_TABLE
- SUPPORTS_DROP_ALTER_ICEBERG_PROPERTY
- UNSUPPORTED_TYPES
- TYPE_PARAM_SETTINGS
- TIME_PART_SINGULARS
- AFTER_HAVING_MODIFIER_TRANSFORMS
- TOKEN_MAPPING
- STRUCT_DELIMITER
- PARAMETER_TOKEN
- NAMED_PLACEHOLDER_TOKEN
- EXPRESSION_PRECEDES_PROPERTIES_CREATABLES
- RESERVED_KEYWORDS
- WITH_SEPARATED_COMMENTS
- EXCLUDE_COMMENTS
- UNWRAPPED_INTERVAL_VALUES
- PARAMETERIZABLE_TEXT_TYPES
- RESPECT_IGNORE_NULLS_UNSUPPORTED_EXPRESSIONS
- SENTINEL_LINE_BREAK
- pretty
- identify
- normalize
- pad
- unsupported_level
- max_unsupported
- leading_comma
- max_text_width
- comments
- dialect
- normalize_functions
- unsupported_messages
- generate
- preprocess
- unsupported
- sep
- seg
- sanitize_comment
- maybe_comment
- wrap
- no_identify
- normalize_func
- indent
- sql
- uncache_sql
- cache_sql
- characterset_sql
- column_parts
- column_sql
- pseudocolumn_sql
- columnposition_sql
- columnconstraint_sql
- computedcolumnconstraint_sql
- autoincrementcolumnconstraint_sql
- compresscolumnconstraint_sql
- generatedasidentitycolumnconstraint_sql
- generatedasrowcolumnconstraint_sql
- periodforsystemtimeconstraint_sql
- notnullcolumnconstraint_sql
- primarykeycolumnconstraint_sql
- uniquecolumnconstraint_sql
- inoutcolumnconstraint_sql
- createable_sql
- create_sql
- sequenceproperties_sql
- triggerproperties_sql
- triggerreferencing_sql
- triggerevent_sql
- clone_sql
- describe_sql
- heredoc_sql
- prepend_ctes
- with_sql
- cte_sql
- tablealias_sql
- bitstring_sql
- hexstring_sql
- bytestring_sql
- unicodestring_sql
- rawstring_sql
- datatypeparam_sql
- datatype_param_bound_limiter
- directory_sql
- delete_sql
- drop_sql
- set_operation
- set_operations
- fetch_sql
- limitoptions_sql
- filter_sql
- hint_sql
- indexparameters_sql
- index_sql
- dynamicidentifier_sql
- identifier_sql
- hex_sql
- lowerhex_sql
- inputoutputformat_sql
- national_sql
- partition_sql
- properties_sql
- root_properties
- properties
- with_properties
- locate_properties
- property_name
- property_sql
- uuidproperty_sql
- likeproperty_sql
- fallbackproperty_sql
- journalproperty_sql
- freespaceproperty_sql
- checksumproperty_sql
- mergeblockratioproperty_sql
- moduleproperty_sql
- datablocksizeproperty_sql
- blockcompressionproperty_sql
- isolatedloadingproperty_sql
- partitionboundspec_sql
- partitionedofproperty_sql
- lockingproperty_sql
- withdataproperty_sql
- withsystemversioningproperty_sql
- insert_sql
- introducer_sql
- kill_sql
- pseudotype_sql
- objectidentifier_sql
- onconflict_sql
- returning_sql
- rowformatdelimitedproperty_sql
- withtablehint_sql
- indextablehint_sql
- historicaldata_sql
- table_parts
- table_sql
- tablefromrows_sql
- tablesample_sql
- pivot_sql
- tuple_sql
- update_sql
- values_sql
- var_sql
- into_sql
- from_sql
- groupingsets_sql
- rollup_sql
- rollupindex_sql
- rollupproperty_sql
- cube_sql
- group_sql
- having_sql
- connect_sql
- prior_sql
- join_sql
- lambda_sql
- lateral_op
- lateral_sql
- limit_sql
- offset_sql
- setitem_sql
- set_sql
- queryband_sql
- pragma_sql
- lock_sql
- literal_sql
- escape_str
- loaddata_sql
- null_sql
- boolean_sql
- booland_sql
- boolor_sql
- order_sql
- withfill_sql
- cluster_sql
- clusterproperty_sql
- distribute_sql
- sort_sql
- ordered_sql
- matchrecognizemeasure_sql
- matchrecognize_sql
- query_modifiers
- options_modifier
- forclause_sql
- queryoption_sql
- offset_limit_modifiers
- after_limit_modifiers
- select_sql
- schema_columns_sql
- star_sql
- sessionparameter_sql
- placeholder_sql
- subquery_sql
- qualify_sql
- prewhere_sql
- where_sql
- window_sql
- partition_by_sql
- windowspec_sql
- withingroup_sql
- between_sql
- bracket_offset_expressions
- bracket_sql
- all_sql
- any_sql
- case_sql
- nextvaluefor_sql
- extract_sql
- trim_sql
- convert_concat_args
- concat_sql
- concatws_sql
- check_sql
- foreignkey_sql
- primarykey_sql
- timeserieskey_sql
- if_sql
- matchagainst_sql
- jsonkeyvalue_sql
- jsonpath_sql
- json_path_part
- formatjson_sql
- formatphrase_sql
- jsonarray_sql
- jsonarrayagg_sql
- jsoncolumndef_sql
- jsonschema_sql
- jsontable_sql
- openjsoncolumndef_sql
- openjson_sql
- in_sql
- in_unnest_op
- interval_sql
- return_sql
- reference_sql
- anonymous_sql
- paren_sql
- neg_sql
- not_sql
- alias_sql
- pivotalias_sql
- aliases_sql
- atindex_sql
- attimezone_sql
- fromtimezone_sql
- fromiso8601date_sql
- fromiso8601timestamp_sql
- fromiso8601timestampnanos_sql
- add_sql
- and_sql
- or_sql
- xor_sql
- connector_sql
- bitwiseand_sql
- bitwiseleftshift_sql
- bitwisenot_sql
- bitwiseor_sql
- bitwiserightshift_sql
- bitwisexor_sql
- cast_sql
- strtotime_sql
- strtodate_sql
- parsedatetime_sql
- currentdate_sql
- collate_sql
- command_sql
- comment_sql
- mergetreettlaction_sql
- mergetreettl_sql
- transaction_sql
- commit_sql
- rollback_sql
- modifycolumn_sql
- alterindex_sql
- alterdiststyle_sql
- altersortkey_sql
- alterrename_sql
- alter_sql
- altersession_sql
- add_column_sql
- droppartition_sql
- dropprimarykey_sql
- addconstraint_sql
- addpartition_sql
- distinct_sql
- respectnulls_sql
- havingmax_sql
- intdiv_sql
- dpipe_sql
- div_sql
- safedivide_sql
- overlaps_sql
- distance_sql
- distancend_sql
- dot_sql
- eq_sql
- propertyeq_sql
- escape_sql
- glob_sql
- gt_sql
- gte_sql
- is_sql
- like_sql
- ilike_sql
- match_sql
- similarto_sql
- lt_sql
- lte_sql
- mod_sql
- mul_sql
- neq_sql
- nullsafeeq_sql
- nullsafeneq_sql
- sub_sql
- trycast_sql
- jsoncast_sql
- try_sql
- log_sql
- use_sql
- binary
- ceil_floor
- function_fallback_sql
- func
- format_args
- too_wide
- expressions
- op_expressions
- naked_property
- tag_sql
- token_sql
- userdefinedfunction_sql
- macrooverloads_sql
- macrooverload_sql
- joinhint_sql
- kwarg_sql
- when_sql
- whens_sql
- merge_sql
- tochar_sql
- tonumber_sql
- dictproperty_sql
- dictrange_sql
- dictsubproperty_sql
- duplicatekeyproperty_sql
- uniquekeyproperty_sql
- distributedbyproperty_sql
- oncluster_sql
- clusteredbyproperty_sql
- anyvalue_sql
- querytransform_sql
- indexconstraintoption_sql
- checkcolumnconstraint_sql
- indexcolumnconstraint_sql
- nvl2_sql
- comprehension_sql
- columnprefix_sql
- opclass_sql
- predict_sql
- generateembedding_sql
- generatetext_sql
- generatetable_sql
- generatebool_sql
- generateint_sql
- generatedouble_sql
- mltranslate_sql
- mlforecast_sql
- aiforecast_sql
- featuresattime_sql
- vectorsearch_sql
- forin_sql
- refresh_sql
- toarray_sql
- tsordstotime_sql
- tsordstotimestamp_sql
- tsordstodatetime_sql
- tsordstodate_sql
- unixdate_sql
- lastday_sql
- dateadd_sql
- arrayany_sql
- partitionrange_sql
- truncatetable_sql
- convert_sql
- copyparameter_sql
- credentials_sql
- copy_sql
- semicolon_sql
- datadeletionproperty_sql
- maskingpolicycolumnconstraint_sql
- gapfill_sql
- scope_resolution
- scoperesolution_sql
- parsejson_sql
- rand_sql
- changes_sql
- pad_sql
- summarize_sql
- explodinggenerateseries_sql
- converttimezone_sql
- json_sql
- jsonvalue_sql
- skipjsoncolumn_sql
- conditionalinsert_sql
- multitableinserts_sql
- oncondition_sql
- jsonextractquote_sql
- jsonexists_sql
- slice_sql
- apply_sql
- grant_sql
- revoke_sql
- grantprivilege_sql
- grantprincipal_sql
- columns_sql
- overlay_sql
- todouble_sql
- string_sql
- median_sql
- overflowtruncatebehavior_sql
- unixseconds_sql
- arraysize_sql
- attach_sql
- detach_sql
- attachoption_sql
- watermarkcolumnconstraint_sql
- encodeproperty_sql
- includeproperty_sql
- xmlelement_sql
- xmlkeyvalueoption_sql
- partitionbyrangeproperty_sql
- partitionbyrangepropertydynamic_sql
- unpivotcolumns_sql
- analyzesample_sql
- analyzestatistics_sql
- analyzehistogram_sql
- analyzedelete_sql
- analyzelistchainedrows_sql
- analyzevalidate_sql
- analyze_sql
- xmltable_sql
- xmlnamespace_sql
- export_sql
- declare_sql
- declareitem_sql
- recursivewithsearch_sql
- parameterizedagg_sql
- anonymousaggfunc_sql
- combinedaggfunc_sql
- combinedparameterizedagg_sql
- show_sql
- install_sql
- get_put_sql
- translatecharacters_sql
- decodecase_sql
- semanticview_sql
- getextract_sql
- datefromunixdate_sql
- space_sql
- buildproperty_sql
- refreshtriggerproperty_sql
- modelattribute_sql
- directorystage_sql
- uuid_sql
- initcap_sql
- localtime_sql
- localtimestamp_sql
- weekstart_name
- weekstart_sql
- chr_sql
- block_sql
- functionspecification_sql
- storedprocedure_sql
- ifblock_sql
- whileblock_sql
- execute_sql
- executesql_sql
- altermodifysqlsecurity_sql
- renameindex_sql