From 211bfab697d6945812a36474baee6187440c5a48 Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Tue, 19 Jul 2022 05:59:57 -0400 Subject: [PATCH] feat(duckdb): implement `ops.StructColumn` operation --- ibis/backends/duckdb/registry.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ibis/backends/duckdb/registry.py b/ibis/backends/duckdb/registry.py index cb7610e710c9..46db5bf1edd4 100644 --- a/ibis/backends/duckdb/registry.py +++ b/ibis/backends/duckdb/registry.py @@ -177,6 +177,18 @@ def _string_agg(t, expr): return agg +def _struct_column(t, expr): + op = expr.op() + compile_kwargs = dict(literal_binds=True) + translated_pairs = ( + (name, t.translate(value).compile(compile_kwargs=compile_kwargs)) + for name, value in zip(op.names, op.values) + ) + return sa.func.struct_pack( + *(sa.text(f"{name} := {value}") for name, value in translated_pairs) + ) + + operation_registry.update( { ops.ArrayColumn: _array_column, @@ -212,6 +224,7 @@ def _string_agg(t, expr): ops.Strftime: _strftime, ops.Arbitrary: _arbitrary, ops.GroupConcat: _string_agg, + ops.StructColumn: _struct_column, } )