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 689a5a495 [core] Remove count function because it cannot be 
implemented correctly (#3932)
689a5a495 is described below

commit 689a5a49544e186b26f5a988732f5e97f3405187
Author: monster <[email protected]>
AuthorDate: Sun Aug 11 21:06:13 2024 +0800

    [core] Remove count function because it cannot be implemented correctly 
(#3932)
---
 .../primary-key-table/merge-engine/aggregation.md  |  12 ++-
 .../compact/aggregate/FieldAggregator.java         |   3 -
 .../mergetree/compact/aggregate/FieldCountAgg.java | 100 ---------------------
 .../compact/aggregate/FieldAggregatorTest.java     |  31 -------
 4 files changed, 9 insertions(+), 137 deletions(-)

diff --git a/docs/content/primary-key-table/merge-engine/aggregation.md 
b/docs/content/primary-key-table/merge-engine/aggregation.md
index 7cdd9044a..27b29ed5b 100644
--- a/docs/content/primary-key-table/merge-engine/aggregation.md
+++ b/docs/content/primary-key-table/merge-engine/aggregation.md
@@ -71,8 +71,14 @@ Current supported aggregate functions and data types are:
   It supports DECIMAL, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, and DOUBLE 
data types.
 
 ### count
-  The count function counts the values across multiple rows.
-  It supports INTEGER, BIGINT data types.
+  In scenarios where counting rows that match a specific condition is 
required, you can use the SUM function to achieve this. By expressing a 
condition as a Boolean value (TRUE or FALSE) and converting it into a numerical 
value, you can effectively count the rows. In this approach, TRUE is converted 
to 1, and FALSE is converted to 0.
+
+  For example, if you have a table orders and want to count the number of rows 
that meet a specific condition, you can use the following query:
+  ```sql
+  SELECT SUM(CASE WHEN condition THEN 1 ELSE 0 END) AS count
+  FROM orders;
+  ```
+
 
 ### max
   The max function identifies and retains the maximum value.
@@ -261,7 +267,7 @@ For streaming queries, `aggregation` merge engine must be 
used together with `lo
 
 ## Retraction
 
-Only `sum`, `product`, `count`, `collect`, `merge_map`, `nested_update`, 
`last_value` and `last_non_null_value` supports retraction (`UPDATE_BEFORE` and 
`DELETE`), others aggregate functions do not support retraction.
+Only `sum`, `product`, `collect`, `merge_map`, `nested_update`, `last_value` 
and `last_non_null_value` supports retraction (`UPDATE_BEFORE` and `DELETE`), 
others aggregate functions do not support retraction.
 If you allow some functions to ignore retraction messages, you can configure:
 `'fields.${field_name}.ignore-retract'='true'`.
 
diff --git 
a/paimon-core/src/main/java/org/apache/paimon/mergetree/compact/aggregate/FieldAggregator.java
 
b/paimon-core/src/main/java/org/apache/paimon/mergetree/compact/aggregate/FieldAggregator.java
index 8d0f5b79f..b3fb7b0eb 100644
--- 
a/paimon-core/src/main/java/org/apache/paimon/mergetree/compact/aggregate/FieldAggregator.java
+++ 
b/paimon-core/src/main/java/org/apache/paimon/mergetree/compact/aggregate/FieldAggregator.java
@@ -89,9 +89,6 @@ public abstract class FieldAggregator implements Serializable 
{
                     case FieldFirstNonNullValueAgg.LEGACY_NAME:
                         fieldAggregator = new 
FieldFirstNonNullValueAgg(fieldType);
                         break;
-                    case FieldCountAgg.NAME:
-                        fieldAggregator = new FieldCountAgg(fieldType);
-                        break;
                     case FieldProductAgg.NAME:
                         fieldAggregator = new FieldProductAgg(fieldType);
                         break;
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
deleted file mode 100644
index 0c1d8c094..000000000
--- 
a/paimon-core/src/main/java/org/apache/paimon/mergetree/compact/aggregate/FieldCountAgg.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.paimon.mergetree.compact.aggregate;
-
-import org.apache.paimon.types.DataType;
-
-/** count value aggregate a field of a row. */
-public class FieldCountAgg extends FieldAggregator {
-
-    public static final String NAME = "count";
-
-    public FieldCountAgg(DataType dataType) {
-        super(dataType);
-    }
-
-    @Override
-    String name() {
-        return NAME;
-    }
-
-    @Override
-    public Object agg(Object accumulator, Object inputField) {
-
-        if (accumulator != null && inputField == null) {
-            return accumulator;
-        }
-        // ordered by type root definition
-        switch (fieldType.getTypeRoot()) {
-            case TINYINT:
-                return accumulator == null
-                        ? (inputField == null ? (byte) 0 : (byte) 1)
-                        : (byte) ((byte) accumulator + 1);
-            case SMALLINT:
-                return accumulator == null
-                        ? (inputField == null ? (short) 0 : (short) 1)
-                        : (short) ((short) accumulator + 1);
-            case INTEGER:
-                return accumulator == null ? (inputField == null ? 0 : 1) : 
(int) accumulator + 1;
-            case BIGINT:
-                return accumulator == null
-                        ? (inputField == null ? 0L : 1L)
-                        : (long) accumulator + 1L;
-            default:
-                String msg =
-                        String.format(
-                                "type %s not support in %s",
-                                fieldType.getTypeRoot().toString(), 
this.getClass().getName());
-                throw new IllegalArgumentException(msg);
-        }
-    }
-
-    @Override
-    public Object retract(Object accumulator, Object inputField) {
-
-        if (accumulator != null && inputField == null) {
-            return accumulator;
-        }
-
-        // ordered by type root definition
-        switch (fieldType.getTypeRoot()) {
-            case TINYINT:
-                return accumulator == null
-                        ? (inputField == null ? (byte) 0 : (byte) -1)
-                        : (byte) ((byte) accumulator - 1);
-            case SMALLINT:
-                return accumulator == null
-                        ? (inputField == null ? (short) 0 : (short) -1)
-                        : (short) ((short) accumulator - 1);
-            case INTEGER:
-                return accumulator == null ? (inputField == null ? 0 : -1) : 
(int) accumulator - 1;
-
-            case BIGINT:
-                return accumulator == null
-                        ? (inputField == null ? 0L : -1L)
-                        : (long) accumulator - 1L;
-            default:
-                String msg =
-                        String.format(
-                                "type %s not support in %s",
-                                fieldType.getTypeRoot().toString(), 
this.getClass().getName());
-                throw new IllegalArgumentException(msg);
-        }
-    }
-}
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 7fae50622..b0ae2c5c0 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
@@ -175,37 +175,6 @@ public class FieldAggregatorTest {
         assertThat(fieldSumAgg.retract(null, 5)).isEqualTo(-5);
     }
 
-    @Test
-    public void testFieldCountIntAgg() {
-        FieldCountAgg fieldCountAggInt = new FieldCountAgg(new IntType());
-        assertThat(fieldCountAggInt.agg(null, null)).isEqualTo(0);
-        assertThat(fieldCountAggInt.agg(1, null)).isEqualTo(1);
-        assertThat(fieldCountAggInt.agg(null, 15)).isEqualTo(1);
-        assertThat(fieldCountAggInt.agg(1, 0)).isEqualTo(2);
-        assertThat(fieldCountAggInt.agg(3, 6)).isEqualTo(4);
-
-        FieldCountAgg fieldCountAggLong = new FieldCountAgg(new BigIntType());
-        assertThat(fieldCountAggLong.agg(null, null)).isEqualTo(0L);
-        assertThat(fieldCountAggLong.agg((long) 1, null)).isEqualTo((long) 1);
-        assertThat(fieldCountAggLong.agg(null, (long) 15)).isEqualTo(1L);
-        assertThat(fieldCountAggLong.agg((long) 1, 0)).isEqualTo((long) 2);
-        assertThat(fieldCountAggLong.agg((long) 3, (long) 6)).isEqualTo((long) 
4);
-
-        FieldCountAgg fieldCountAggByte = new FieldCountAgg(new TinyIntType());
-        assertThat(fieldCountAggByte.agg(null, null)).isEqualTo((byte) 0);
-        assertThat(fieldCountAggByte.agg((byte) 1, null)).isEqualTo((byte) 1);
-        assertThat(fieldCountAggByte.agg(null, (byte) 15)).isEqualTo((byte) 1);
-        assertThat(fieldCountAggByte.agg((byte) 1, 0)).isEqualTo((byte) 2);
-        assertThat(fieldCountAggByte.agg((byte) 3, (byte) 6)).isEqualTo((byte) 
4);
-
-        FieldCountAgg fieldCountAggShort = new FieldCountAgg(new 
SmallIntType());
-        assertThat(fieldCountAggShort.agg(null, null)).isEqualTo((short) 0);
-        assertThat(fieldCountAggShort.agg((short) 1, null)).isEqualTo((short) 
1);
-        assertThat(fieldCountAggShort.agg(null, (short) 15)).isEqualTo((short) 
1);
-        assertThat(fieldCountAggShort.agg((short) 1, 0)).isEqualTo((short) 2);
-        assertThat(fieldCountAggShort.agg((short) 3, (short) 
6)).isEqualTo((short) 4);
-    }
-
     @Test
     public void testFieldProductIntAgg() {
         FieldProductAgg fieldProductAgg = new FieldProductAgg(new IntType());

Reply via email to