From fb7e79eb4c8d6e22b7324de4bb1ea9cd11b8da7c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 7 Apr 2023 14:35:04 +0200 Subject: Merging upstream version 11.5.2. Signed-off-by: Daniel Baumann --- docs/sqlglot/dialects/hive.html | 789 ++++++++++++++++++++-------------------- 1 file changed, 395 insertions(+), 394 deletions(-) (limited to 'docs/sqlglot/dialects/hive.html') diff --git a/docs/sqlglot/dialects/hive.html b/docs/sqlglot/dialects/hive.html index d1b5e63..66a4b7f 100644 --- a/docs/sqlglot/dialects/hive.html +++ b/docs/sqlglot/dialects/hive.html @@ -3,7 +3,7 @@ - + sqlglot.dialects.hive API documentation @@ -341,131 +341,130 @@ 253 "FROM_UNIXTIME": format_time_lambda(exp.UnixToStr, "hive", True), 254 "GET_JSON_OBJECT": exp.JSONExtractScalar.from_arg_list, 255 "LOCATE": locate_to_strposition, -256 "LOG": ( -257 lambda args: exp.Log.from_arg_list(args) -258 if len(args) > 1 -259 else exp.Ln.from_arg_list(args) -260 ), -261 "MAP": parse_var_map, -262 "MONTH": lambda args: exp.Month(this=exp.TsOrDsToDate.from_arg_list(args)), -263 "PERCENTILE": exp.Quantile.from_arg_list, -264 "PERCENTILE_APPROX": exp.ApproxQuantile.from_arg_list, -265 "COLLECT_SET": exp.SetAgg.from_arg_list, -266 "SIZE": exp.ArraySize.from_arg_list, -267 "SPLIT": exp.RegexpSplit.from_arg_list, -268 "TO_DATE": format_time_lambda(exp.TsOrDsToDate, "hive"), -269 "UNIX_TIMESTAMP": format_time_lambda(exp.StrToUnix, "hive", True), -270 "YEAR": lambda args: exp.Year(this=exp.TsOrDsToDate.from_arg_list(args)), -271 } -272 -273 PROPERTY_PARSERS = { -274 **parser.Parser.PROPERTY_PARSERS, # type: ignore -275 "WITH SERDEPROPERTIES": lambda self: exp.SerdeProperties( -276 expressions=self._parse_wrapped_csv(self._parse_property) -277 ), -278 } -279 -280 class Generator(generator.Generator): -281 TYPE_MAPPING = { -282 **generator.Generator.TYPE_MAPPING, # type: ignore -283 exp.DataType.Type.TEXT: "STRING", -284 exp.DataType.Type.DATETIME: "TIMESTAMP", -285 exp.DataType.Type.VARBINARY: "BINARY", -286 exp.DataType.Type.TIMESTAMPTZ: "TIMESTAMP", -287 } -288 -289 TRANSFORMS = { -290 **generator.Generator.TRANSFORMS, # type: ignore -291 **transforms.UNALIAS_GROUP, # type: ignore -292 **transforms.ELIMINATE_QUALIFY, # type: ignore -293 exp.Property: _property_sql, -294 exp.ApproxDistinct: approx_count_distinct_sql, -295 exp.ArrayConcat: rename_func("CONCAT"), -296 exp.ArraySize: rename_func("SIZE"), -297 exp.ArraySort: _array_sort, -298 exp.With: no_recursive_cte_sql, -299 exp.DateAdd: _add_date_sql, -300 exp.DateDiff: _date_diff_sql, -301 exp.DateStrToDate: rename_func("TO_DATE"), -302 exp.DateToDi: lambda self, e: f"CAST(DATE_FORMAT({self.sql(e, 'this')}, {Hive.dateint_format}) AS INT)", -303 exp.DiToDate: lambda self, e: f"TO_DATE(CAST({self.sql(e, 'this')} AS STRING), {Hive.dateint_format})", -304 exp.FileFormatProperty: lambda self, e: f"STORED AS {e.name.upper()}", -305 exp.If: if_sql, -306 exp.Index: _index_sql, -307 exp.ILike: no_ilike_sql, -308 exp.Join: _unnest_to_explode_sql, -309 exp.JSONExtract: rename_func("GET_JSON_OBJECT"), -310 exp.JSONExtractScalar: rename_func("GET_JSON_OBJECT"), -311 exp.Map: var_map_sql, -312 exp.Max: max_or_greatest, -313 exp.Min: min_or_least, -314 exp.VarMap: var_map_sql, -315 exp.Create: create_with_partitions_sql, -316 exp.Quantile: rename_func("PERCENTILE"), -317 exp.ApproxQuantile: rename_func("PERCENTILE_APPROX"), -318 exp.RegexpLike: lambda self, e: self.binary(e, "RLIKE"), -319 exp.RegexpSplit: rename_func("SPLIT"), -320 exp.SafeDivide: no_safe_divide_sql, -321 exp.SchemaCommentProperty: lambda self, e: self.naked_property(e), -322 exp.SetAgg: rename_func("COLLECT_SET"), -323 exp.Split: lambda self, e: f"SPLIT({self.sql(e, 'this')}, CONCAT('\\\\Q', {self.sql(e, 'expression')}))", -324 exp.StrPosition: strposition_to_locate_sql, -325 exp.StrToDate: _str_to_date, -326 exp.StrToTime: _str_to_time, -327 exp.StrToUnix: _str_to_unix, -328 exp.StructExtract: struct_extract_sql, -329 exp.TableFormatProperty: lambda self, e: f"USING {self.sql(e, 'this')}", -330 exp.TimeStrToDate: rename_func("TO_DATE"), -331 exp.TimeStrToTime: timestrtotime_sql, -332 exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"), -333 exp.TimeToStr: _time_to_str, -334 exp.TimeToUnix: rename_func("UNIX_TIMESTAMP"), -335 exp.TsOrDiToDi: lambda self, e: f"CAST(SUBSTR(REPLACE(CAST({self.sql(e, 'this')} AS STRING), '-', ''), 1, 8) AS INT)", -336 exp.TsOrDsAdd: lambda self, e: f"DATE_ADD({self.sql(e, 'this')}, {self.sql(e, 'expression')})", -337 exp.TsOrDsToDate: _to_date_sql, -338 exp.TryCast: no_trycast_sql, -339 exp.UnixToStr: lambda self, e: self.func( -340 "FROM_UNIXTIME", e.this, _time_format(self, e) -341 ), -342 exp.UnixToTime: rename_func("FROM_UNIXTIME"), -343 exp.UnixToTimeStr: rename_func("FROM_UNIXTIME"), -344 exp.PartitionedByProperty: lambda self, e: f"PARTITIONED BY {self.sql(e, 'this')}", -345 exp.RowFormatSerdeProperty: lambda self, e: f"ROW FORMAT SERDE {self.sql(e, 'this')}", -346 exp.SerdeProperties: lambda self, e: self.properties(e, prefix="WITH SERDEPROPERTIES"), -347 exp.NumberToStr: rename_func("FORMAT_NUMBER"), -348 exp.LastDateOfMonth: rename_func("LAST_DAY"), -349 } -350 -351 PROPERTIES_LOCATION = { -352 **generator.Generator.PROPERTIES_LOCATION, # type: ignore -353 exp.FileFormatProperty: exp.Properties.Location.POST_SCHEMA, -354 exp.PartitionedByProperty: exp.Properties.Location.POST_SCHEMA, -355 exp.TableFormatProperty: exp.Properties.Location.POST_SCHEMA, -356 } -357 -358 LIMIT_FETCH = "LIMIT" -359 -360 def arrayagg_sql(self, expression: exp.ArrayAgg) -> str: -361 return self.func( -362 "COLLECT_LIST", -363 expression.this.this if isinstance(expression.this, exp.Order) else expression.this, -364 ) -365 -366 def with_properties(self, properties: exp.Properties) -> str: -367 return self.properties( -368 properties, -369 prefix=self.seg("TBLPROPERTIES"), -370 ) -371 -372 def datatype_sql(self, expression: exp.DataType) -> str: -373 if ( -374 expression.this in (exp.DataType.Type.VARCHAR, exp.DataType.Type.NVARCHAR) -375 and not expression.expressions -376 ): -377 expression = exp.DataType.build("text") -378 elif expression.this in exp.DataType.TEMPORAL_TYPES: -379 expression = exp.DataType.build(expression.this) -380 return super().datatype_sql(expression) +256 "MAP": parse_var_map, +257 "MONTH": lambda args: exp.Month(this=exp.TsOrDsToDate.from_arg_list(args)), +258 "PERCENTILE": exp.Quantile.from_arg_list, +259 "PERCENTILE_APPROX": exp.ApproxQuantile.from_arg_list, +260 "COLLECT_SET": exp.SetAgg.from_arg_list, +261 "SIZE": exp.ArraySize.from_arg_list, +262 "SPLIT": exp.RegexpSplit.from_arg_list, +263 "TO_DATE": format_time_lambda(exp.TsOrDsToDate, "hive"), +264 "TO_JSON": exp.JSONFormat.from_arg_list, +265 "UNIX_TIMESTAMP": format_time_lambda(exp.StrToUnix, "hive", True), +266 "YEAR": lambda args: exp.Year(this=exp.TsOrDsToDate.from_arg_list(args)), +267 } +268 +269 PROPERTY_PARSERS = { +270 **parser.Parser.PROPERTY_PARSERS, # type: ignore +271 "WITH SERDEPROPERTIES": lambda self: exp.SerdeProperties( +272 expressions=self._parse_wrapped_csv(self._parse_property) +273 ), +274 } +275 +276 LOG_DEFAULTS_TO_LN = True +277 +278 class Generator(generator.Generator): +279 TYPE_MAPPING = { +280 **generator.Generator.TYPE_MAPPING, # type: ignore +281 exp.DataType.Type.TEXT: "STRING", +282 exp.DataType.Type.DATETIME: "TIMESTAMP", +283 exp.DataType.Type.VARBINARY: "BINARY", +284 exp.DataType.Type.TIMESTAMPTZ: "TIMESTAMP", +285 } +286 +287 TRANSFORMS = { +288 **generator.Generator.TRANSFORMS, # type: ignore +289 **transforms.UNALIAS_GROUP, # type: ignore +290 **transforms.ELIMINATE_QUALIFY, # type: ignore +291 exp.Property: _property_sql, +292 exp.ApproxDistinct: approx_count_distinct_sql, +293 exp.ArrayConcat: rename_func("CONCAT"), +294 exp.ArraySize: rename_func("SIZE"), +295 exp.ArraySort: _array_sort, +296 exp.With: no_recursive_cte_sql, +297 exp.DateAdd: _add_date_sql, +298 exp.DateDiff: _date_diff_sql, +299 exp.DateStrToDate: rename_func("TO_DATE"), +300 exp.DateToDi: lambda self, e: f"CAST(DATE_FORMAT({self.sql(e, 'this')}, {Hive.dateint_format}) AS INT)", +301 exp.DiToDate: lambda self, e: f"TO_DATE(CAST({self.sql(e, 'this')} AS STRING), {Hive.dateint_format})", +302 exp.FileFormatProperty: lambda self, e: f"STORED AS {e.name.upper()}", +303 exp.If: if_sql, +304 exp.Index: _index_sql, +305 exp.ILike: no_ilike_sql, +306 exp.Join: _unnest_to_explode_sql, +307 exp.JSONExtract: rename_func("GET_JSON_OBJECT"), +308 exp.JSONExtractScalar: rename_func("GET_JSON_OBJECT"), +309 exp.JSONFormat: rename_func("TO_JSON"), +310 exp.Map: var_map_sql, +311 exp.Max: max_or_greatest, +312 exp.Min: min_or_least, +313 exp.VarMap: var_map_sql, +314 exp.Create: create_with_partitions_sql, +315 exp.Quantile: rename_func("PERCENTILE"), +316 exp.ApproxQuantile: rename_func("PERCENTILE_APPROX"), +317 exp.RegexpLike: lambda self, e: self.binary(e, "RLIKE"), +318 exp.RegexpSplit: rename_func("SPLIT"), +319 exp.SafeDivide: no_safe_divide_sql, +320 exp.SchemaCommentProperty: lambda self, e: self.naked_property(e), +321 exp.SetAgg: rename_func("COLLECT_SET"), +322 exp.Split: lambda self, e: f"SPLIT({self.sql(e, 'this')}, CONCAT('\\\\Q', {self.sql(e, 'expression')}))", +323 exp.StrPosition: strposition_to_locate_sql, +324 exp.StrToDate: _str_to_date, +325 exp.StrToTime: _str_to_time, +326 exp.StrToUnix: _str_to_unix, +327 exp.StructExtract: struct_extract_sql, +328 exp.TableFormatProperty: lambda self, e: f"USING {self.sql(e, 'this')}", +329 exp.TimeStrToDate: rename_func("TO_DATE"), +330 exp.TimeStrToTime: timestrtotime_sql, +331 exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"), +332 exp.TimeToStr: _time_to_str, +333 exp.TimeToUnix: rename_func("UNIX_TIMESTAMP"), +334 exp.TsOrDiToDi: lambda self, e: f"CAST(SUBSTR(REPLACE(CAST({self.sql(e, 'this')} AS STRING), '-', ''), 1, 8) AS INT)", +335 exp.TsOrDsAdd: lambda self, e: f"DATE_ADD({self.sql(e, 'this')}, {self.sql(e, 'expression')})", +336 exp.TsOrDsToDate: _to_date_sql, +337 exp.TryCast: no_trycast_sql, +338 exp.UnixToStr: lambda self, e: self.func( +339 "FROM_UNIXTIME", e.this, _time_format(self, e) +340 ), +341 exp.UnixToTime: rename_func("FROM_UNIXTIME"), +342 exp.UnixToTimeStr: rename_func("FROM_UNIXTIME"), +343 exp.PartitionedByProperty: lambda self, e: f"PARTITIONED BY {self.sql(e, 'this')}", +344 exp.RowFormatSerdeProperty: lambda self, e: f"ROW FORMAT SERDE {self.sql(e, 'this')}", +345 exp.SerdeProperties: lambda self, e: self.properties(e, prefix="WITH SERDEPROPERTIES"), +346 exp.NumberToStr: rename_func("FORMAT_NUMBER"), +347 exp.LastDateOfMonth: rename_func("LAST_DAY"), +348 } +349 +350 PROPERTIES_LOCATION = { +351 **generator.Generator.PROPERTIES_LOCATION, # type: ignore +352 exp.FileFormatProperty: exp.Properties.Location.POST_SCHEMA, +353 exp.PartitionedByProperty: exp.Properties.Location.POST_SCHEMA, +354 exp.TableFormatProperty: exp.Properties.Location.POST_SCHEMA, +355 } +356 +357 LIMIT_FETCH = "LIMIT" +358 +359 def arrayagg_sql(self, expression: exp.ArrayAgg) -> str: +360 return self.func( +361 "COLLECT_LIST", +362 expression.this.this if isinstance(expression.this, exp.Order) else expression.this, +363 ) +364 +365 def with_properties(self, properties: exp.Properties) -> str: +366 return self.properties( +367 properties, +368 prefix=self.seg("TBLPROPERTIES"), +369 ) +370 +371 def datatype_sql(self, expression: exp.DataType) -> str: +372 if ( +373 expression.this in (exp.DataType.Type.VARCHAR, exp.DataType.Type.NVARCHAR) +374 and not expression.expressions +375 ): +376 expression = exp.DataType.build("text") +377 elif expression.this in exp.DataType.TEMPORAL_TYPES: +378 expression = exp.DataType.build(expression.this) +379 return super().datatype_sql(expression) @@ -582,131 +581,130 @@ 254 "FROM_UNIXTIME": format_time_lambda(exp.UnixToStr, "hive", True), 255 "GET_JSON_OBJECT": exp.JSONExtractScalar.from_arg_list, 256 "LOCATE": locate_to_strposition, -257 "LOG": ( -258 lambda args: exp.Log.from_arg_list(args) -259 if len(args) > 1 -260 else exp.Ln.from_arg_list(args) -261 ), -262 "MAP": parse_var_map, -263 "MONTH": lambda args: exp.Month(this=exp.TsOrDsToDate.from_arg_list(args)), -264 "PERCENTILE": exp.Quantile.from_arg_list, -265 "PERCENTILE_APPROX": exp.ApproxQuantile.from_arg_list, -266 "COLLECT_SET": exp.SetAgg.from_arg_list, -267 "SIZE": exp.ArraySize.from_arg_list, -268 "SPLIT": exp.RegexpSplit.from_arg_list, -269 "TO_DATE": format_time_lambda(exp.TsOrDsToDate, "hive"), -270 "UNIX_TIMESTAMP": format_time_lambda(exp.StrToUnix, "hive", True), -271 "YEAR": lambda args: exp.Year(this=exp.TsOrDsToDate.from_arg_list(args)), -272 } -273 -274 PROPERTY_PARSERS = { -275 **parser.Parser.PROPERTY_PARSERS, # type: ignore -276 "WITH SERDEPROPERTIES": lambda self: exp.SerdeProperties( -277 expressions=self._parse_wrapped_csv(self._parse_property) -278 ), -279 } -280 -281 class Generator(generator.Generator): -282 TYPE_MAPPING = { -283 **generator.Generator.TYPE_MAPPING, # type: ignore -284 exp.DataType.Type.TEXT: "STRING", -285 exp.DataType.Type.DATETIME: "TIMESTAMP", -286 exp.DataType.Type.VARBINARY: "BINARY", -287 exp.DataType.Type.TIMESTAMPTZ: "TIMESTAMP", -288 } -289 -290 TRANSFORMS = { -291 **generator.Generator.TRANSFORMS, # type: ignore -292 **transforms.UNALIAS_GROUP, # type: ignore -293 **transforms.ELIMINATE_QUALIFY, # type: ignore -294 exp.Property: _property_sql, -295 exp.ApproxDistinct: approx_count_distinct_sql, -296 exp.ArrayConcat: rename_func("CONCAT"), -297 exp.ArraySize: rename_func("SIZE"), -298 exp.ArraySort: _array_sort, -299 exp.With: no_recursive_cte_sql, -300 exp.DateAdd: _add_date_sql, -301 exp.DateDiff: _date_diff_sql, -302 exp.DateStrToDate: rename_func("TO_DATE"), -303 exp.DateToDi: lambda self, e: f"CAST(DATE_FORMAT({self.sql(e, 'this')}, {Hive.dateint_format}) AS INT)", -304 exp.DiToDate: lambda self, e: f"TO_DATE(CAST({self.sql(e, 'this')} AS STRING), {Hive.dateint_format})", -305 exp.FileFormatProperty: lambda self, e: f"STORED AS {e.name.upper()}", -306 exp.If: if_sql, -307 exp.Index: _index_sql, -308 exp.ILike: no_ilike_sql, -309 exp.Join: _unnest_to_explode_sql, -310 exp.JSONExtract: rename_func("GET_JSON_OBJECT"), -311 exp.JSONExtractScalar: rename_func("GET_JSON_OBJECT"), -312 exp.Map: var_map_sql, -313 exp.Max: max_or_greatest, -314 exp.Min: min_or_least, -315 exp.VarMap: var_map_sql, -316 exp.Create: create_with_partitions_sql, -317 exp.Quantile: rename_func("PERCENTILE"), -318 exp.ApproxQuantile: rename_func("PERCENTILE_APPROX"), -319 exp.RegexpLike: lambda self, e: self.binary(e, "RLIKE"), -320 exp.RegexpSplit: rename_func("SPLIT"), -321 exp.SafeDivide: no_safe_divide_sql, -322 exp.SchemaCommentProperty: lambda self, e: self.naked_property(e), -323 exp.SetAgg: rename_func("COLLECT_SET"), -324 exp.Split: lambda self, e: f"SPLIT({self.sql(e, 'this')}, CONCAT('\\\\Q', {self.sql(e, 'expression')}))", -325 exp.StrPosition: strposition_to_locate_sql, -326 exp.StrToDate: _str_to_date, -327 exp.StrToTime: _str_to_time, -328 exp.StrToUnix: _str_to_unix, -329 exp.StructExtract: struct_extract_sql, -330 exp.TableFormatProperty: lambda self, e: f"USING {self.sql(e, 'this')}", -331 exp.TimeStrToDate: rename_func("TO_DATE"), -332 exp.TimeStrToTime: timestrtotime_sql, -333 exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"), -334 exp.TimeToStr: _time_to_str, -335 exp.TimeToUnix: rename_func("UNIX_TIMESTAMP"), -336 exp.TsOrDiToDi: lambda self, e: f"CAST(SUBSTR(REPLACE(CAST({self.sql(e, 'this')} AS STRING), '-', ''), 1, 8) AS INT)", -337 exp.TsOrDsAdd: lambda self, e: f"DATE_ADD({self.sql(e, 'this')}, {self.sql(e, 'expression')})", -338 exp.TsOrDsToDate: _to_date_sql, -339 exp.TryCast: no_trycast_sql, -340 exp.UnixToStr: lambda self, e: self.func( -341 "FROM_UNIXTIME", e.this, _time_format(self, e) -342 ), -343 exp.UnixToTime: rename_func("FROM_UNIXTIME"), -344 exp.UnixToTimeStr: rename_func("FROM_UNIXTIME"), -345 exp.PartitionedByProperty: lambda self, e: f"PARTITIONED BY {self.sql(e, 'this')}", -346 exp.RowFormatSerdeProperty: lambda self, e: f"ROW FORMAT SERDE {self.sql(e, 'this')}", -347 exp.SerdeProperties: lambda self, e: self.properties(e, prefix="WITH SERDEPROPERTIES"), -348 exp.NumberToStr: rename_func("FORMAT_NUMBER"), -349 exp.LastDateOfMonth: rename_func("LAST_DAY"), -350 } -351 -352 PROPERTIES_LOCATION = { -353 **generator.Generator.PROPERTIES_LOCATION, # type: ignore -354 exp.FileFormatProperty: exp.Properties.Location.POST_SCHEMA, -355 exp.PartitionedByProperty: exp.Properties.Location.POST_SCHEMA, -356 exp.TableFormatProperty: exp.Properties.Location.POST_SCHEMA, -357 } -358 -359 LIMIT_FETCH = "LIMIT" -360 -361 def arrayagg_sql(self, expression: exp.ArrayAgg) -> str: -362 return self.func( -363 "COLLECT_LIST", -364 expression.this.this if isinstance(expression.this, exp.Order) else expression.this, -365 ) -366 -367 def with_properties(self, properties: exp.Properties) -> str: -368 return self.properties( -369 properties, -370 prefix=self.seg("TBLPROPERTIES"), -371 ) -372 -373 def datatype_sql(self, expression: exp.DataType) -> str: -374 if ( -375 expression.this in (exp.DataType.Type.VARCHAR, exp.DataType.Type.NVARCHAR) -376 and not expression.expressions -377 ): -378 expression = exp.DataType.build("text") -379 elif expression.this in exp.DataType.TEMPORAL_TYPES: -380 expression = exp.DataType.build(expression.this) -381 return super().datatype_sql(expression) +257 "MAP": parse_var_map, +258 "MONTH": lambda args: exp.Month(this=exp.TsOrDsToDate.from_arg_list(args)), +259 "PERCENTILE": exp.Quantile.from_arg_list, +260 "PERCENTILE_APPROX": exp.ApproxQuantile.from_arg_list, +261 "COLLECT_SET": exp.SetAgg.from_arg_list, +262 "SIZE": exp.ArraySize.from_arg_list, +263 "SPLIT": exp.RegexpSplit.from_arg_list, +264 "TO_DATE": format_time_lambda(exp.TsOrDsToDate, "hive"), +265 "TO_JSON": exp.JSONFormat.from_arg_list, +266 "UNIX_TIMESTAMP": format_time_lambda(exp.StrToUnix, "hive", True), +267 "YEAR": lambda args: exp.Year(this=exp.TsOrDsToDate.from_arg_list(args)), +268 } +269 +270 PROPERTY_PARSERS = { +271 **parser.Parser.PROPERTY_PARSERS, # type: ignore +272 "WITH SERDEPROPERTIES": lambda self: exp.SerdeProperties( +273 expressions=self._parse_wrapped_csv(self._parse_property) +274 ), +275 } +276 +277 LOG_DEFAULTS_TO_LN = True +278 +279 class Generator(generator.Generator): +280 TYPE_MAPPING = { +281 **generator.Generator.TYPE_MAPPING, # type: ignore +282 exp.DataType.Type.TEXT: "STRING", +283 exp.DataType.Type.DATETIME: "TIMESTAMP", +284 exp.DataType.Type.VARBINARY: "BINARY", +285 exp.DataType.Type.TIMESTAMPTZ: "TIMESTAMP", +286 } +287 +288 TRANSFORMS = { +289 **generator.Generator.TRANSFORMS, # type: ignore +290 **transforms.UNALIAS_GROUP, # type: ignore +291 **transforms.ELIMINATE_QUALIFY, # type: ignore +292 exp.Property: _property_sql, +293 exp.ApproxDistinct: approx_count_distinct_sql, +294 exp.ArrayConcat: rename_func("CONCAT"), +295 exp.ArraySize: rename_func("SIZE"), +296 exp.ArraySort: _array_sort, +297 exp.With: no_recursive_cte_sql, +298 exp.DateAdd: _add_date_sql, +299 exp.DateDiff: _date_diff_sql, +300 exp.DateStrToDate: rename_func("TO_DATE"), +301 exp.DateToDi: lambda self, e: f"CAST(DATE_FORMAT({self.sql(e, 'this')}, {Hive.dateint_format}) AS INT)", +302 exp.DiToDate: lambda self, e: f"TO_DATE(CAST({self.sql(e, 'this')} AS STRING), {Hive.dateint_format})", +303 exp.FileFormatProperty: lambda self, e: f"STORED AS {e.name.upper()}", +304 exp.If: if_sql, +305 exp.Index: _index_sql, +306 exp.ILike: no_ilike_sql, +307 exp.Join: _unnest_to_explode_sql, +308 exp.JSONExtract: rename_func("GET_JSON_OBJECT"), +309 exp.JSONExtractScalar: rename_func("GET_JSON_OBJECT"), +310 exp.JSONFormat: rename_func("TO_JSON"), +311 exp.Map: var_map_sql, +312 exp.Max: max_or_greatest, +313 exp.Min: min_or_least, +314 exp.VarMap: var_map_sql, +315 exp.Create: create_with_partitions_sql, +316 exp.Quantile: rename_func("PERCENTILE"), +317 exp.ApproxQuantile: rename_func("PERCENTILE_APPROX"), +318 exp.RegexpLike: lambda self, e: self.binary(e, "RLIKE"), +319 exp.RegexpSplit: rename_func("SPLIT"), +320 exp.SafeDivide: no_safe_divide_sql, +321 exp.SchemaCommentProperty: lambda self, e: self.naked_property(e), +322 exp.SetAgg: rename_func("COLLECT_SET"), +323 exp.Split: lambda self, e: f"SPLIT({self.sql(e, 'this')}, CONCAT('\\\\Q', {self.sql(e, 'expression')}))", +324 exp.StrPosition: strposition_to_locate_sql, +325 exp.StrToDate: _str_to_date, +326 exp.StrToTime: _str_to_time, +327 exp.StrToUnix: _str_to_unix, +328 exp.StructExtract: struct_extract_sql, +329 exp.TableFormatProperty: lambda self, e: f"USING {self.sql(e, 'this')}", +330 exp.TimeStrToDate: rename_func("TO_DATE"), +331 exp.TimeStrToTime: timestrtotime_sql, +332 exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"), +333 exp.TimeToStr: _time_to_str, +334 exp.TimeToUnix: rename_func("UNIX_TIMESTAMP"), +335 exp.TsOrDiToDi: lambda self, e: f"CAST(SUBSTR(REPLACE(CAST({self.sql(e, 'this')} AS STRING), '-', ''), 1, 8) AS INT)", +336 exp.TsOrDsAdd: lambda self, e: f"DATE_ADD({self.sql(e, 'this')}, {self.sql(e, 'expression')})", +337 exp.TsOrDsToDate: _to_date_sql, +338 exp.TryCast: no_trycast_sql, +339 exp.UnixToStr: lambda self, e: self.func( +340 "FROM_UNIXTIME", e.this, _time_format(self, e) +341 ), +342 exp.UnixToTime: rename_func("FROM_UNIXTIME"), +343 exp.UnixToTimeStr: rename_func("FROM_UNIXTIME"), +344 exp.PartitionedByProperty: lambda self, e: f"PARTITIONED BY {self.sql(e, 'this')}", +345 exp.RowFormatSerdeProperty: lambda self, e: f"ROW FORMAT SERDE {self.sql(e, 'this')}", +346 exp.SerdeProperties: lambda self, e: self.properties(e, prefix="WITH SERDEPROPERTIES"), +347 exp.NumberToStr: rename_func("FORMAT_NUMBER"), +348 exp.LastDateOfMonth: rename_func("LAST_DAY"), +349 } +350 +351 PROPERTIES_LOCATION = { +352 **generator.Generator.PROPERTIES_LOCATION, # type: ignore +353 exp.FileFormatProperty: exp.Properties.Location.POST_SCHEMA, +354 exp.PartitionedByProperty: exp.Properties.Location.POST_SCHEMA, +355 exp.TableFormatProperty: exp.Properties.Location.POST_SCHEMA, +356 } +357 +358 LIMIT_FETCH = "LIMIT" +359 +360 def arrayagg_sql(self, expression: exp.ArrayAgg) -> str: +361 return self.func( +362 "COLLECT_LIST", +363 expression.this.this if isinstance(expression.this, exp.Order) else expression.this, +364 ) +365 +366 def with_properties(self, properties: exp.Properties) -> str: +367 return self.properties( +368 properties, +369 prefix=self.seg("TBLPROPERTIES"), +370 ) +371 +372 def datatype_sql(self, expression: exp.DataType) -> str: +373 if ( +374 expression.this in (exp.DataType.Type.VARCHAR, exp.DataType.Type.NVARCHAR) +375 and not expression.expressions +376 ): +377 expression = exp.DataType.build("text") +378 elif expression.this in exp.DataType.TEMPORAL_TYPES: +379 expression = exp.DataType.build(expression.this) +380 return super().datatype_sql(expression) @@ -830,29 +828,27 @@ 254 "FROM_UNIXTIME": format_time_lambda(exp.UnixToStr, "hive", True), 255 "GET_JSON_OBJECT": exp.JSONExtractScalar.from_arg_list, 256 "LOCATE": locate_to_strposition, -257 "LOG": ( -258 lambda args: exp.Log.from_arg_list(args) -259 if len(args) > 1 -260 else exp.Ln.from_arg_list(args) -261 ), -262 "MAP": parse_var_map, -263 "MONTH": lambda args: exp.Month(this=exp.TsOrDsToDate.from_arg_list(args)), -264 "PERCENTILE": exp.Quantile.from_arg_list, -265 "PERCENTILE_APPROX": exp.ApproxQuantile.from_arg_list, -266 "COLLECT_SET": exp.SetAgg.from_arg_list, -267 "SIZE": exp.ArraySize.from_arg_list, -268 "SPLIT": exp.RegexpSplit.from_arg_list, -269 "TO_DATE": format_time_lambda(exp.TsOrDsToDate, "hive"), -270 "UNIX_TIMESTAMP": format_time_lambda(exp.StrToUnix, "hive", True), -271 "YEAR": lambda args: exp.Year(this=exp.TsOrDsToDate.from_arg_list(args)), -272 } -273 -274 PROPERTY_PARSERS = { -275 **parser.Parser.PROPERTY_PARSERS, # type: ignore -276 "WITH SERDEPROPERTIES": lambda self: exp.SerdeProperties( -277 expressions=self._parse_wrapped_csv(self._parse_property) -278 ), -279 } +257 "MAP": parse_var_map, +258 "MONTH": lambda args: exp.Month(this=exp.TsOrDsToDate.from_arg_list(args)), +259 "PERCENTILE": exp.Quantile.from_arg_list, +260 "PERCENTILE_APPROX": exp.ApproxQuantile.from_arg_list, +261 "COLLECT_SET": exp.SetAgg.from_arg_list, +262 "SIZE": exp.ArraySize.from_arg_list, +263 "SPLIT": exp.RegexpSplit.from_arg_list, +264 "TO_DATE": format_time_lambda(exp.TsOrDsToDate, "hive"), +265 "TO_JSON": exp.JSONFormat.from_arg_list, +266 "UNIX_TIMESTAMP": format_time_lambda(exp.StrToUnix, "hive", True), +267 "YEAR": lambda args: exp.Year(this=exp.TsOrDsToDate.from_arg_list(args)), +268 } +269 +270 PROPERTY_PARSERS = { +271 **parser.Parser.PROPERTY_PARSERS, # type: ignore +272 "WITH SERDEPROPERTIES": lambda self: exp.SerdeProperties( +273 expressions=self._parse_wrapped_csv(self._parse_property) +274 ), +275 } +276 +277 LOG_DEFAULTS_TO_LN = True @@ -909,107 +905,108 @@ Default: "nulls_are_small" -
281    class Generator(generator.Generator):
-282        TYPE_MAPPING = {
-283            **generator.Generator.TYPE_MAPPING,  # type: ignore
-284            exp.DataType.Type.TEXT: "STRING",
-285            exp.DataType.Type.DATETIME: "TIMESTAMP",
-286            exp.DataType.Type.VARBINARY: "BINARY",
-287            exp.DataType.Type.TIMESTAMPTZ: "TIMESTAMP",
-288        }
-289
-290        TRANSFORMS = {
-291            **generator.Generator.TRANSFORMS,  # type: ignore
-292            **transforms.UNALIAS_GROUP,  # type: ignore
-293            **transforms.ELIMINATE_QUALIFY,  # type: ignore
-294            exp.Property: _property_sql,
-295            exp.ApproxDistinct: approx_count_distinct_sql,
-296            exp.ArrayConcat: rename_func("CONCAT"),
-297            exp.ArraySize: rename_func("SIZE"),
-298            exp.ArraySort: _array_sort,
-299            exp.With: no_recursive_cte_sql,
-300            exp.DateAdd: _add_date_sql,
-301            exp.DateDiff: _date_diff_sql,
-302            exp.DateStrToDate: rename_func("TO_DATE"),
-303            exp.DateToDi: lambda self, e: f"CAST(DATE_FORMAT({self.sql(e, 'this')}, {Hive.dateint_format}) AS INT)",
-304            exp.DiToDate: lambda self, e: f"TO_DATE(CAST({self.sql(e, 'this')} AS STRING), {Hive.dateint_format})",
-305            exp.FileFormatProperty: lambda self, e: f"STORED AS {e.name.upper()}",
-306            exp.If: if_sql,
-307            exp.Index: _index_sql,
-308            exp.ILike: no_ilike_sql,
-309            exp.Join: _unnest_to_explode_sql,
-310            exp.JSONExtract: rename_func("GET_JSON_OBJECT"),
-311            exp.JSONExtractScalar: rename_func("GET_JSON_OBJECT"),
-312            exp.Map: var_map_sql,
-313            exp.Max: max_or_greatest,
-314            exp.Min: min_or_least,
-315            exp.VarMap: var_map_sql,
-316            exp.Create: create_with_partitions_sql,
-317            exp.Quantile: rename_func("PERCENTILE"),
-318            exp.ApproxQuantile: rename_func("PERCENTILE_APPROX"),
-319            exp.RegexpLike: lambda self, e: self.binary(e, "RLIKE"),
-320            exp.RegexpSplit: rename_func("SPLIT"),
-321            exp.SafeDivide: no_safe_divide_sql,
-322            exp.SchemaCommentProperty: lambda self, e: self.naked_property(e),
-323            exp.SetAgg: rename_func("COLLECT_SET"),
-324            exp.Split: lambda self, e: f"SPLIT({self.sql(e, 'this')}, CONCAT('\\\\Q', {self.sql(e, 'expression')}))",
-325            exp.StrPosition: strposition_to_locate_sql,
-326            exp.StrToDate: _str_to_date,
-327            exp.StrToTime: _str_to_time,
-328            exp.StrToUnix: _str_to_unix,
-329            exp.StructExtract: struct_extract_sql,
-330            exp.TableFormatProperty: lambda self, e: f"USING {self.sql(e, 'this')}",
-331            exp.TimeStrToDate: rename_func("TO_DATE"),
-332            exp.TimeStrToTime: timestrtotime_sql,
-333            exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"),
-334            exp.TimeToStr: _time_to_str,
-335            exp.TimeToUnix: rename_func("UNIX_TIMESTAMP"),
-336            exp.TsOrDiToDi: lambda self, e: f"CAST(SUBSTR(REPLACE(CAST({self.sql(e, 'this')} AS STRING), '-', ''), 1, 8) AS INT)",
-337            exp.TsOrDsAdd: lambda self, e: f"DATE_ADD({self.sql(e, 'this')}, {self.sql(e, 'expression')})",
-338            exp.TsOrDsToDate: _to_date_sql,
-339            exp.TryCast: no_trycast_sql,
-340            exp.UnixToStr: lambda self, e: self.func(
-341                "FROM_UNIXTIME", e.this, _time_format(self, e)
-342            ),
-343            exp.UnixToTime: rename_func("FROM_UNIXTIME"),
-344            exp.UnixToTimeStr: rename_func("FROM_UNIXTIME"),
-345            exp.PartitionedByProperty: lambda self, e: f"PARTITIONED BY {self.sql(e, 'this')}",
-346            exp.RowFormatSerdeProperty: lambda self, e: f"ROW FORMAT SERDE {self.sql(e, 'this')}",
-347            exp.SerdeProperties: lambda self, e: self.properties(e, prefix="WITH SERDEPROPERTIES"),
-348            exp.NumberToStr: rename_func("FORMAT_NUMBER"),
-349            exp.LastDateOfMonth: rename_func("LAST_DAY"),
-350        }
-351
-352        PROPERTIES_LOCATION = {
-353            **generator.Generator.PROPERTIES_LOCATION,  # type: ignore
-354            exp.FileFormatProperty: exp.Properties.Location.POST_SCHEMA,
-355            exp.PartitionedByProperty: exp.Properties.Location.POST_SCHEMA,
-356            exp.TableFormatProperty: exp.Properties.Location.POST_SCHEMA,
-357        }
-358
-359        LIMIT_FETCH = "LIMIT"
-360
-361        def arrayagg_sql(self, expression: exp.ArrayAgg) -> str:
-362            return self.func(
-363                "COLLECT_LIST",
-364                expression.this.this if isinstance(expression.this, exp.Order) else expression.this,
-365            )
-366
-367        def with_properties(self, properties: exp.Properties) -> str:
-368            return self.properties(
-369                properties,
-370                prefix=self.seg("TBLPROPERTIES"),
-371            )
-372
-373        def datatype_sql(self, expression: exp.DataType) -> str:
-374            if (
-375                expression.this in (exp.DataType.Type.VARCHAR, exp.DataType.Type.NVARCHAR)
-376                and not expression.expressions
-377            ):
-378                expression = exp.DataType.build("text")
-379            elif expression.this in exp.DataType.TEMPORAL_TYPES:
-380                expression = exp.DataType.build(expression.this)
-381            return super().datatype_sql(expression)
+            
279    class Generator(generator.Generator):
+280        TYPE_MAPPING = {
+281            **generator.Generator.TYPE_MAPPING,  # type: ignore
+282            exp.DataType.Type.TEXT: "STRING",
+283            exp.DataType.Type.DATETIME: "TIMESTAMP",
+284            exp.DataType.Type.VARBINARY: "BINARY",
+285            exp.DataType.Type.TIMESTAMPTZ: "TIMESTAMP",
+286        }
+287
+288        TRANSFORMS = {
+289            **generator.Generator.TRANSFORMS,  # type: ignore
+290            **transforms.UNALIAS_GROUP,  # type: ignore
+291            **transforms.ELIMINATE_QUALIFY,  # type: ignore
+292            exp.Property: _property_sql,
+293            exp.ApproxDistinct: approx_count_distinct_sql,
+294            exp.ArrayConcat: rename_func("CONCAT"),
+295            exp.ArraySize: rename_func("SIZE"),
+296            exp.ArraySort: _array_sort,
+297            exp.With: no_recursive_cte_sql,
+298            exp.DateAdd: _add_date_sql,
+299            exp.DateDiff: _date_diff_sql,
+300            exp.DateStrToDate: rename_func("TO_DATE"),
+301            exp.DateToDi: lambda self, e: f"CAST(DATE_FORMAT({self.sql(e, 'this')}, {Hive.dateint_format}) AS INT)",
+302            exp.DiToDate: lambda self, e: f"TO_DATE(CAST({self.sql(e, 'this')} AS STRING), {Hive.dateint_format})",
+303            exp.FileFormatProperty: lambda self, e: f"STORED AS {e.name.upper()}",
+304            exp.If: if_sql,
+305            exp.Index: _index_sql,
+306            exp.ILike: no_ilike_sql,
+307            exp.Join: _unnest_to_explode_sql,
+308            exp.JSONExtract: rename_func("GET_JSON_OBJECT"),
+309            exp.JSONExtractScalar: rename_func("GET_JSON_OBJECT"),
+310            exp.JSONFormat: rename_func("TO_JSON"),
+311            exp.Map: var_map_sql,
+312            exp.Max: max_or_greatest,
+313            exp.Min: min_or_least,
+314            exp.VarMap: var_map_sql,
+315            exp.Create: create_with_partitions_sql,
+316            exp.Quantile: rename_func("PERCENTILE"),
+317            exp.ApproxQuantile: rename_func("PERCENTILE_APPROX"),
+318            exp.RegexpLike: lambda self, e: self.binary(e, "RLIKE"),
+319            exp.RegexpSplit: rename_func("SPLIT"),
+320            exp.SafeDivide: no_safe_divide_sql,
+321            exp.SchemaCommentProperty: lambda self, e: self.naked_property(e),
+322            exp.SetAgg: rename_func("COLLECT_SET"),
+323            exp.Split: lambda self, e: f"SPLIT({self.sql(e, 'this')}, CONCAT('\\\\Q', {self.sql(e, 'expression')}))",
+324            exp.StrPosition: strposition_to_locate_sql,
+325            exp.StrToDate: _str_to_date,
+326            exp.StrToTime: _str_to_time,
+327            exp.StrToUnix: _str_to_unix,
+328            exp.StructExtract: struct_extract_sql,
+329            exp.TableFormatProperty: lambda self, e: f"USING {self.sql(e, 'this')}",
+330            exp.TimeStrToDate: rename_func("TO_DATE"),
+331            exp.TimeStrToTime: timestrtotime_sql,
+332            exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"),
+333            exp.TimeToStr: _time_to_str,
+334            exp.TimeToUnix: rename_func("UNIX_TIMESTAMP"),
+335            exp.TsOrDiToDi: lambda self, e: f"CAST(SUBSTR(REPLACE(CAST({self.sql(e, 'this')} AS STRING), '-', ''), 1, 8) AS INT)",
+336            exp.TsOrDsAdd: lambda self, e: f"DATE_ADD({self.sql(e, 'this')}, {self.sql(e, 'expression')})",
+337            exp.TsOrDsToDate: _to_date_sql,
+338            exp.TryCast: no_trycast_sql,
+339            exp.UnixToStr: lambda self, e: self.func(
+340                "FROM_UNIXTIME", e.this, _time_format(self, e)
+341            ),
+342            exp.UnixToTime: rename_func("FROM_UNIXTIME"),
+343            exp.UnixToTimeStr: rename_func("FROM_UNIXTIME"),
+344            exp.PartitionedByProperty: lambda self, e: f"PARTITIONED BY {self.sql(e, 'this')}",
+345            exp.RowFormatSerdeProperty: lambda self, e: f"ROW FORMAT SERDE {self.sql(e, 'this')}",
+346            exp.SerdeProperties: lambda self, e: self.properties(e, prefix="WITH SERDEPROPERTIES"),
+347            exp.NumberToStr: rename_func("FORMAT_NUMBER"),
+348            exp.LastDateOfMonth: rename_func("LAST_DAY"),
+349        }
+350
+351        PROPERTIES_LOCATION = {
+352            **generator.Generator.PROPERTIES_LOCATION,  # type: ignore
+353            exp.FileFormatProperty: exp.Properties.Location.POST_SCHEMA,
+354            exp.PartitionedByProperty: exp.Properties.Location.POST_SCHEMA,
+355            exp.TableFormatProperty: exp.Properties.Location.POST_SCHEMA,
+356        }
+357
+358        LIMIT_FETCH = "LIMIT"
+359
+360        def arrayagg_sql(self, expression: exp.ArrayAgg) -> str:
+361            return self.func(
+362                "COLLECT_LIST",
+363                expression.this.this if isinstance(expression.this, exp.Order) else expression.this,
+364            )
+365
+366        def with_properties(self, properties: exp.Properties) -> str:
+367            return self.properties(
+368                properties,
+369                prefix=self.seg("TBLPROPERTIES"),
+370            )
+371
+372        def datatype_sql(self, expression: exp.DataType) -> str:
+373            if (
+374                expression.this in (exp.DataType.Type.VARCHAR, exp.DataType.Type.NVARCHAR)
+375                and not expression.expressions
+376            ):
+377                expression = exp.DataType.build("text")
+378            elif expression.this in exp.DataType.TEMPORAL_TYPES:
+379                expression = exp.DataType.build(expression.this)
+380            return super().datatype_sql(expression)
 
@@ -1068,11 +1065,11 @@ Default: True
-
361        def arrayagg_sql(self, expression: exp.ArrayAgg) -> str:
-362            return self.func(
-363                "COLLECT_LIST",
-364                expression.this.this if isinstance(expression.this, exp.Order) else expression.this,
-365            )
+            
360        def arrayagg_sql(self, expression: exp.ArrayAgg) -> str:
+361            return self.func(
+362                "COLLECT_LIST",
+363                expression.this.this if isinstance(expression.this, exp.Order) else expression.this,
+364            )
 
@@ -1090,11 +1087,11 @@ Default: True
-
367        def with_properties(self, properties: exp.Properties) -> str:
-368            return self.properties(
-369                properties,
-370                prefix=self.seg("TBLPROPERTIES"),
-371            )
+            
366        def with_properties(self, properties: exp.Properties) -> str:
+367            return self.properties(
+368                properties,
+369                prefix=self.seg("TBLPROPERTIES"),
+370            )
 
@@ -1112,15 +1109,15 @@ Default: True
-
373        def datatype_sql(self, expression: exp.DataType) -> str:
-374            if (
-375                expression.this in (exp.DataType.Type.VARCHAR, exp.DataType.Type.NVARCHAR)
-376                and not expression.expressions
-377            ):
-378                expression = exp.DataType.build("text")
-379            elif expression.this in exp.DataType.TEMPORAL_TYPES:
-380                expression = exp.DataType.build(expression.this)
-381            return super().datatype_sql(expression)
+            
372        def datatype_sql(self, expression: exp.DataType) -> str:
+373            if (
+374                expression.this in (exp.DataType.Type.VARCHAR, exp.DataType.Type.NVARCHAR)
+375                and not expression.expressions
+376            ):
+377                expression = exp.DataType.build("text")
+378            elif expression.this in exp.DataType.TEMPORAL_TYPES:
+379                expression = exp.DataType.build(expression.this)
+380            return super().datatype_sql(expression)
 
@@ -1147,6 +1144,7 @@ Default: True
cache_sql
characterset_sql
column_sql
+
columnposition_sql
columndef_sql
columnconstraint_sql
autoincrementcolumnconstraint_sql
@@ -1262,6 +1260,7 @@ Default: True
primarykey_sql
unique_sql
if_sql
+
matchagainst_sql
jsonkeyvalue_sql
jsonobject_sql
in_sql
@@ -1313,8 +1312,10 @@ Default: True
gt_sql
gte_sql
ilike_sql
+
ilikeany_sql
is_sql
like_sql
+
likeany_sql
similarto_sql
lt_sql
lte_sql
-- cgit v1.2.3