Skip to content

Add collect/merge_map aggregations and binary merge optimizations. - #2388

Open
platinumhamburg wants to merge 5 commits into
apache:mainfrom
platinumhamburg:complex-functions
Open

platinumhamburg wants to merge 5 commits into
apache:mainfrom
platinumhamburg:complex-functions

Conversation

@platinumhamburg

Copy link
Copy Markdown
Contributor

Extend tests and docs to cover new functions and array/map utilities.

Purpose

Linked issue: close #2387

Brief change log

Tests

API and Format

Documentation

Extend tests and docs to cover new functions and array/map utilities.
@platinumhamburg

Copy link
Copy Markdown
Contributor Author

Hi @fresh-borzoni, would you have time to review this PR? It adds new aggregate functions to the aggregation merge engine. Given your work on last_n, your feedback on the function semantics, edge cases, and fit with the existing aggregation framework would be especially helpful. Thanks!

Comment thread fluss-common/src/main/java/org/apache/fluss/metadata/AggFunction.java Outdated
Comment thread website/docs/table-design/merge-engines/aggregation.md Outdated
Comment thread website/docs/table-design/merge-engines/aggregation.md
Comment thread fluss-common/src/main/java/org/apache/fluss/row/InternalArrayUtils.java Outdated
@polyzos

polyzos commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Thanks @platinumhamburg.

I've added a few comments and suggestions. 👍

@fresh-borzoni fresh-borzoni left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @platinumhamburg, looked through. Seema @polyzos already did a good job with the review :)

Couple of thoughts:
FieldCollectAgg, FieldMergeMapAgg and both factories carry the "based on Apache Paimon" header, but they aren't in the Apache Paimon list in the root LICENSE. The other Paimon-derived aggregators are all listed there. Shall we add?

On the binary concat: #4923 adds BinaryArraySplicer, which does that for last_n. It copies a range of a binary array as bytes and shifts the offsets of the variable-length data. At 1000 elements a last_n merge went from 10.9 µs to 0.75 µs for BIGINT, and from 18.3 µs to 5.45 µs for STRING on my laptop.

Non-distinct collect is the same case:

if (spliceable && BinaryArraySplicer.canSplice(accumulatorArray, inputArray)) {
    return new BinaryArraySplicer(elementType)
            .append((BinaryArray) accumulatorArray, 0, accumulatorArray.size())
            .append((BinaryArray) inputArray, 0, inputArray.size())
            .build();
}

with spliceable = BinaryArraySplicer.supports(elementType), as last_n does it.

Can you take a look and share your thoughts? I'm dubious since merge isn't the part that dominates, so eager to align on this.

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.

[Aggregation] Add collect/merge_map aggregation support

3 participants