From 00c54b543ea1b6633d2da8ca5bea407349d85bf9 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Fri, 8 Sep 2023 16:12:43 -0400 Subject: [PATCH] feat(duckdb): make sure any and all handle filters --- ibis/backends/duckdb/compiler/values.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/ibis/backends/duckdb/compiler/values.py b/ibis/backends/duckdb/compiler/values.py index 69b5b5268c7b0..8b11cd128f00b 100644 --- a/ibis/backends/duckdb/compiler/values.py +++ b/ibis/backends/duckdb/compiler/values.py @@ -187,6 +187,26 @@ def _not(op, **kw): return sg.expressions.Not(this=arg) +@translate_val.register(ops.Any) +def _any(op, **kw): + arg = translate_val(op.arg, **kw) + any_expr = sg.expressions.AnyValue(this=arg) + if op.where is not None: + where = sg.expressions.Where(this=translate_val(op.where, **kw)) + return sg.expressions.Filter(this=any_expr, expression=where) + return any_expr + + +@translate_val.register(ops.All) +def _any(op, **kw): + arg = translate_val(op.arg, **kw) + all_expr = sg.func("bool_and", arg) + if op.where is not None: + where = sg.expressions.Where(this=translate_val(op.where, **kw)) + return sg.expressions.Filter(this=all_expr, expression=where) + return all_expr + + ### Timey McTimeFace @@ -537,8 +557,6 @@ def _levenshtein(op, **kw): ops.Mean: "avg", ops.Max: "max", ops.Min: "min", - ops.Any: "any_value", - ops.All: "min", ops.ArgMin: "arg_min", ops.Mode: "mode", ops.ArgMax: "arg_max",