Skip to content

[client][server] Support adding aggregation columns - #3459

Merged
luoyuxia merged 3 commits into
apache:mainfrom
wzx140:codex/aggregation-add-column-agg-function
Jul 3, 2026
Merged

luoyuxia merged 3 commits into
apache:mainfrom
wzx140:codex/aggregation-add-column-agg-function

Conversation

@wzx140

@wzx140 wzx140 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Support Java API TableChange.addColumn interfaces to pass aggregation functions when altering table schema.
  • Carry the aggregation function through ALTER TABLE ADD COLUMN RPC so the server preserves it in the new schema.
  • Validate aggregation functions on schema alter for aggregation merge engine tables and reject them on non-aggregation tables.

Support carrying aggregation functions through alter table add column requests.

Validate aggregation functions during schema alter and reject them on non-aggregation tables.
@luoyuxia
luoyuxia requested a review from Copilot June 12, 2026 04:08

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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds end-to-end support for specifying aggregation functions when adding columns via ALTER TABLE ADD COLUMN, including RPC transport and server-side validation for aggregation vs non-aggregation merge engine tables.

Changes:

  • Extend TableChange.addColumn to optionally carry an AggFunction.
  • Add RPC support to serialize/deserialize aggregation functions for ADD COLUMN.
  • Enforce validation rules for aggregation functions on schema alter and table creation.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
fluss-server/src/main/java/org/apache/fluss/server/utils/TableDescriptorValidation.java Adds validation to reject aggregation functions for non-aggregation merge engines; exposes validation helpers for reuse.
fluss-server/src/main/java/org/apache/fluss/server/utils/ServerRpcMessageUtils.java Deserializes aggregation function from PbAddColumn to TableChange.AddColumn.
fluss-server/src/main/java/org/apache/fluss/server/coordinator/SchemaUpdate.java Applies AggFunction when building the updated schema for added columns.
fluss-server/src/main/java/org/apache/fluss/server/coordinator/MetadataManager.java Validates aggregation function usage during ALTER TABLE schema updates based on merge engine.
fluss-rpc/src/main/proto/FlussApi.proto Adds serialized_agg_function field to PbAddColumn.
fluss-common/src/main/java/org/apache/fluss/metadata/TableChange.java Adds new addColumn overload carrying AggFunction and stores it on AddColumn.
fluss-client/src/test/java/org/apache/fluss/client/admin/FlussAdminITCase.java Adds integration tests for altering aggregation and non-aggregation tables with aggregation functions.
fluss-client/src/main/java/org/apache/fluss/client/utils/ClientRpcMessageUtils.java Serializes aggregation function into PbAddColumn.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wzx140
wzx140 force-pushed the codex/aggregation-add-column-agg-function branch 2 times, most recently from 9d58da3 to b9e72bc Compare June 12, 2026 06:18
@wzx140

wzx140 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

@luoyuxia Could you please help review this one?

@wzx140 wzx140 closed this Jun 12, 2026
@wzx140 wzx140 reopened this Jun 12, 2026

@luoyuxia luoyuxia 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.

@wzx140 Thanks for the pr. Left minor comments. PTAL

+ ", comment='"
+ comment
+ '\''
+ ", aggFunction="

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.

nit: if aggFunction is null, we don't need to print "aggFunction=null"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -440,6 +441,7 @@ public void alterTableSchema(
if (!schemaChanges.isEmpty()) {
Schema newSchema =

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.

I think we should also updat table option to reflect the new added merge coumn.
Like

CREATE TABLE test_last_value  (
    id BIGINT,
    status STRING,
    last_login TIMESTAMP(3),
    PRIMARY KEY (id) NOT ENFORCED
) WITH (
    'table.merge-engine' = 'aggregation',
    **'fields.status.agg' = 'last_value',**
    **'fields.last_login.agg' = 'last_value'**
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@luoyuxia Let me summarize the current situation a bit, since this part is somewhat subtle.

I think fields.*.agg should be treated as the Flink SQL option representation of column aggregation functions, rather than as the authoritative storage in Fluss table properties.

For Flink SQL CREATE TABLE, these options are parsed and converted into the column-level AggFunction in the Fluss schema. For Flink SQL SHOW CREATE TABLE, the options can be reconstructed from the column-level aggregation metadata for display.

The actual source of truth in Fluss metadata should remain the schema column AggFunction. Persisting the same aggregation information again in table properties would duplicate the metadata in two places and could introduce consistency issues.

This is also consistent with the Java API behavior: when a table is created with column-level AggFunctions through the Java API, TableInfo#getProperties() / getCustomProperties() do not contain fields.*.agg; the aggregation metadata is stored on the schema columns.

}

@Test
void testAlterAggregationTableColumnWithAggFunction() throws Exception {

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.

I think we had better to verify the merge works for new coulmn, may need to write rows to verify it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@luoyuxia luoyuxia 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.

@wzx140 Thanks. LGTM. @platinumhamburg Would you like to take another look? I’m not sure whether adding columns via ALTER TABLE has any corner cases for agg merge engine tables.

@platinumhamburg platinumhamburg 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.

LGTM.

@luoyuxia
luoyuxia merged commit e2a4403 into apache:main Jul 3, 2026
7 checks passed
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.

4 participants