Skip to content

Commit

Permalink
fix(flink): correct the filtered count translation
Browse files Browse the repository at this point in the history
  • Loading branch information
deepyaman authored and cpcloud committed Oct 9, 2023
1 parent 8502e81 commit 2cbca74
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
8 changes: 7 additions & 1 deletion ibis/backends/flink/registry.py
Expand Up @@ -18,7 +18,13 @@


def _count_star(translator: ExprTranslator, op: ops.Node) -> str:
return "count(*)"
# TODO(deepyaman): Use `FILTER` syntax; see note on `_filter` below.
if (where := op.where) is not None:
condition = f"CASE WHEN {translator.translate(where)} THEN 1 END"
else:
condition = "*"

return f"COUNT({condition})"


def _date(translator: ExprTranslator, op: ops.Node) -> str:
Expand Down
@@ -1,4 +1,4 @@
SELECT t0.`b`, count(*) AS `total`, avg(t0.`a`) AS `avg_a`,
SELECT t0.`b`, COUNT(*) AS `total`, avg(t0.`a`) AS `avg_a`,
avg(CASE WHEN t0.`g` = 'A' THEN t0.`a` ELSE NULL END) AS `avg_a_A`,
avg(CASE WHEN t0.`g` = 'B' THEN t0.`a` ELSE NULL END) AS `avg_a_B`
FROM table t0
Expand Down
@@ -1,5 +1,5 @@
SELECT EXTRACT(year from t0.`i`) AS `year`,
EXTRACT(month from t0.`i`) AS `month`, count(*) AS `total`,
EXTRACT(month from t0.`i`) AS `month`, COUNT(*) AS `total`,
count(DISTINCT t0.`b`) AS `b_unique`
FROM table t0
GROUP BY EXTRACT(year from t0.`i`), EXTRACT(month from t0.`i`)
@@ -1,3 +1,3 @@
SELECT t0.`i`, count(*) AS `CountStar(table)`
SELECT t0.`i`, COUNT(*) AS `CountStar(table)`
FROM table t0
GROUP BY t0.`i`
@@ -1,4 +1,4 @@
SELECT t0.`g`, sum(t0.`b`) AS `b_sum`
FROM table t0
GROUP BY t0.`g`
HAVING count(*) >= CAST(1000 AS SMALLINT)
HAVING COUNT(*) >= CAST(1000 AS SMALLINT)
@@ -1,4 +1,4 @@
SELECT t0.`ExtractYear(i)`, count(*) AS `ExtractYear(i)_count`
SELECT t0.`ExtractYear(i)`, COUNT(*) AS `ExtractYear(i)_count`
FROM (
SELECT EXTRACT(year from t1.`i`) AS `ExtractYear(i)`
FROM table t1
Expand Down

0 comments on commit 2cbca74

Please sign in to comment.