1 | /* | |
2 | * Copyright OpenSearch Contributors | |
3 | * SPDX-License-Identifier: Apache-2.0 | |
4 | */ | |
5 | ||
6 | ||
7 | package org.opensearch.sql.ast.expression; | |
8 | ||
9 | import java.util.Collections; | |
10 | import java.util.List; | |
11 | import lombok.EqualsAndHashCode; | |
12 | import lombok.Getter; | |
13 | import lombok.RequiredArgsConstructor; | |
14 | import lombok.Setter; | |
15 | import lombok.experimental.Accessors; | |
16 | import org.opensearch.sql.ast.AbstractNodeVisitor; | |
17 | import org.opensearch.sql.common.utils.StringUtils; | |
18 | ||
19 | /** | |
20 | * Expression node of aggregate functions. | |
21 | * Params include aggregate function name (AVG, SUM, MAX etc.) and the field to aggregate. | |
22 | */ | |
23 | @Getter | |
24 | @EqualsAndHashCode(callSuper = false) | |
25 | @RequiredArgsConstructor | |
26 | public class AggregateFunction extends UnresolvedExpression { | |
27 | private final String funcName; | |
28 | private final UnresolvedExpression field; | |
29 | private final List<UnresolvedExpression> argList; | |
30 | @Setter | |
31 | @Accessors(fluent = true) | |
32 | private UnresolvedExpression condition; | |
33 | private Boolean distinct = false; | |
34 | ||
35 | /** | |
36 | * Constructor. | |
37 | * @param funcName function name. | |
38 | * @param field {@link UnresolvedExpression}. | |
39 | */ | |
40 | public AggregateFunction(String funcName, UnresolvedExpression field) { | |
41 | this.funcName = funcName; | |
42 | this.field = field; | |
43 | this.argList = Collections.emptyList(); | |
44 | } | |
45 | ||
46 | /** | |
47 | * Constructor. | |
48 | * @param funcName function name. | |
49 | * @param field {@link UnresolvedExpression}. | |
50 | * @param distinct whether distinct field is specified or not. | |
51 | */ | |
52 | public AggregateFunction(String funcName, UnresolvedExpression field, Boolean distinct) { | |
53 | this.funcName = funcName; | |
54 | this.field = field; | |
55 | this.argList = Collections.emptyList(); | |
56 | this.distinct = distinct; | |
57 | } | |
58 | ||
59 | @Override | |
60 | public List<UnresolvedExpression> getChild() { | |
61 |
1
1. getChild : replaced return value with Collections.emptyList for org/opensearch/sql/ast/expression/AggregateFunction::getChild → NO_COVERAGE |
return Collections.singletonList(field); |
62 | } | |
63 | ||
64 | @Override | |
65 | public <R, C> R accept(AbstractNodeVisitor<R, C> nodeVisitor, C context) { | |
66 |
1
1. accept : replaced return value with null for org/opensearch/sql/ast/expression/AggregateFunction::accept → KILLED |
return nodeVisitor.visitAggregateFunction(this, context); |
67 | } | |
68 | ||
69 | @Override | |
70 | public String toString() { | |
71 |
1
1. toString : replaced return value with "" for org/opensearch/sql/ast/expression/AggregateFunction::toString → KILLED |
return StringUtils.format("%s(%s)", funcName, field); |
72 | } | |
73 | } | |
Mutations | ||
61 |
1.1 |
|
66 |
1.1 |
|
71 |
1.1 |