Skip to content

Commit

Permalink
[core] Fix FieldCountAgg null value init process (apache#3536)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuzifu666 authored Jun 19, 2024
1 parent a0558f1 commit 48b0828
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ String name() {
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()) {
Expand All @@ -59,7 +59,7 @@ public Object agg(Object accumulator, Object inputField) {
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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,11 @@ public void testFieldSumIntAgg() {
@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
Expand Down

0 comments on commit 48b0828

Please sign in to comment.