Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Fix that AggregateMergeFunction handles multiple sequence fields mistakenly #5065

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.paimon.mergetree.compact.MergeFunctionFactory;
import org.apache.paimon.mergetree.compact.aggregate.factory.FieldAggregatorFactory;
import org.apache.paimon.mergetree.compact.aggregate.factory.FieldLastNonNullValueAggFactory;
import org.apache.paimon.mergetree.compact.aggregate.factory.FieldLastValueAggFactory;
import org.apache.paimon.mergetree.compact.aggregate.factory.FieldPrimaryKeyAggFactory;
import org.apache.paimon.options.Options;
import org.apache.paimon.types.DataType;
Expand Down Expand Up @@ -149,8 +150,8 @@ public MergeFunction<KeyValue> create(@Nullable int[][] projection) {

private String getAggFuncName(String fieldName, List<String> sequenceFields) {
if (sequenceFields.contains(fieldName)) {
// no agg for sequence fields, use last_non_null_value to do cover
return FieldLastNonNullValueAggFactory.NAME;
// no agg for sequence fields, use last_value to do cover
return FieldLastValueAggFactory.NAME;
}

if (primaryKeys.contains(fieldName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,26 @@ public void testIncrementTagQueryWithRescaleBucket() throws Exception {
}
}

@Test
public void testAggregationWithNullSequenceField() {
sql(
"CREATE TABLE test ("
+ " pk INT PRIMARY KEY NOT ENFORCED,"
+ " v STRING,"
+ " s0 INT,"
+ " s1 INT"
+ ") WITH ("
+ " 'merge-engine' = 'aggregation',"
+ " 'sequence.field' = 's0,s1')");

sql(
"INSERT INTO test VALUES (1, 'A1', CAST (NULL AS INT), 1), (1, 'A2', 1, CAST (NULL AS INT))");
assertThat(sql("SELECT * FROM test")).containsExactly(Row.of(1, "A2", 1, null));

sql("INSERT INTO test VALUES (1, 'A3', 1, 0)");
assertThat(sql("SELECT * FROM test")).containsExactly(Row.of(1, "A3", 1, 0));
}

private void validateCount1PushDown(String sql) {
Transformation<?> transformation = AbstractTestBase.translate(tEnv, sql);
while (!transformation.getInputs().isEmpty()) {
Expand Down