Skip to content

Commit

Permalink
fix(duckdb): ensure that structs can be used with sqlglot 20.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and gforsyth committed Feb 15, 2024
1 parent fb037a6 commit 17be43a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ibis/backends/duckdb/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ def _aggregate(self, funcname: str, *args, where):
return sge.Filter(this=expr, expression=sge.Where(this=where))
return expr

def visit_StructColumn(self, op, *, names, values):
return sge.Struct.from_arg_list(
[
sge.PropertyEQ(
this=sg.to_identifier(name, quoted=self.quoted), expression=value
)
for name, value in zip(names, values)
]
)

def visit_ArrayDistinct(self, op, *, arg):
return self.if_(
arg.is_(NULL),
Expand Down Expand Up @@ -314,6 +324,18 @@ def visit_NonNullLiteral(self, op, *, value, dtype):
args.append(tz)

return self.f[funcname](*args)
elif dtype.is_struct():
return sge.Struct.from_arg_list(
[
sge.PropertyEQ(
this=sg.to_identifier(k, quoted=self.quoted),
expression=self.visit_Literal(
ops.Literal(v, field_dtype), value=v, dtype=field_dtype
),
)
for field_dtype, (k, v) in zip(dtype.types, value.items())
]
)
else:
return None

Expand Down

0 comments on commit 17be43a

Please sign in to comment.