1 | /* | |
2 | * Copyright OpenSearch Contributors | |
3 | * SPDX-License-Identifier: Apache-2.0 | |
4 | */ | |
5 | ||
6 | ||
7 | package org.opensearch.sql.expression; | |
8 | ||
9 | import com.google.common.base.Strings; | |
10 | import lombok.AllArgsConstructor; | |
11 | import lombok.EqualsAndHashCode; | |
12 | import lombok.Getter; | |
13 | import lombok.RequiredArgsConstructor; | |
14 | import org.opensearch.sql.data.model.ExprValue; | |
15 | import org.opensearch.sql.data.type.ExprType; | |
16 | import org.opensearch.sql.expression.env.Environment; | |
17 | ||
18 | /** | |
19 | * Named expression that represents expression with name. | |
20 | * Please see more details in associated unresolved expression operator | |
21 | * {@link org.opensearch.sql.ast.expression.Alias}. | |
22 | */ | |
23 | @AllArgsConstructor | |
24 | @EqualsAndHashCode | |
25 | @Getter | |
26 | @RequiredArgsConstructor | |
27 | public class NamedExpression implements Expression { | |
28 | ||
29 | /** | |
30 | * Expression name. | |
31 | */ | |
32 | private final String name; | |
33 | ||
34 | /** | |
35 | * Expression that being named. | |
36 | */ | |
37 | private final Expression delegated; | |
38 | ||
39 | /** | |
40 | * Optional alias. | |
41 | */ | |
42 | private String alias; | |
43 | ||
44 | @Override | |
45 | public ExprValue valueOf(Environment<Expression, ExprValue> valueEnv) { | |
46 |
1
1. valueOf : replaced return value with null for org/opensearch/sql/expression/NamedExpression::valueOf → KILLED |
return delegated.valueOf(valueEnv); |
47 | } | |
48 | ||
49 | @Override | |
50 | public ExprType type() { | |
51 |
1
1. type : replaced return value with null for org/opensearch/sql/expression/NamedExpression::type → KILLED |
return delegated.type(); |
52 | } | |
53 | ||
54 | /** | |
55 | * Get expression name using name or its alias (if it's present). | |
56 | * @return expression name | |
57 | */ | |
58 | public String getNameOrAlias() { | |
59 |
2
1. getNameOrAlias : negated conditional → KILLED 2. getNameOrAlias : replaced return value with "" for org/opensearch/sql/expression/NamedExpression::getNameOrAlias → KILLED |
return Strings.isNullOrEmpty(alias) ? name : alias; |
60 | } | |
61 | ||
62 | @Override | |
63 | public <T, C> T accept(ExpressionNodeVisitor<T, C> visitor, C context) { | |
64 |
1
1. accept : replaced return value with null for org/opensearch/sql/expression/NamedExpression::accept → KILLED |
return visitor.visitNamed(this, context); |
65 | } | |
66 | ||
67 | @Override | |
68 | public String toString() { | |
69 |
1
1. toString : replaced return value with "" for org/opensearch/sql/expression/NamedExpression::toString → KILLED |
return getNameOrAlias(); |
70 | } | |
71 | ||
72 | } | |
Mutations | ||
46 |
1.1 |
|
51 |
1.1 |
|
59 |
1.1 2.2 |
|
64 |
1.1 |
|
69 |
1.1 |