Skip to content

Commit

Permalink
fix(duckdb): force string_agg separator to be a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Jul 5, 2022
1 parent e580bec commit 21cdf2f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ibis/backends/duckdb/registry.py
Expand Up @@ -165,6 +165,18 @@ def _arbitrary(t, expr):
return t._reduction(getattr(sa.func, how), expr)


def _string_agg(t, expr):
op = expr.op()
if not isinstance(lit := op.sep.op(), ops.Literal):
raise TypeError(
"Separator argument to group_concat operation must be a constant"
)
agg = sa.func.string_agg(t.translate(op.arg), sa.text(repr(lit.value)))
if (where := op.where) is not None:
return agg.filter(t.translate(where))
return agg


operation_registry.update(
{
ops.ArrayColumn: _array_column,
Expand Down Expand Up @@ -199,6 +211,7 @@ def _arbitrary(t, expr):
ops.ApproxCountDistinct: reduction(sa.func.approx_count_distinct),
ops.Strftime: _strftime,
ops.Arbitrary: _arbitrary,
ops.GroupConcat: _string_agg,
}
)

Expand Down

0 comments on commit 21cdf2f

Please sign in to comment.