Skip to content

Commit ca27f87

Browse files
guojn1githubgxll
authored andcommitted
[fix][runtime] Add first_val_agg function
1 parent dd43a5a commit ca27f87

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

parser/src/main/java/io/dingodb/expr/parser/DefaultFunFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import io.dingodb.expr.runtime.op.VariadicOp;
3737
import io.dingodb.expr.runtime.op.aggregation.CountAgg;
3838
import io.dingodb.expr.runtime.op.aggregation.CountAllAgg;
39+
import io.dingodb.expr.runtime.op.aggregation.FirstValueAgg;
3940
import io.dingodb.expr.runtime.op.aggregation.MaxAgg;
4041
import io.dingodb.expr.runtime.op.aggregation.MinAgg;
4142
import io.dingodb.expr.runtime.op.aggregation.SingleValueAgg;
@@ -311,6 +312,7 @@ public DefaultFunFactory(@NonNull ExprConfig config) {
311312
registerUnaryFun(SumAgg.NAME, Exprs.SUM_AGG);
312313
registerUnaryFun(Sum0Agg.NAME, Exprs.SUM0_AGG);
313314
registerUnaryFun(SingleValueAgg.NAME, Exprs.SINGLE_VALUE_AGG);
315+
registerUnaryFun(FirstValueAgg.NAME, Exprs.FIRST_VALUE_AGG);
314316
}
315317

316318
@Override

runtime/src/main/java/io/dingodb/expr/runtime/expr/Exprs.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import io.dingodb.expr.runtime.op.VariadicOp;
4444
import io.dingodb.expr.runtime.op.aggregation.CountAgg;
4545
import io.dingodb.expr.runtime.op.aggregation.CountAllAgg;
46+
import io.dingodb.expr.runtime.op.aggregation.FirstValueAgg;
4647
import io.dingodb.expr.runtime.op.aggregation.MaxAgg;
4748
import io.dingodb.expr.runtime.op.aggregation.MinAgg;
4849
import io.dingodb.expr.runtime.op.aggregation.SingleValueAgg;
@@ -353,6 +354,7 @@ public final class Exprs {
353354
public static final SumAgg SUM_AGG = SumAgg.INSTANCE;
354355
public static final Sum0Agg SUM0_AGG = Sum0Agg.INSTANCE;
355356
public static final SingleValueAgg SINGLE_VALUE_AGG = SingleValueAgg.INSTANCE;
357+
public static final FirstValueAgg FIRST_VALUE_AGG = FirstValueAgg.INSTANCE;
356358

357359
private Exprs() {
358360
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2021 DataCanvas
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.dingodb.expr.runtime.op.aggregation;
18+
19+
import io.dingodb.expr.common.type.Type;
20+
import io.dingodb.expr.runtime.ExprConfig;
21+
import lombok.AccessLevel;
22+
import lombok.Getter;
23+
import lombok.RequiredArgsConstructor;
24+
import org.checkerframework.checker.nullness.qual.NonNull;
25+
import org.checkerframework.checker.nullness.qual.Nullable;
26+
27+
import java.io.Serial;
28+
29+
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
30+
public class FirstValueAgg extends UnaryAgg {
31+
public static final String NAME = "FIRST_VALUE_AGG";
32+
33+
public static final FirstValueAgg INSTANCE = new FirstValueAgg(null);
34+
35+
@Serial
36+
private static final long serialVersionUID = -1444678046223537450L;
37+
38+
@Getter
39+
private final Type type;
40+
41+
@Override
42+
public Object first(@Nullable Object value, ExprConfig config) {
43+
return value;
44+
}
45+
46+
@Override
47+
public Object add(@Nullable Object var, @Nullable Object value, ExprConfig config) {
48+
return value;
49+
}
50+
51+
@Override
52+
public Object merge(@NonNull Object var1, @NonNull Object var2, ExprConfig config) {
53+
return null;
54+
}
55+
56+
@Override
57+
public Object emptyValue() {
58+
return null;
59+
}
60+
}

0 commit comments

Comments
 (0)