Skip to content

DM-55685: Expanded aggregation support - #1094

Open
malensek wants to merge 5 commits into
mainfrom
tickets/DM-55685
Open

malensek wants to merge 5 commits into
mainfrom
tickets/DM-55685

Conversation

@malensek

@malensek malensek commented Sep 3, 2026

Copy link
Copy Markdown
Member

The query analysis AggregatePlugin previously assumed a flat, top-level list of expressions from the parser adapter. As a result, the adapter layer restricted aggregations to simple column references only. This change enables the plugin to handle both a flat list of expressions from the legacy adapter as well as a potentially deeper tree of expressions produced by the Hyrise adapter.

Additionally, this change enables BIT_ aggregations, since they can be split and merged via AccumulateOp like MIN, MAX, SUM.

Here are some of the new possibilities supported by this change (using the qcase02 test dataset):

SELECT ROUND(100.0 * COUNT(yFlags) / COUNT(*), 1) FROM qcase02.Object;
SELECT MAX(ABS(decl_PS)) FROM qcase02.Object;
SELECT MAX(objectId + 1) FROM qcase02.Object;
SELECT MIN(LENGTH(objectId)) FROM qcase02.Object;
SELECT 25 + SUM(uNumObs) + 100 FROM qcase02.Object;
SELECT BIT_OR(uFlags & 255) FROM qcase02.Object;

Summary of Changes

  • AggregatePlugin now recursively traverses ValueExpr and ValueFactor trees
  • SchemaFactory now preserves UNSIGNED_FLAG when creating integer columns
  • BIT_XOR, BIT_AND, BIT_OR are now allowed by the parser adapter and processed in query analysis
  • HAVING aggregations that can't be resolved are now rejected up front
  • New unit and integration tests for this functionality

Related issues (existing behavior, being tracked in DM-56009):

  • HAVING with non-aggregate expressions are not currently validated against the SELECT list
  • GROUP BY keys are not validated against the SELECT list
  • SELECT * does not populate _usedValueExprs, so nothing in ORDER BY / HAVING matches

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical aggregate-placement and grouped-merge planning issues remain unresolved.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Expands distributed aggregation to support nested expressions, bitwise aggregates, and unsigned intermediate result types.

Changes:

  • Recursively detects and rewrites aggregate expression trees.
  • Adds BIT_AND, BIT_OR, and BIT_XOR support.
  • Adds unit and integration coverage.
File summaries
File Description
src/query/ValueFactor.h Declares recursive aggregation detection.
src/query/ValueFactor.cc Implements recursive factor traversal.
src/query/ValueExpr.cc Delegates aggregation detection to factors.
src/query/AggOp.cc Adds bitwise accumulation operations.
src/qproc/testQueryAnaAggregation.cc Tests rewritten plans; critically, a grouped merge expects chunkId that the parallel query does not emit.
src/qana/CheckAggregation.h Removes the obsolete shallow checker.
src/qana/AggregatePlugin.cc Recursively rewrites aggregate trees.
src/mysql/SchemaFactory.cc Preserves unsigned integer metadata.
src/ccontrol/testHyriseGeneratedIR.cc Updates adapter aggregation tests.
src/ccontrol/HyriseAdapter.cc Expands aggregate parsing; critically, invalid aggregate placements beyond WHERE, including HAVING, are not safely rejected or rewritten.
data/case01/queries/2117_nestedAggregateExpressionGroupBy.sql Tests grouped nested aggregation.
data/case01/queries/2116_nestedAggregateExpression.sql Tests nested aggregate arithmetic.
data/case01/queries/2115_bitwiseAggregatesEmptyInput.sql Tests empty-input identities.
data/case01/queries/2114_bitwiseAggregateWideValue.sql Tests unsigned 64-bit results.
data/case01/queries/2113_bitwiseAggregateExpression.sql Tests expression arguments.
data/case01/queries/2112_bitwiseAggregatesGroupBy.sql Tests grouped bitwise aggregation.
data/case01/queries/2111_bitwiseAggregatesEmptyChunks.sql Tests empty worker chunks.
data/case01/queries/2110_bitwiseAggregates.sql Tests basic bitwise aggregates.
Review details
  • Files reviewed: 18/18 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/ccontrol/HyriseAdapter.cc
Comment thread src/qproc/testQueryAnaAggregation.cc Outdated
@malensek
malensek force-pushed the tickets/DM-55685 branch 2 times, most recently from 191639d to 5bd2755 Compare September 9, 2026 22:20
Previously this method checked all factors for AGGFUNC types. This adds
a new ValueFactor::hasAggregation() method to also check for scalar
functions or expressions that contain an aggregation, and is called by
the original ValueExpr::hasAggregation().
Previously signed/unsigned information was not preserved for integer
types when creating merge tables, so unsigned results from the worker
were converted to signed columns on the czar.

In most cases this would not be an issue (no conversion error), but
bitwise aggregations make it easier to produce values that would not
convert properly (e.g., a number with all bits set).
Much like MIN, MAX, SUM, AccumulateOp can be used for bitwise
aggregations because the same action can be applied in both the parallel
and merging phases. This adds BIT_AND, BIT_OR, and BIT_XOR to the map of
valid aggregations and associates them with AccumulateOp.
The previous parser adapter produced a flat, top-level list of
expressions that made merge query rewriting straightforward. However, it
also meant aggregations were limited to simple column references. This
change enables `qana` to handle both a flat list of expressions from the
legacy adapter as well as a tree of expressions. Consequently, we can
now support admissible nested operations like SELECT MAX(LENGTH(x)).
* Updates the parser adapter to allow these query types
* Adds validation to TablePlugin to ensure aggregations in `HAVING` are
  present in the `SELECT` list
* Adds new unit and integration tests to verify their functionality.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The recursive rewrite, placement validation, schema handling, and edge cases are covered consistently by focused unit and integration tests.

Review details
  • Files reviewed: 21/21 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@malensek
malensek marked this pull request as ready for review September 9, 2026 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants