Skip to content

Commit

Permalink
[fix] Remove count function
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzhuoyu committed Aug 11, 2024
1 parent 875cadb commit adbe0b9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 137 deletions.
12 changes: 9 additions & 3 deletions docs/content/primary-key-table/merge-engine/aggregation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -260,7 +266,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'`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ public static FieldAggregator createFieldAggregator(
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;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -156,37 +156,6 @@ public void testFieldSumIntAgg() {
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());
Expand Down

0 comments on commit adbe0b9

Please sign in to comment.