Skip to content

Commit

Permalink
Merge pull request #677 from mabel-dev/FIX/#669
Browse files Browse the repository at this point in the history
#669 `COUNT(*)` cannot be mixed with other aggregates.
  • Loading branch information
joocer authored Nov 20, 2022
2 parents 226fe8a + 0a19bcd commit 226297c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 6 additions & 4 deletions opteryx/operators/aggregate_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,16 @@ def _build_aggs(aggregators, columns):
count_options = None

if field_node.token_type == NodeType.WILDCARD:
display_field = "*"
field_name = columns.preferred_column_names[0][0]
# count * counts nulls
count_options = pyarrow.compute.CountOptions(mode="all")
elif field_node.token_type == NodeType.IDENTIFIER:
display_field = field_node.value
field_name = columns.get_column_from_alias(
field_node.value, only_one=True
)
elif field_node.token_type == NodeType.LITERAL_NUMERIC:
display_field = str(field_node.value)
field_name = field_node.value
elif len(exists) > 0:
display_field = exists[0]
field_name = exists[0]
else:
display_name = format_expression(field_node)
Expand Down Expand Up @@ -188,6 +184,12 @@ def _non_group_aggregates(aggregates, table, columns):
table.num_rows, column_node.value, dtype=numpy.float64
)
mapped_column_name = str(column_node.value)
elif (
aggregate.value == "COUNT"
and aggregate.parameters[0].token_type == NodeType.WILDCARD
):
result["COUNT(*)"] = table.num_rows
continue
else:
column_name = format_expression(aggregate.parameters[0])
mapped_column_name = columns.get_column_from_alias(
Expand Down
6 changes: 5 additions & 1 deletion tests/sql_battery/tests/regression.run_tests
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,8 @@ SHOW COLUMNS FROM $planets FOR DATES BETWEEN YESTERDAY AND TODAY LIKE '%name%';
SELECT ARRAY_AGG(DISTINCT LEFT(LOWER(name), 1) LIMIT 2) from $satellites GROUP BY planetId;
SELECT ARRAY_AGG(DISTINCT RIGHT(LOWER(name), 1) LIMIT 2) from $satellites GROUP BY planetId;
SELECT ARRAY_AGG(DISTINCT LEFT(UPPER(name), 1) LIMIT 2) from $satellites GROUP BY planetId;
SELECT ARRAY_AGG(DISTINCT RIGHT(UPPER(name), 1) LIMIT 2) from $satellites GROUP BY planetId
SELECT ARRAY_AGG(DISTINCT RIGHT(UPPER(name), 1) LIMIT 2) from $satellites GROUP BY planetId


SELECT COUNT(*), COUNT_DISTINCT(id) FROM $planets;
SELECT COUNT(*), SUM(id) FROM $planets;

0 comments on commit 226297c

Please sign in to comment.