From 4554ab4c7d6b2bbbaa6f4d0b810bf477d1a505a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 25 Sep 2023 10:20:09 +0200 Subject: Merging upstream version 18.7.0. Signed-off-by: Daniel Baumann --- sqlglot/dialects/hive.py | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'sqlglot/dialects/hive.py') diff --git a/sqlglot/dialects/hive.py b/sqlglot/dialects/hive.py index bec27d3..a427870 100644 --- a/sqlglot/dialects/hive.py +++ b/sqlglot/dialects/hive.py @@ -111,7 +111,7 @@ def _array_sort_sql(self: Hive.Generator, expression: exp.ArraySort) -> str: def _property_sql(self: Hive.Generator, expression: exp.Property) -> str: - return f"'{expression.name}'={self.sql(expression, 'value')}" + return f"{self.property_name(expression, string_key=True)}={self.sql(expression, 'value')}" def _str_to_unix_sql(self: Hive.Generator, expression: exp.StrToUnix) -> str: @@ -413,7 +413,7 @@ class Hive(Dialect): exp.DiToDate: lambda self, e: f"TO_DATE(CAST({self.sql(e, 'this')} AS STRING), {Hive.DATEINT_FORMAT})", exp.FileFormatProperty: lambda self, e: f"STORED AS {self.sql(e, 'this') if isinstance(e.this, exp.InputOutputFormat) else e.name.upper()}", exp.FromBase64: rename_func("UNBASE64"), - exp.If: if_sql, + exp.If: if_sql(), exp.ILike: no_ilike_sql, exp.IsNan: rename_func("ISNAN"), exp.JSONExtract: rename_func("GET_JSON_OBJECT"), @@ -466,6 +466,11 @@ class Hive(Dialect): exp.NumberToStr: rename_func("FORMAT_NUMBER"), exp.LastDateOfMonth: rename_func("LAST_DAY"), exp.National: lambda self, e: self.national_sql(e, prefix=""), + exp.ClusteredColumnConstraint: lambda self, e: f"({self.expressions(e, 'this', indent=False)})", + exp.NonClusteredColumnConstraint: lambda self, e: f"({self.expressions(e, 'this', indent=False)})", + exp.NotForReplicationColumnConstraint: lambda self, e: "", + exp.OnProperty: lambda self, e: "", + exp.PrimaryKeyColumnConstraint: lambda self, e: "PRIMARY KEY", } PROPERTIES_LOCATION = { @@ -475,6 +480,35 @@ class Hive(Dialect): exp.VolatileProperty: exp.Properties.Location.UNSUPPORTED, } + def parameter_sql(self, expression: exp.Parameter) -> str: + this = self.sql(expression, "this") + parent = expression.parent + + if isinstance(parent, exp.EQ) and isinstance(parent.parent, exp.SetItem): + # We need to produce SET key = value instead of SET ${key} = value + return this + + return f"${{{this}}}" + + def schema_sql(self, expression: exp.Schema) -> str: + expression = expression.copy() + + for ordered in expression.find_all(exp.Ordered): + if ordered.args.get("desc") is False: + ordered.set("desc", None) + + return super().schema_sql(expression) + + def constraint_sql(self, expression: exp.Constraint) -> str: + expression = expression.copy() + + for prop in list(expression.find_all(exp.Properties)): + prop.pop() + + this = self.sql(expression, "this") + expressions = self.expressions(expression, sep=" ", flat=True) + return f"CONSTRAINT {this} {expressions}" + def rowformatserdeproperty_sql(self, expression: exp.RowFormatSerdeProperty) -> str: serde_props = self.sql(expression, "serde_properties") serde_props = f" {serde_props}" if serde_props else "" -- cgit v1.2.3