summaryrefslogtreecommitdiffstats
path: root/sqlglot/dialects/hive.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-03 14:11:07 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-03 14:11:07 +0000
commit42a1548cecf48d18233f56e3385cf9c89abcb9c2 (patch)
tree5e0fff4ecbd1fd7dd1022a7580139038df2a824c /sqlglot/dialects/hive.py
parentReleasing debian version 21.1.2-1. (diff)
downloadsqlglot-42a1548cecf48d18233f56e3385cf9c89abcb9c2.tar.xz
sqlglot-42a1548cecf48d18233f56e3385cf9c89abcb9c2.zip
Merging upstream version 22.2.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/dialects/hive.py')
-rw-r--r--sqlglot/dialects/hive.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/sqlglot/dialects/hive.py b/sqlglot/dialects/hive.py
index 43211dc..55a9254 100644
--- a/sqlglot/dialects/hive.py
+++ b/sqlglot/dialects/hive.py
@@ -140,6 +140,15 @@ def _str_to_unix_sql(self: Hive.Generator, expression: exp.StrToUnix) -> str:
return self.func("UNIX_TIMESTAMP", expression.this, time_format("hive")(self, expression))
+def _unix_to_time_sql(self: Hive.Generator, expression: exp.UnixToTime) -> str:
+ timestamp = self.sql(expression, "this")
+ scale = expression.args.get("scale")
+ if scale in (None, exp.UnixToTime.SECONDS):
+ return rename_func("FROM_UNIXTIME")(self, expression)
+
+ return f"FROM_UNIXTIME({timestamp} / POW(10, {scale}))"
+
+
def _str_to_date_sql(self: Hive.Generator, expression: exp.StrToDate) -> str:
this = self.sql(expression, "this")
time_format = self.format_time(expression)
@@ -536,7 +545,7 @@ class Hive(Dialect):
exp.UnixToStr: lambda self, e: self.func(
"FROM_UNIXTIME", e.this, time_format("hive")(self, e)
),
- exp.UnixToTime: rename_func("FROM_UNIXTIME"),
+ exp.UnixToTime: _unix_to_time_sql,
exp.UnixToTimeStr: rename_func("FROM_UNIXTIME"),
exp.PartitionedByProperty: lambda self, e: f"PARTITIONED BY {self.sql(e, 'this')}",
exp.SerdeProperties: lambda self, e: self.properties(e, prefix="WITH SERDEPROPERTIES"),
@@ -609,9 +618,8 @@ class Hive(Dialect):
return self.properties(properties, prefix=self.seg("TBLPROPERTIES"))
def datatype_sql(self, expression: exp.DataType) -> str:
- if (
- expression.this in (exp.DataType.Type.VARCHAR, exp.DataType.Type.NVARCHAR)
- and not expression.expressions
+ if expression.this in self.PARAMETERIZABLE_TEXT_TYPES and (
+ not expression.expressions or expression.expressions[0].name == "MAX"
):
expression = exp.DataType.build("text")
elif expression.is_type(exp.DataType.Type.TEXT) and expression.expressions:
@@ -631,3 +639,15 @@ class Hive(Dialect):
def version_sql(self, expression: exp.Version) -> str:
sql = super().version_sql(expression)
return sql.replace("FOR ", "", 1)
+
+ def struct_sql(self, expression: exp.Struct) -> str:
+ values = []
+
+ for i, e in enumerate(expression.expressions):
+ if isinstance(e, exp.PropertyEQ):
+ self.unsupported("Hive does not support named structs.")
+ values.append(e.expression)
+ else:
+ values.append(e)
+
+ return self.func("STRUCT", *values)