Skip to content

Conversation

@gianm
Copy link
Contributor

@gianm gianm commented Sep 8, 2025

The rule is adapted from Calcite's AggregateMergeRule, with two changes:

  1. Includes a workaround for https://issues.apache.org/jira/browse/CALCITE-7162

  2. Includes the ability to merge two Aggregate with a Project between them, by pushing the Project below the new merged Aggregate.

The goal is to rewrite a query like:

SELECT
  hr,
  UPPER(t1.x) x,
  SUM(t1.cnt) cnt,
  MIN(t1.mn) mn,
  MAX(t1.mx) mx
FROM (
  SELECT
    floor(__time to hour) hr,
    dim2 x,
    COUNT(*) cnt,
    MIN(m1 * 5) mn,
    MAX(m1 + m2) mx
  FROM druid.foo
  WHERE dim2 IN ('abc', 'def', 'a', 'b', '')
  GROUP BY 1, 2
) t1
WHERE t1.x IN ('abc', 'foo', 'bar', 'a', '')
GROUP BY 1, 2

Into:

SELECT
  FLOOR(__time TO hour) hr,
  UPPER(dim2) x,
  COUNT(*) cnt,
  MIN(m1 * 5) mn,
  MAX(m1 + m2) mx
FROM druid.foo
WHERE dim2 IN ('abc', 'a', '')
GROUP BY 1, 2

The rule is adapted from Calcite's AggregateMergeRule, with two changes:

1) Includes a workaround for https://issues.apache.org/jira/browse/CALCITE-7162

2) Includes the ability to merge two Aggregate with a Project between
   them, by pushing the Project below the new merged Aggregate.
@cryptoe cryptoe requested a review from kgyrtkirk September 9, 2025 10:13
@github-actions
Copy link

github-actions bot commented Nov 9, 2025

This pull request has been marked as stale due to 60 days of inactivity.
It will be closed in 4 weeks if no further activity occurs. If you think
that's incorrect or this pull request should instead be reviewed, please simply
write any comment. Even if closed, you can still revive the PR at any time or
discuss it on the [email protected] list.
Thank you for your contributions.

@github-actions github-actions bot added the stale label Nov 9, 2025
@github-actions
Copy link

github-actions bot commented Dec 7, 2025

This pull request/issue has been closed due to lack of activity. If you think that
is incorrect, or the pull request requires review, you can revive the PR at any time.

@github-actions github-actions bot closed this Dec 7, 2025
@gianm gianm reopened this Dec 31, 2025
@github-actions github-actions bot removed the stale label Jan 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant