Merging upstream version 22.2.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
b13ba670fd
commit
2c28c49d7e
148 changed files with 68457 additions and 63176 deletions
|
@ -453,11 +453,32 @@ class Presto(Dialect):
|
|||
return super().bracket_sql(expression)
|
||||
|
||||
def struct_sql(self, expression: exp.Struct) -> str:
|
||||
if any(isinstance(arg, self.KEY_VALUE_DEFINITIONS) for arg in expression.expressions):
|
||||
self.unsupported("Struct with key-value definitions is unsupported.")
|
||||
return self.function_fallback_sql(expression)
|
||||
from sqlglot.optimizer.annotate_types import annotate_types
|
||||
|
||||
return rename_func("ROW")(self, expression)
|
||||
expression = annotate_types(expression)
|
||||
values: t.List[str] = []
|
||||
schema: t.List[str] = []
|
||||
unknown_type = False
|
||||
|
||||
for e in expression.expressions:
|
||||
if isinstance(e, exp.PropertyEQ):
|
||||
if e.type and e.type.is_type(exp.DataType.Type.UNKNOWN):
|
||||
unknown_type = True
|
||||
else:
|
||||
schema.append(f"{self.sql(e, 'this')} {self.sql(e.type)}")
|
||||
values.append(self.sql(e, "expression"))
|
||||
else:
|
||||
values.append(self.sql(e))
|
||||
|
||||
size = len(expression.expressions)
|
||||
|
||||
if not size or len(schema) != size:
|
||||
if unknown_type:
|
||||
self.unsupported(
|
||||
"Cannot convert untyped key-value definitions (try annotate_types)."
|
||||
)
|
||||
return self.func("ROW", *values)
|
||||
return f"CAST(ROW({', '.join(values)}) AS ROW({', '.join(schema)}))"
|
||||
|
||||
def interval_sql(self, expression: exp.Interval) -> str:
|
||||
unit = self.sql(expression, "unit")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue