Skip to content

Commit

Permalink
feat(datafusion): implement argmin/argmax
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist committed Sep 25, 2024
1 parent a8a3478 commit 3310220
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 8 additions & 2 deletions ibis/backends/sql/compilers/datafusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class DataFusionCompiler(SQLGlotCompiler):
post_rewrites = (split_select_distinct_with_order_by,)

UNSUPPORTED_OPS = (
ops.ArgMax,
ops.ArgMin,
ops.ArrayDistinct,
ops.ArrayFilter,
ops.ArrayMap,
Expand Down Expand Up @@ -457,6 +455,14 @@ def visit_Last(self, op, *, arg, where, order_by, include_null):
where = cond if where is None else sge.And(this=cond, expression=where)
return self.agg.last_value(arg, where=where, order_by=order_by)

def visit_ArgMin(self, op, *, arg, key, where):
return self.agg.first_value(arg, where=where, order_by=[sge.Ordered(this=key)])

def visit_ArgMax(self, op, *, arg, key, where):
return self.agg.first_value(
arg, where=where, order_by=[sge.Ordered(this=key, desc=True)]
)

def visit_Aggregate(self, op, *, parent, groups, metrics):
"""Support `GROUP BY` expressions in `SELECT` since DataFusion does not."""
quoted = self.quoted
Expand Down
4 changes: 0 additions & 4 deletions ibis/backends/tests/test_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ def mean_udf(s):
]

argidx_not_grouped_marks = [
"datafusion",
"impala",
"mysql",
"mssql",
Expand Down Expand Up @@ -411,7 +410,6 @@ def mean_and_std(v):
[
"impala",
"mysql",
"datafusion",
"mssql",
"druid",
"oracle",
Expand All @@ -431,7 +429,6 @@ def mean_and_std(v):
[
"impala",
"mysql",
"datafusion",
"mssql",
"druid",
"oracle",
Expand Down Expand Up @@ -691,7 +688,6 @@ def test_first_last_ordered(alltypes, method, filtered, include_null):

@pytest.mark.notimpl(
[
"datafusion",
"druid",
"exasol",
"flink",
Expand Down

0 comments on commit 3310220

Please sign in to comment.