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 14a158a3a [core] Support Numberic type to FieldCountAgg (#3552)
14a158a3a is described below
commit 14a158a3a67258cbd0bdcf37dbbc6cd412e86010
Author: xuzifu666 <[email protected]>
AuthorDate: Thu Jun 20 09:39:12 2024 +0800
[core] Support Numberic type to FieldCountAgg (#3552)
---
.../mergetree/compact/aggregate/FieldCountAgg.java | 12 ++++++++
.../compact/aggregate/FieldAggregatorTest.java | 33 ++++++++++++++++++----
2 files changed, 39 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 5fb7b2bb9..87d4bacf3 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
@@ -42,6 +42,12 @@ public class FieldCountAgg extends FieldAggregator {
} else {
// ordered by type root definition
switch (fieldType.getTypeRoot()) {
+ case TINYINT:
+ count = (byte) ((byte) accumulator + 1);
+ break;
+ case SMALLINT:
+ count = (short) ((short) accumulator + 1);
+ break;
case INTEGER:
count = (int) accumulator + 1;
break;
@@ -63,6 +69,12 @@ public class FieldCountAgg extends FieldAggregator {
} else {
// ordered by type root definition
switch (fieldType.getTypeRoot()) {
+ case TINYINT:
+ count = (byte) ((byte) accumulator - 1);
+ break;
+ case SMALLINT:
+ count = (short) ((short) accumulator - 1);
+ break;
case INTEGER:
count = (int) accumulator - 1;
break;
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 5bca65ed7..8ca08e0aa 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
@@ -154,12 +154,33 @@ public class FieldAggregatorTest {
@Test
public void testFieldCountIntAgg() {
- FieldCountAgg fieldCountAgg = new FieldCountAgg(new IntType());
- 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);
+ 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(0);
+ assertThat(fieldCountAggLong.agg((long) 1, null)).isEqualTo((long) 1);
+ assertThat(fieldCountAggLong.agg(null, (long) 15)).isEqualTo(1);
+ 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(0);
+ assertThat(fieldCountAggByte.agg((byte) 1, null)).isEqualTo((byte) 1);
+ assertThat(fieldCountAggByte.agg(null, (byte) 15)).isEqualTo(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(0);
+ assertThat(fieldCountAggShort.agg((short) 1, null)).isEqualTo((short)
1);
+ assertThat(fieldCountAggShort.agg(null, (short) 15)).isEqualTo(1);
+ assertThat(fieldCountAggShort.agg((short) 1, 0)).isEqualTo((short) 2);
+ assertThat(fieldCountAggShort.agg((short) 3, (short)
6)).isEqualTo((short) 4);
}
@Test