Skip to content

Commit

Permalink
feat(datafusion): implement Count operation
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Apr 13, 2022
1 parent b110636 commit 4797a86
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
10 changes: 10 additions & 0 deletions ibis/backends/datafusion/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,16 @@ def mod(op, expr):
return translate(op.left) % translate(op.right)


@translate.register(ops.Count)
def count(op, expr):
op_arg = op.arg
if isinstance(op_arg, ir.TableExpr):
arg = df.literal(1)
else:
arg = translate(op_arg)
return df.functions.count(arg)


@translate.register(ops.Sum)
def sum(op, expr):
arg = translate(op.arg)
Expand Down
1 change: 0 additions & 1 deletion ibis/backends/tests/test_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ def test_binds_are_cast(alltypes):
expr.execute()


@pytest.mark.notimpl(["datafusion"])
def test_agg_sort(alltypes):
query = alltypes.aggregate(count=alltypes.count())
query = query.sort_by(alltypes.year)
Expand Down
6 changes: 4 additions & 2 deletions ibis/backends/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ def test_table_info(alltypes):
alltypes.info(buf=buf)

info_str = buf.getvalue()
assert info_str is not None
schema = alltypes.schema()

assert "Nulls" in info_str
assert all(str(type) in info_str for type in alltypes.schema().types)
assert all(str(type) in info_str for type in schema.types)
assert all(name in info_str for name in schema.names)

0 comments on commit 4797a86

Please sign in to comment.