sqlglot.generators.hive
1from __future__ import annotations 2 3import re 4import typing as t 5from functools import partial 6 7from sqlglot import exp, generator, transforms 8from sqlglot.dialects.dialect import ( 9 DATE_ADD_OR_SUB, 10 approx_count_distinct_sql, 11 arg_max_or_min_no_count, 12 datestrtodate_sql, 13 if_sql, 14 left_to_substring_sql, 15 max_or_greatest, 16 min_or_least, 17 no_ilike_sql, 18 no_recursive_cte_sql, 19 no_trycast_sql, 20 regexp_extract_sql, 21 regexp_replace_sql, 22 rename_func, 23 right_to_substring_sql, 24 strposition_sql, 25 struct_extract_sql, 26 time_format, 27 timestrtotime_sql, 28 trim_sql, 29 weekstart_unit_to_str, 30 var_map_sql, 31 sequence_sql, 32 property_sql, 33) 34from sqlglot.transforms import ( 35 remove_unique_constraints, 36 ctas_with_tmp_tables_to_create_tmp_view, 37 preprocess, 38 move_schema_columns_to_partitioned_by, 39) 40from sqlglot.generator import unsupported_args 41from sqlglot.time import format_time 42 43# These constants are duplicated from the Hive dialect class to avoid circular imports. 44# They must be kept in sync with Hive.TIME_FORMAT, Hive.DATE_FORMAT, Hive.DATEINT_FORMAT. 45HIVE_TIME_FORMAT = "'yyyy-MM-dd HH:mm:ss'" 46HIVE_DATE_FORMAT = "'yyyy-MM-dd'" 47HIVE_DATEINT_FORMAT = "'yyyyMMdd'" 48 49# The default formats above, as rendered by the lenient rewrite (non-padded month/day/time) 50HIVE_NON_PADDED_TIME_FORMATS = ("'yyyy-M-d H:m:s'", "'yyyy-M-d'") 51 52# Expressions that parse a string with a format (vs. formatting one, like TimeToStr). 53PARSE_TIME_EXPRESSIONS = (exp.StrToTime, exp.StrToDate, exp.StrToUnix, exp.TsOrDsToDate) 54 55CANONICAL_TIME_FORMAT = re.compile(r"%(?:[mdHIMS]strict|[-:].|.)") 56 57LAX_TO_NON_PADDED_FORMATS = { 58 "%m": "%-m", 59 "%d": "%-d", 60 "%H": "%-H", 61 "%I": "%-I", 62 "%M": "%-M", 63 "%S": "%-S", 64} 65 66 67def _lenient_parse_format(fmt: str) -> str: 68 """ 69 Changes a lax month/day/hour/minute/second in a canonical format to its non-padded form 70 (e.g. %m -> %-m), which java.time parses with or without a leading zero. This is only safe 71 for delimited specifiers, because adjacent fields parse greedily, so e.g. 'yyyyMd' (from 72 '%Y%m%d') can't even parse '20200101'. 73 74 The format is decomposed into specifiers (`formats`) and the interleaved literal text (`parts`). 75 Specifier i sits between parts[i] and parts[i + 1]. A specifier is changed only when its 76 neighbors don't touch a digit run, i.e., neither side is another specifier or a literal digit. 77 At the end, the pieces are zipped back together to produce the rewritten canonical format. 78 """ 79 parts = CANONICAL_TIME_FORMAT.split(fmt) 80 formats = CANONICAL_TIME_FORMAT.findall(fmt) 81 82 for i, fmt_ in enumerate(formats): 83 if fmt_ in LAX_TO_NON_PADDED_FORMATS: 84 left, right = parts[i], parts[i + 1] 85 left_adjacent = (not left and i > 0) or (left and left[-1].isdigit()) 86 right_adjacent = (not right and i < len(formats) - 1) or (right and right[0].isdigit()) 87 if not left_adjacent and not right_adjacent: 88 formats[i] = LAX_TO_NON_PADDED_FORMATS[fmt_] 89 90 return "".join(part + fmt_ for part, fmt_ in zip(parts, formats + [""])) 91 92 93# (FuncType, Multiplier) 94DATE_DELTA_INTERVAL = { 95 "YEAR": ("ADD_MONTHS", 12), 96 "MONTH": ("ADD_MONTHS", 1), 97 "QUARTER": ("ADD_MONTHS", 3), 98 "WEEK": ("DATE_ADD", 7), 99 "DAY": ("DATE_ADD", 1), 100} 101 102TIME_DIFF_FACTOR = { 103 "MILLISECOND": " * 1000", 104 "SECOND": "", 105 "MINUTE": " / 60", 106 "HOUR": " / 3600", 107} 108 109DIFF_MONTH_SWITCH = ("YEAR", "QUARTER", "MONTH") 110 111HIVE_TS_OR_DS_EXPRESSIONS: tuple[type[exp.Expr], ...] = ( 112 exp.DateDiff, 113 exp.Day, 114 exp.Month, 115 exp.Year, 116) 117 118 119def _add_date_sql(self: HiveGenerator, expression: DATE_ADD_OR_SUB) -> str: 120 if isinstance(expression, exp.TsOrDsAdd) and not expression.unit: 121 return self.func("DATE_ADD", expression.this, expression.expression) 122 123 unit = expression.text("unit").upper() 124 func, multiplier = DATE_DELTA_INTERVAL.get(unit, ("DATE_ADD", 1)) 125 126 if isinstance(expression, exp.DateSub): 127 multiplier *= -1 128 129 increment = expression.expression 130 if isinstance(increment, exp.Literal): 131 value = increment.to_py() if increment.is_number else int(increment.name) 132 increment = exp.Literal.number(value * multiplier) 133 elif multiplier != 1: 134 increment *= exp.Literal.number(multiplier) 135 136 return self.func(func, expression.this, increment) 137 138 139def _date_diff_sql(self: HiveGenerator, expression: exp.DateDiff | exp.TsOrDsDiff) -> str: 140 unit = expression.text("unit").upper() 141 142 factor = TIME_DIFF_FACTOR.get(unit) 143 if factor is not None: 144 left = self.sql(expression, "this") 145 right = self.sql(expression, "expression") 146 sec_diff = f"UNIX_TIMESTAMP({left}) - UNIX_TIMESTAMP({right})" 147 return f"({sec_diff}){factor}" if factor else sec_diff 148 149 months_between = unit in DIFF_MONTH_SWITCH 150 sql_func = "MONTHS_BETWEEN" if months_between else "DATEDIFF" 151 _, multiplier = DATE_DELTA_INTERVAL.get(unit, ("", 1)) 152 multiplier_sql = f" / {multiplier}" if multiplier > 1 else "" 153 diff_sql = f"{sql_func}({self.format_args(expression.this, expression.expression)})" 154 155 if months_between or multiplier_sql: 156 # MONTHS_BETWEEN returns a float, so we need to truncate the fractional part. 157 # For the same reason, we want to truncate if there's a divisor present. 158 diff_sql = f"CAST({diff_sql}{multiplier_sql} AS INT)" 159 160 return diff_sql 161 162 163@generator.unsupported_args(("expression", "Hive's SORT_ARRAY does not support a comparator.")) 164def _array_sort_sql(self: HiveGenerator, expression: exp.ArraySort) -> str: 165 return self.func("SORT_ARRAY", expression.this) 166 167 168def _str_to_unix_sql(self: HiveGenerator, expression: exp.StrToUnix) -> str: 169 return self.func("UNIX_TIMESTAMP", expression.this, time_format("hive")(self, expression)) 170 171 172def _unix_to_time_sql(self: HiveGenerator, expression: exp.UnixToTime) -> str: 173 timestamp = self.sql(expression, "this") 174 scale = expression.args.get("scale") 175 if scale in (None, exp.UnixToTime.SECONDS): 176 return rename_func("FROM_UNIXTIME")(self, expression) 177 178 return f"FROM_UNIXTIME({timestamp} / POW(10, {scale}))" 179 180 181def _is_cast_time_format(self: HiveGenerator, expression: exp.Expr, time_format: str) -> bool: 182 """Checks whether CAST subsumes the expression's parse format.""" 183 if time_format in (HIVE_TIME_FORMAT, HIVE_DATE_FORMAT): 184 return True 185 186 if time_format in HIVE_NON_PADDED_TIME_FORMATS: 187 # The base render skips the lenient rewrite: a lax specifier pads back (e.g. %m -> MM), 188 # an explicit non-padded specifier (e.g. %-m) doesn't 189 padded_format = generator.Generator.format_time(self, expression) 190 return padded_format in (HIVE_TIME_FORMAT, HIVE_DATE_FORMAT) 191 192 return False 193 194 195def _str_to_date_sql(self: HiveGenerator, expression: exp.StrToDate) -> str: 196 this = self.sql(expression, "this") 197 time_format = self.format_time(expression) 198 if time_format and not _is_cast_time_format(self, expression, time_format): 199 this = f"FROM_UNIXTIME(UNIX_TIMESTAMP({this}, {time_format}))" 200 return f"CAST({this} AS DATE)" 201 202 203def _str_to_time_sql(self: HiveGenerator, expression: exp.StrToTime) -> str: 204 this = self.sql(expression, "this") 205 time_format = self.format_time(expression) 206 if time_format and not _is_cast_time_format(self, expression, time_format): 207 this = f"FROM_UNIXTIME(UNIX_TIMESTAMP({this}, {time_format}))" 208 return f"CAST({this} AS TIMESTAMP)" 209 210 211def _to_date_sql(self: HiveGenerator, expression: exp.TsOrDsToDate) -> str: 212 time_format = self.format_time(expression) 213 if time_format and not _is_cast_time_format(self, expression, time_format): 214 return self.func("TO_DATE", expression.this, time_format) 215 216 if isinstance(expression.parent, self.TS_OR_DS_EXPRESSIONS): 217 return self.sql(expression, "this") 218 219 return self.func("TO_DATE", expression.this) 220 221 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: t.ClassVar = HIVE_TS_OR_DS_EXPRESSIONS 406 407 IGNORE_NULLS_FUNCS: t.ClassVar = (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 if expression.args.get("exists"): 542 self.unsupported("ALTER COLUMN IF EXISTS is not supported by this dialect") 543 544 this = self.sql(expression, "this") 545 new_name = self.sql(expression, "rename_to") or this 546 dtype = self.sql(expression, "dtype") 547 comment = ( 548 f" COMMENT {self.sql(expression, 'comment')}" if self.sql(expression, "comment") else "" 549 ) 550 default = self.sql(expression, "default") 551 visible = expression.args.get("visible") 552 allow_null = expression.args.get("allow_null") 553 drop = expression.args.get("drop") 554 555 if any([default, drop, visible]) or allow_null is not None: 556 self.unsupported("Unsupported CHANGE COLUMN syntax") 557 558 if not dtype: 559 self.unsupported("CHANGE COLUMN without a type is not supported") 560 561 return f"CHANGE COLUMN {this} {new_name} {dtype}{comment}" 562 563 def renamecolumn_sql(self, expression: exp.RenameColumn) -> str: 564 self.unsupported("Cannot rename columns without data type defined in Hive") 565 return "" 566 567 def alterset_sql(self, expression: exp.AlterSet) -> str: 568 exprs = self.expressions(expression, flat=True) 569 exprs = f" {exprs}" if exprs else "" 570 location = self.sql(expression, "location") 571 location = f" LOCATION {location}" if location else "" 572 file_format = self.expressions(expression, key="file_format", flat=True, sep=" ") 573 file_format = f" FILEFORMAT {file_format}" if file_format else "" 574 serde = self.sql(expression, "serde") 575 serde = f" SERDE {serde}" if serde else "" 576 tags = self.expressions(expression, key="tag", flat=True, sep="") 577 tags = f" TAGS {tags}" if tags else "" 578 579 return f"SET{serde}{exprs}{location}{file_format}{tags}" 580 581 def serdeproperties_sql(self, expression: exp.SerdeProperties) -> str: 582 prefix = "WITH " if expression.args.get("with_") else "" 583 exprs = self.expressions(expression, flat=True) 584 585 return f"{prefix}SERDEPROPERTIES ({exprs})" 586 587 def exists_sql(self, expression: exp.Exists) -> str: 588 if expression.expression: 589 return self.function_fallback_sql(expression) 590 591 return super().exists_sql(expression) 592 593 def timetostr_sql(self, expression: exp.TimeToStr) -> str: 594 this = expression.this 595 if isinstance(this, exp.TimeStrToTime): 596 this = this.this 597 598 return self.func("DATE_FORMAT", this, self.format_time(expression)) 599 600 def usingproperty_sql(self, expression: exp.UsingProperty) -> str: 601 kind = expression.args.get("kind") 602 return f"USING {kind} {self.sql(expression, 'this')}" 603 604 def fileformatproperty_sql(self, expression: exp.FileFormatProperty) -> str: 605 if isinstance(expression.this, exp.InputOutputFormat): 606 this = self.sql(expression, "this") 607 else: 608 this = expression.name.upper() 609 610 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'>)
223class HiveGenerator(generator.Generator): 224 SELECT_KINDS: tuple[str, ...] = () 225 TRY_SUPPORTED = False 226 SUPPORTS_UESCAPE = False 227 SUPPORTS_DECODE_CASE = False 228 LIMIT_FETCH = "LIMIT" 229 TABLESAMPLE_WITH_METHOD = False 230 JOIN_HINTS = False 231 TABLE_HINTS = False 232 QUERY_HINTS = False 233 INDEX_ON = "ON TABLE" 234 EXTRACT_ALLOWS_QUOTES = False 235 NVL2_SUPPORTED = False 236 LAST_DAY_SUPPORTS_DATE_PART = False 237 JSON_PATH_SINGLE_QUOTE_ESCAPE = True 238 SAFE_JSON_PATH_KEY_RE = re.compile(r"^[_\-a-zA-Z][\-\w]*$") 239 SUPPORTS_TO_NUMBER = False 240 WITH_PROPERTIES_PREFIX = "TBLPROPERTIES" 241 PARSE_JSON_NAME: str | None = "PARSE_JSON" 242 PAD_FILL_PATTERN_IS_REQUIRED = True 243 SUPPORTS_MEDIAN = False 244 ARRAY_SIZE_NAME = "SIZE" 245 ALTER_SET_TYPE = "" 246 247 EXPRESSIONS_WITHOUT_NESTED_CTES = { 248 exp.Insert, 249 exp.Select, 250 exp.Subquery, 251 exp.SetOperation, 252 } 253 254 SUPPORTED_JSON_PATH_PARTS = { 255 exp.JSONPathKey, 256 exp.JSONPathRoot, 257 exp.JSONPathSubscript, 258 exp.JSONPathWildcard, 259 } 260 261 TYPE_MAPPING = { 262 **generator.Generator.TYPE_MAPPING, 263 exp.DType.BIT: "BOOLEAN", 264 exp.DType.BLOB: "BINARY", 265 exp.DType.DATETIME: "TIMESTAMP", 266 exp.DType.ROWVERSION: "BINARY", 267 exp.DType.TEXT: "STRING", 268 exp.DType.TIME: "TIMESTAMP", 269 exp.DType.TIMESTAMPNTZ: "TIMESTAMP", 270 exp.DType.TIMESTAMPTZ: "TIMESTAMP", 271 exp.DType.UTINYINT: "SMALLINT", 272 exp.DType.VARBINARY: "BINARY", 273 } 274 275 TRANSFORMS = { 276 **generator.Generator.TRANSFORMS, 277 exp.Property: property_sql, 278 exp.AnyValue: rename_func("FIRST"), 279 exp.ApproxDistinct: approx_count_distinct_sql, 280 exp.ArgMax: arg_max_or_min_no_count("MAX_BY"), 281 exp.ArgMin: arg_max_or_min_no_count("MIN_BY"), 282 exp.Array: transforms.preprocess([transforms.inherit_struct_field_names]), 283 exp.ArrayConcat: rename_func("CONCAT"), 284 exp.ArrayToString: lambda self, e: self.func("CONCAT_WS", e.expression, e.this), 285 exp.ArraySort: _array_sort_sql, 286 exp.With: no_recursive_cte_sql, 287 exp.DateAdd: _add_date_sql, 288 exp.DateDiff: _date_diff_sql, 289 exp.DateStrToDate: datestrtodate_sql, 290 exp.DateSub: _add_date_sql, 291 exp.DateToDi: lambda self, e: ( 292 f"CAST(DATE_FORMAT({self.sql(e, 'this')}, {HIVE_DATEINT_FORMAT}) AS INT)" 293 ), 294 exp.DiToDate: lambda self, e: ( 295 f"TO_DATE(CAST({self.sql(e, 'this')} AS STRING), {HIVE_DATEINT_FORMAT})" 296 ), 297 exp.StorageHandlerProperty: lambda self, e: f"STORED BY {self.sql(e, 'this')}", 298 exp.FromBase64: rename_func("UNBASE64"), 299 exp.GenerateSeries: sequence_sql, 300 exp.GenerateDateArray: sequence_sql, 301 exp.If: if_sql(), 302 exp.ILike: no_ilike_sql, 303 exp.IntDiv: lambda self, e: self.binary(e, "DIV"), 304 exp.IsNan: rename_func("ISNAN"), 305 exp.JSONExtract: lambda self, e: self.func("GET_JSON_OBJECT", e.this, e.expression), 306 exp.JSONExtractScalar: lambda self, e: self.func("GET_JSON_OBJECT", e.this, e.expression), 307 exp.JSONFormat: rename_func("TO_JSON"), 308 exp.Left: left_to_substring_sql, 309 exp.Map: var_map_sql, 310 exp.Max: max_or_greatest, 311 exp.MD5Digest: lambda self, e: self.func("UNHEX", self.func("MD5", e.this)), 312 exp.Min: min_or_least, 313 exp.MonthsBetween: lambda self, e: self.func("MONTHS_BETWEEN", e.this, e.expression), 314 exp.NotNullColumnConstraint: lambda _, e: "" if e.args.get("allow_null") else "NOT NULL", 315 exp.VarMap: var_map_sql, 316 exp.Create: preprocess( 317 [ 318 remove_unique_constraints, 319 ctas_with_tmp_tables_to_create_tmp_view, 320 move_schema_columns_to_partitioned_by, 321 ] 322 ), 323 exp.Quantile: rename_func("PERCENTILE"), 324 exp.ApproxQuantile: rename_func("PERCENTILE_APPROX"), 325 exp.RegexpExtract: regexp_extract_sql, 326 exp.RegexpExtractAll: regexp_extract_sql, 327 exp.RegexpReplace: regexp_replace_sql, 328 exp.RegexpLike: lambda self, e: self.binary(e, "RLIKE"), 329 exp.RegexpSplit: rename_func("SPLIT"), 330 exp.Right: right_to_substring_sql, 331 exp.SchemaCommentProperty: lambda self, e: self.naked_property(e), 332 exp.ArrayUniqueAgg: rename_func("COLLECT_SET"), 333 exp.Split: lambda self, e: self.func( 334 "SPLIT", e.this, self.func("CONCAT", "'\\\\Q'", e.expression, "'\\\\E'") 335 ), 336 exp.Select: transforms.preprocess( 337 [ 338 transforms.eliminate_qualify, 339 transforms.eliminate_distinct_on, 340 partial(transforms.unnest_to_explode, unnest_using_arrays_zip=False), 341 transforms.any_to_exists, 342 ] 343 ), 344 exp.StrPosition: lambda self, e: strposition_sql( 345 self, e, func_name="LOCATE", supports_position=True 346 ), 347 exp.StrToDate: _str_to_date_sql, 348 exp.StrToTime: _str_to_time_sql, 349 exp.StrToUnix: _str_to_unix_sql, 350 exp.StructExtract: struct_extract_sql, 351 exp.StarMap: rename_func("MAP"), 352 exp.Table: transforms.preprocess([transforms.unnest_generate_series]), 353 exp.TimeStrToDate: rename_func("TO_DATE"), 354 exp.TimeStrToTime: timestrtotime_sql, 355 exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"), 356 exp.TimestampTrunc: lambda self, e: self.func( 357 "TRUNC", e.this, weekstart_unit_to_str(self, e) 358 ), 359 exp.TimeToUnix: rename_func("UNIX_TIMESTAMP"), 360 exp.ToBase64: rename_func("BASE64"), 361 exp.TsOrDiToDi: lambda self, e: ( 362 f"CAST(SUBSTR(REPLACE(CAST({self.sql(e, 'this')} AS STRING), '-', ''), 1, 8) AS INT)" 363 ), 364 exp.TsOrDsAdd: _add_date_sql, 365 exp.TsOrDsDiff: _date_diff_sql, 366 exp.TsOrDsToDate: _to_date_sql, 367 exp.TryCast: no_trycast_sql, 368 exp.Trim: trim_sql, 369 exp.Unicode: rename_func("ASCII"), 370 exp.UnixToStr: lambda self, e: self.func( 371 "FROM_UNIXTIME", e.this, time_format("hive")(self, e) 372 ), 373 exp.UnixToTime: _unix_to_time_sql, 374 exp.UnixToTimeStr: rename_func("FROM_UNIXTIME"), 375 exp.Unnest: rename_func("EXPLODE"), 376 exp.PartitionedByProperty: lambda self, e: f"PARTITIONED BY {self.sql(e, 'this')}", 377 exp.NumberToStr: rename_func("FORMAT_NUMBER"), 378 exp.National: lambda self, e: self.national_sql(e, prefix=""), 379 exp.ClusteredColumnConstraint: lambda self, e: ( 380 f"({self.expressions(e, 'this', indent=False)})" 381 ), 382 exp.NonClusteredColumnConstraint: lambda self, e: ( 383 f"({self.expressions(e, 'this', indent=False)})" 384 ), 385 exp.NotForReplicationColumnConstraint: lambda *_: "", 386 exp.OnProperty: lambda *_: "", 387 exp.PartitionedByBucket: lambda self, e: self.func("BUCKET", e.expression, e.this), 388 exp.PartitionByTruncate: lambda self, e: self.func("TRUNCATE", e.expression, e.this), 389 exp.PrimaryKeyColumnConstraint: lambda *_: "PRIMARY KEY", 390 exp.WeekOfYear: rename_func("WEEKOFYEAR"), 391 exp.DayOfMonth: rename_func("DAYOFMONTH"), 392 exp.DayOfWeek: rename_func("DAYOFWEEK"), 393 exp.Levenshtein: unsupported_args("ins_cost", "del_cost", "sub_cost", "max_dist")( 394 rename_func("LEVENSHTEIN") 395 ), 396 } 397 398 PROPERTIES_LOCATION = { 399 **generator.Generator.PROPERTIES_LOCATION, 400 exp.FileFormatProperty: exp.Properties.Location.POST_SCHEMA, 401 exp.PartitionedByProperty: exp.Properties.Location.POST_SCHEMA, 402 exp.VolatileProperty: exp.Properties.Location.UNSUPPORTED, 403 exp.WithDataProperty: exp.Properties.Location.UNSUPPORTED, 404 } 405 406 TS_OR_DS_EXPRESSIONS: t.ClassVar = HIVE_TS_OR_DS_EXPRESSIONS 407 408 IGNORE_NULLS_FUNCS: t.ClassVar = (exp.First, exp.Last, exp.FirstValue, exp.LastValue) 409 410 def format_time( 411 self, 412 expression: exp.Expr, 413 inverse_time_mapping: dict[str, str] | None = None, 414 inverse_time_trie: dict | None = None, 415 ) -> str | None: 416 # Inferred property because this method is reused by other dialects under Hive 417 is_dialect_strict = self.dialect.TIME_MAPPING.get("MM") == "%mstrict" 418 419 if ( 420 is_dialect_strict 421 and inverse_time_mapping is None 422 and isinstance(expression, PARSE_TIME_EXPRESSIONS) 423 ): 424 # Render a lenient %m/%d non-padded (M/d) so single-digit sources stay parseable 425 return format_time( 426 _lenient_parse_format(self.sql(expression, "format")), 427 self.dialect.INVERSE_TIME_MAPPING, 428 self.dialect.INVERSE_TIME_TRIE, 429 ) 430 431 return super().format_time(expression, inverse_time_mapping, inverse_time_trie) 432 433 def ignorenulls_sql(self, expression: exp.IgnoreNulls) -> str: 434 this = expression.this 435 if isinstance(this, self.IGNORE_NULLS_FUNCS): 436 return self.func(this.sql_name(), this.this, exp.true()) 437 438 return super().ignorenulls_sql(expression) 439 440 def unnest_sql(self, expression: exp.Unnest) -> str: 441 return rename_func("EXPLODE")(self, expression) 442 443 def _jsonpathkey_sql(self, expression: exp.JSONPathKey) -> str: 444 if isinstance(expression.this, exp.JSONPathWildcard): 445 self.unsupported("Unsupported wildcard in JSONPathKey expression") 446 return "" 447 448 return super()._jsonpathkey_sql(expression) 449 450 def parameter_sql(self, expression: exp.Parameter) -> str: 451 this = self.sql(expression, "this") 452 expression_sql = self.sql(expression, "expression") 453 454 parent = expression.parent 455 this = f"{this}:{expression_sql}" if expression_sql else this 456 457 if isinstance(parent, exp.EQ) and isinstance(parent.parent, exp.SetItem): 458 # We need to produce SET key = value instead of SET ${key} = value 459 return this 460 461 return f"${{{this}}}" 462 463 def schema_sql(self, expression: exp.Schema) -> str: 464 for ordered in expression.find_all(exp.Ordered): 465 if ordered.args.get("desc") is False: 466 ordered.set("desc", None) 467 468 return super().schema_sql(expression) 469 470 def constraint_sql(self, expression: exp.Constraint) -> str: 471 for prop in list(expression.find_all(exp.Properties)): 472 prop.pop() 473 474 this = self.sql(expression, "this") 475 expressions = self.expressions(expression, sep=" ", flat=True) 476 return f"CONSTRAINT {this} {expressions}" 477 478 def rowformatserdeproperty_sql(self, expression: exp.RowFormatSerdeProperty) -> str: 479 serde_props = self.sql(expression, "serde_properties") 480 serde_props = f" {serde_props}" if serde_props else "" 481 return f"ROW FORMAT SERDE {self.sql(expression, 'this')}{serde_props}" 482 483 def arrayagg_sql(self, expression: exp.ArrayAgg) -> str: 484 return self.func( 485 "COLLECT_LIST", 486 expression.this.this if isinstance(expression.this, exp.Order) else expression.this, 487 ) 488 489 # Hive/Spark lack native numeric TRUNC. CAST to BIGINT truncates toward zero (not rounds). 490 # Potential enhancement: a TRUNC_TEMPLATE using FLOOR/CEIL with scale (Spark 3.3+) 491 # could preserve decimals: CASE WHEN x >= 0 THEN FLOOR(x, d) ELSE CEIL(x, d) END 492 @unsupported_args("decimals") 493 def trunc_sql(self, expression: exp.Trunc) -> str: 494 return self.sql(exp.cast(expression.this, exp.DType.BIGINT)) 495 496 def datatype_sql(self, expression: exp.DataType) -> str: 497 if expression.this in self.PARAMETERIZABLE_TEXT_TYPES and ( 498 not expression.expressions or expression.expressions[0].name == "MAX" 499 ): 500 expression.set("this", exp.DType.TEXT) 501 expression.set("expressions", None) 502 elif expression.is_type(exp.DType.TEXT) and expression.expressions: 503 expression.set("this", exp.DType.VARCHAR) 504 elif expression.this in exp.DataType.TEMPORAL_TYPES: 505 expression.set("expressions", None) 506 elif expression.is_type("float"): 507 size_expression = expression.find(exp.DataTypeParam) 508 if size_expression: 509 size = int(size_expression.name) 510 expression.set("this", exp.DType.FLOAT if size <= 32 else exp.DType.DOUBLE) 511 expression.set("expressions", None) 512 return super().datatype_sql(expression) 513 514 def version_sql(self, expression: exp.Version) -> str: 515 sql = super().version_sql(expression) 516 return sql.replace("FOR ", "", 1) 517 518 def struct_sql(self, expression: exp.Struct) -> str: 519 values = [] 520 521 for i, e in enumerate(expression.expressions): 522 if isinstance(e, exp.PropertyEQ): 523 self.unsupported("Hive does not support named structs.") 524 values.append(e.expression) 525 else: 526 values.append(e) 527 528 return self.func("STRUCT", *values) 529 530 def columndef_sql(self, expression: exp.ColumnDef, sep: str = " ") -> str: 531 return super().columndef_sql( 532 expression, 533 sep=( 534 ": " 535 if isinstance(expression.parent, exp.DataType) 536 and expression.parent.is_type("struct") 537 else sep 538 ), 539 ) 540 541 def altercolumn_sql(self, expression: exp.AlterColumn) -> str: 542 if expression.args.get("exists"): 543 self.unsupported("ALTER COLUMN IF EXISTS is not supported by this dialect") 544 545 this = self.sql(expression, "this") 546 new_name = self.sql(expression, "rename_to") or this 547 dtype = self.sql(expression, "dtype") 548 comment = ( 549 f" COMMENT {self.sql(expression, 'comment')}" if self.sql(expression, "comment") else "" 550 ) 551 default = self.sql(expression, "default") 552 visible = expression.args.get("visible") 553 allow_null = expression.args.get("allow_null") 554 drop = expression.args.get("drop") 555 556 if any([default, drop, visible]) or allow_null is not None: 557 self.unsupported("Unsupported CHANGE COLUMN syntax") 558 559 if not dtype: 560 self.unsupported("CHANGE COLUMN without a type is not supported") 561 562 return f"CHANGE COLUMN {this} {new_name} {dtype}{comment}" 563 564 def renamecolumn_sql(self, expression: exp.RenameColumn) -> str: 565 self.unsupported("Cannot rename columns without data type defined in Hive") 566 return "" 567 568 def alterset_sql(self, expression: exp.AlterSet) -> str: 569 exprs = self.expressions(expression, flat=True) 570 exprs = f" {exprs}" if exprs else "" 571 location = self.sql(expression, "location") 572 location = f" LOCATION {location}" if location else "" 573 file_format = self.expressions(expression, key="file_format", flat=True, sep=" ") 574 file_format = f" FILEFORMAT {file_format}" if file_format else "" 575 serde = self.sql(expression, "serde") 576 serde = f" SERDE {serde}" if serde else "" 577 tags = self.expressions(expression, key="tag", flat=True, sep="") 578 tags = f" TAGS {tags}" if tags else "" 579 580 return f"SET{serde}{exprs}{location}{file_format}{tags}" 581 582 def serdeproperties_sql(self, expression: exp.SerdeProperties) -> str: 583 prefix = "WITH " if expression.args.get("with_") else "" 584 exprs = self.expressions(expression, flat=True) 585 586 return f"{prefix}SERDEPROPERTIES ({exprs})" 587 588 def exists_sql(self, expression: exp.Exists) -> str: 589 if expression.expression: 590 return self.function_fallback_sql(expression) 591 592 return super().exists_sql(expression) 593 594 def timetostr_sql(self, expression: exp.TimeToStr) -> str: 595 this = expression.this 596 if isinstance(this, exp.TimeStrToTime): 597 this = this.this 598 599 return self.func("DATE_FORMAT", this, self.format_time(expression)) 600 601 def usingproperty_sql(self, expression: exp.UsingProperty) -> str: 602 kind = expression.args.get("kind") 603 return f"USING {kind} {self.sql(expression, 'this')}" 604 605 def fileformatproperty_sql(self, expression: exp.FileFormatProperty) -> str: 606 if isinstance(expression.this, exp.InputOutputFormat): 607 this = self.sql(expression, "this") 608 else: 609 this = expression.name.upper() 610 611 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.Subquery'>, <class 'sqlglot.expressions.dml.Insert'>, <class 'sqlglot.expressions.query.Select'>, <class 'sqlglot.expressions.query.SetOperation'>}
SUPPORTED_JSON_PATH_PARTS =
{<class 'sqlglot.expressions.query.JSONPathKey'>, <class 'sqlglot.expressions.query.JSONPathWildcard'>, <class 'sqlglot.expressions.query.JSONPathSubscript'>, <class 'sqlglot.expressions.query.JSONPathRoot'>}
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: ClassVar =
(<class 'sqlglot.expressions.temporal.DateDiff'>, <class 'sqlglot.expressions.temporal.Day'>, <class 'sqlglot.expressions.temporal.Month'>, <class 'sqlglot.expressions.temporal.Year'>)
IGNORE_NULLS_FUNCS: ClassVar =
(<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:
410 def format_time( 411 self, 412 expression: exp.Expr, 413 inverse_time_mapping: dict[str, str] | None = None, 414 inverse_time_trie: dict | None = None, 415 ) -> str | None: 416 # Inferred property because this method is reused by other dialects under Hive 417 is_dialect_strict = self.dialect.TIME_MAPPING.get("MM") == "%mstrict" 418 419 if ( 420 is_dialect_strict 421 and inverse_time_mapping is None 422 and isinstance(expression, PARSE_TIME_EXPRESSIONS) 423 ): 424 # Render a lenient %m/%d non-padded (M/d) so single-digit sources stay parseable 425 return format_time( 426 _lenient_parse_format(self.sql(expression, "format")), 427 self.dialect.INVERSE_TIME_MAPPING, 428 self.dialect.INVERSE_TIME_TRIE, 429 ) 430 431 return super().format_time(expression, inverse_time_mapping, inverse_time_trie)
450 def parameter_sql(self, expression: exp.Parameter) -> str: 451 this = self.sql(expression, "this") 452 expression_sql = self.sql(expression, "expression") 453 454 parent = expression.parent 455 this = f"{this}:{expression_sql}" if expression_sql else this 456 457 if isinstance(parent, exp.EQ) and isinstance(parent.parent, exp.SetItem): 458 # We need to produce SET key = value instead of SET ${key} = value 459 return this 460 461 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:
496 def datatype_sql(self, expression: exp.DataType) -> str: 497 if expression.this in self.PARAMETERIZABLE_TEXT_TYPES and ( 498 not expression.expressions or expression.expressions[0].name == "MAX" 499 ): 500 expression.set("this", exp.DType.TEXT) 501 expression.set("expressions", None) 502 elif expression.is_type(exp.DType.TEXT) and expression.expressions: 503 expression.set("this", exp.DType.VARCHAR) 504 elif expression.this in exp.DataType.TEMPORAL_TYPES: 505 expression.set("expressions", None) 506 elif expression.is_type("float"): 507 size_expression = expression.find(exp.DataTypeParam) 508 if size_expression: 509 size = int(size_expression.name) 510 expression.set("this", exp.DType.FLOAT if size <= 32 else exp.DType.DOUBLE) 511 expression.set("expressions", None) 512 return super().datatype_sql(expression)
518 def struct_sql(self, expression: exp.Struct) -> str: 519 values = [] 520 521 for i, e in enumerate(expression.expressions): 522 if isinstance(e, exp.PropertyEQ): 523 self.unsupported("Hive does not support named structs.") 524 values.append(e.expression) 525 else: 526 values.append(e) 527 528 return self.func("STRUCT", *values)
541 def altercolumn_sql(self, expression: exp.AlterColumn) -> str: 542 if expression.args.get("exists"): 543 self.unsupported("ALTER COLUMN IF EXISTS is not supported by this dialect") 544 545 this = self.sql(expression, "this") 546 new_name = self.sql(expression, "rename_to") or this 547 dtype = self.sql(expression, "dtype") 548 comment = ( 549 f" COMMENT {self.sql(expression, 'comment')}" if self.sql(expression, "comment") else "" 550 ) 551 default = self.sql(expression, "default") 552 visible = expression.args.get("visible") 553 allow_null = expression.args.get("allow_null") 554 drop = expression.args.get("drop") 555 556 if any([default, drop, visible]) or allow_null is not None: 557 self.unsupported("Unsupported CHANGE COLUMN syntax") 558 559 if not dtype: 560 self.unsupported("CHANGE COLUMN without a type is not supported") 561 562 return f"CHANGE COLUMN {this} {new_name} {dtype}{comment}"
568 def alterset_sql(self, expression: exp.AlterSet) -> str: 569 exprs = self.expressions(expression, flat=True) 570 exprs = f" {exprs}" if exprs else "" 571 location = self.sql(expression, "location") 572 location = f" LOCATION {location}" if location else "" 573 file_format = self.expressions(expression, key="file_format", flat=True, sep=" ") 574 file_format = f" FILEFORMAT {file_format}" if file_format else "" 575 serde = self.sql(expression, "serde") 576 serde = f" SERDE {serde}" if serde else "" 577 tags = self.expressions(expression, key="tag", flat=True, sep="") 578 tags = f" TAGS {tags}" if tags else "" 579 580 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
- SUPPORTS_ALTER_COLUMN_NULLABILITY
- SUPPORTS_ALTER_COLUMN_IF_EXISTS
- 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
- casestatement_sql
- whileblock_sql
- loopblock_sql
- repeatblock_sql
- leave_sql
- iterate_sql
- execute_sql
- executesql_sql
- altermodifysqlsecurity_sql
- renameindex_sql