Repository navigation
[client][server] Support adding aggregation columns - #3459
Conversation
Support carrying aggregation functions through alter table add column requests. Validate aggregation functions during schema alter and reject them on non-aggregation tables.
There was a problem hiding this comment.
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.addColumnto optionally carry anAggFunction. - 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.
9d58da3 to
b9e72bc
Compare
|
@luoyuxia Could you please help review this one? |
| + ", comment='" | ||
| + comment | ||
| + '\'' | ||
| + ", aggFunction=" |
There was a problem hiding this comment.
nit: if aggFunction is null, we don't need to print "aggFunction=null"
| @@ -440,6 +441,7 @@ public void alterTableSchema( | |||
| if (!schemaChanges.isEmpty()) { | |||
| Schema newSchema = | |||
There was a problem hiding this comment.
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'**
);
There was a problem hiding this comment.
@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 { |
There was a problem hiding this comment.
I think we had better to verify the merge works for new coulmn, may need to write rows to verify it.
luoyuxia
left a comment
There was a problem hiding this comment.
@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.
Summary
TableChange.addColumninterfaces to pass aggregation functions when altering table schema.