This is an automated email from the ASF dual-hosted git repository.

lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new 48b08288c [core] Fix FieldCountAgg null value init process (#3536)
48b08288c is described below

commit 48b08288cd8113c7c6a8df1283acbf8b0a25b01f
Author: xuzifu666 <[email protected]>
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

Reply via email to