You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@paimon.apache.org by lz...@apache.org on 2024/07/06 01:39:49 UTC
(paimon) 06/27: [core] Fix FieldCountAgg null value init process (#3536)
This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch release-0.8
in repository https://gitbox.apache.org/repos/asf/paimon.git
commit 0351301ab998ff9a5abe8140c5d90dbf92c92c77
Author: xuzifu666 <12...@qq.com>
AuthorDate: Wed Jun 19 16:27:32 2024 +0800
[core] Fix FieldCountAgg null value init process (#3536)
---
.../apache/paimon/mergetree/compact/aggregate/FieldCountAgg.java | 4 ++--
.../paimon/mergetree/compact/aggregate/FieldAggregatorTest.java | 9 +++++----
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/paimon-core/src/main/java/org/apache/paimon/mergetree/compact/aggregate/FieldCountAgg.java b/paimon-core/src/main/java/org/apache/paimon/mergetree/compact/aggregate/FieldCountAgg.java
index f03290cb8..5fb7b2bb9 100644
--- a/paimon-core/src/main/java/org/apache/paimon/mergetree/compact/aggregate/FieldCountAgg.java
+++ b/paimon-core/src/main/java/org/apache/paimon/mergetree/compact/aggregate/FieldCountAgg.java
@@ -38,7 +38,7 @@ public class FieldCountAgg extends FieldAggregator {
public Object agg(Object accumulator, Object inputField) {
Object count;
if (accumulator == null || inputField == null) {
- count = (accumulator == null ? 1 : accumulator);
+ count = (accumulator == null ? (inputField == null ? 0 : 1) : accumulator);
} else {
// ordered by type root definition
switch (fieldType.getTypeRoot()) {
@@ -59,7 +59,7 @@ public class FieldCountAgg extends FieldAggregator {
public Object retract(Object accumulator, Object inputField) {
Object count;
if (accumulator == null || inputField == null) {
- count = (accumulator == null ? 1 : accumulator);
+ count = (accumulator == null ? (inputField == null ? 0 : -1) : accumulator);
} else {
// ordered by type root definition
switch (fieldType.getTypeRoot()) {
diff --git a/paimon-core/src/test/java/org/apache/paimon/mergetree/compact/aggregate/FieldAggregatorTest.java b/paimon-core/src/test/java/org/apache/paimon/mergetree/compact/aggregate/FieldAggregatorTest.java
index e164bda31..5bca65ed7 100644
--- a/paimon-core/src/test/java/org/apache/paimon/mergetree/compact/aggregate/FieldAggregatorTest.java
+++ b/paimon-core/src/test/java/org/apache/paimon/mergetree/compact/aggregate/FieldAggregatorTest.java
@@ -155,10 +155,11 @@ public class FieldAggregatorTest {
@Test
public void testFieldCountIntAgg() {
FieldCountAgg fieldCountAgg = new FieldCountAgg(new IntType());
- assertThat(fieldCountAgg.agg(null, 10)).isEqualTo(1);
- assertThat(fieldCountAgg.agg(1, 5)).isEqualTo(2);
- assertThat(fieldCountAgg.agg(2, 15)).isEqualTo(3);
- assertThat(fieldCountAgg.agg(3, 25)).isEqualTo(4);
+ assertThat(fieldCountAgg.agg(null, null)).isEqualTo(0);
+ assertThat(fieldCountAgg.agg(1, null)).isEqualTo(1);
+ assertThat(fieldCountAgg.agg(null, 15)).isEqualTo(1);
+ assertThat(fieldCountAgg.agg(1, 0)).isEqualTo(2);
+ assertThat(fieldCountAgg.agg(3, 6)).isEqualTo(4);
}
@Test