1 | /* | |
2 | * Copyright OpenSearch Contributors | |
3 | * SPDX-License-Identifier: Apache-2.0 | |
4 | */ | |
5 | ||
6 | package org.opensearch.sql.expression.parse; | |
7 | ||
8 | import com.google.common.collect.ImmutableList; | |
9 | import lombok.EqualsAndHashCode; | |
10 | import lombok.Getter; | |
11 | import lombok.ToString; | |
12 | import org.opensearch.sql.data.model.ExprValue; | |
13 | import org.opensearch.sql.data.model.ExprValueUtils; | |
14 | import org.opensearch.sql.data.type.ExprCoreType; | |
15 | import org.opensearch.sql.data.type.ExprType; | |
16 | import org.opensearch.sql.exception.ExpressionEvaluationException; | |
17 | import org.opensearch.sql.exception.SemanticCheckException; | |
18 | import org.opensearch.sql.expression.Expression; | |
19 | import org.opensearch.sql.expression.ExpressionNodeVisitor; | |
20 | import org.opensearch.sql.expression.FunctionExpression; | |
21 | import org.opensearch.sql.expression.env.Environment; | |
22 | import org.opensearch.sql.expression.function.FunctionName; | |
23 | ||
24 | /** | |
25 | * ParseExpression. | |
26 | */ | |
27 | @EqualsAndHashCode | |
28 | @ToString | |
29 | public abstract class ParseExpression extends FunctionExpression { | |
30 | @Getter | |
31 | protected final Expression sourceField; | |
32 | protected final Expression pattern; | |
33 | @Getter | |
34 | protected final Expression identifier; | |
35 | protected final String identifierStr; | |
36 | ||
37 | /** | |
38 | * ParseExpression. | |
39 | * | |
40 | * @param functionName name of function expression | |
41 | * @param sourceField source text field | |
42 | * @param pattern pattern used for parsing | |
43 | * @param identifier derived field | |
44 | */ | |
45 | public ParseExpression(String functionName, Expression sourceField, Expression pattern, | |
46 | Expression identifier) { | |
47 | super(FunctionName.of(functionName), ImmutableList.of(sourceField, pattern, identifier)); | |
48 | this.sourceField = sourceField; | |
49 | this.pattern = pattern; | |
50 | this.identifier = identifier; | |
51 | this.identifierStr = identifier.valueOf().stringValue(); | |
52 | } | |
53 | ||
54 | @Override | |
55 | public ExprValue valueOf(Environment<Expression, ExprValue> valueEnv) { | |
56 | ExprValue value = valueEnv.resolve(sourceField); | |
57 |
2
1. valueOf : negated conditional → KILLED 2. valueOf : negated conditional → KILLED |
if (value.isNull() || value.isMissing()) { |
58 |
1
1. valueOf : replaced return value with null for org/opensearch/sql/expression/parse/ParseExpression::valueOf → KILLED |
return ExprValueUtils.nullValue(); |
59 | } | |
60 | try { | |
61 |
1
1. valueOf : replaced return value with null for org/opensearch/sql/expression/parse/ParseExpression::valueOf → KILLED |
return parseValue(value); |
62 | } catch (ExpressionEvaluationException e) { | |
63 | throw new SemanticCheckException( | |
64 | String.format("failed to parse field \"%s\" with type [%s]", sourceField, value.type())); | |
65 | } | |
66 | } | |
67 | ||
68 | @Override | |
69 | public ExprType type() { | |
70 |
1
1. type : replaced return value with null for org/opensearch/sql/expression/parse/ParseExpression::type → KILLED |
return ExprCoreType.STRING; |
71 | } | |
72 | ||
73 | @Override | |
74 | public <T, C> T accept(ExpressionNodeVisitor<T, C> visitor, C context) { | |
75 |
1
1. accept : replaced return value with null for org/opensearch/sql/expression/parse/ParseExpression::accept → KILLED |
return visitor.visitParse(this, context); |
76 | } | |
77 | ||
78 | abstract ExprValue parseValue(ExprValue value) throws ExpressionEvaluationException; | |
79 | } | |
Mutations | ||
57 |
1.1 2.2 |
|
58 |
1.1 |
|
61 |
1.1 |
|
70 |
1.1 |
|
75 |
1.1 |