1 | /* | |
2 | * Copyright OpenSearch Contributors | |
3 | * SPDX-License-Identifier: Apache-2.0 | |
4 | */ | |
5 | ||
6 | package org.opensearch.sql.expression.function; | |
7 | ||
8 | import java.util.List; | |
9 | import lombok.Getter; | |
10 | import lombok.RequiredArgsConstructor; | |
11 | import org.apache.commons.lang3.tuple.Pair; | |
12 | import org.opensearch.sql.data.type.ExprCoreType; | |
13 | import org.opensearch.sql.data.type.ExprType; | |
14 | import org.opensearch.sql.exception.SemanticCheckException; | |
15 | ||
16 | @RequiredArgsConstructor | |
17 | public class RelevanceFunctionResolver | |
18 | implements FunctionResolver { | |
19 | ||
20 | @Getter | |
21 | private final FunctionName functionName; | |
22 | ||
23 | @Getter | |
24 | private final ExprType declaredFirstParamType; | |
25 | ||
26 | @Override | |
27 | public Pair<FunctionSignature, FunctionBuilder> resolve(FunctionSignature unresolvedSignature) { | |
28 |
1
1. resolve : negated conditional → KILLED |
if (!unresolvedSignature.getFunctionName().equals(functionName)) { |
29 | throw new SemanticCheckException(String.format("Expected '%s' but got '%s'", | |
30 | functionName.getFunctionName(), unresolvedSignature.getFunctionName().getFunctionName())); | |
31 | } | |
32 | List<ExprType> paramTypes = unresolvedSignature.getParamTypeList(); | |
33 | ExprType providedFirstParamType = paramTypes.get(0); | |
34 | ||
35 | // Check if the first parameter is of the specified type. | |
36 |
1
1. resolve : negated conditional → KILLED |
if (!declaredFirstParamType.equals(providedFirstParamType)) { |
37 | throw new SemanticCheckException( | |
38 | getWrongParameterErrorMessage(0, providedFirstParamType, declaredFirstParamType)); | |
39 | } | |
40 | ||
41 | // Check if all but the first parameter are of type STRING. | |
42 |
2
1. resolve : changed conditional boundary → KILLED 2. resolve : negated conditional → KILLED |
for (int i = 1; i < paramTypes.size(); i++) { |
43 | ExprType paramType = paramTypes.get(i); | |
44 |
1
1. resolve : negated conditional → KILLED |
if (!ExprCoreType.STRING.equals(paramType)) { |
45 | throw new SemanticCheckException( | |
46 | getWrongParameterErrorMessage(i, paramType, ExprCoreType.STRING)); | |
47 | } | |
48 | } | |
49 | ||
50 | FunctionBuilder buildFunction = | |
51 |
1
1. lambda$resolve$0 : replaced return value with null for org/opensearch/sql/expression/function/RelevanceFunctionResolver::lambda$resolve$0 → KILLED |
args -> new OpenSearchFunctions.OpenSearchFunction(functionName, args); |
52 |
1
1. resolve : replaced return value with null for org/opensearch/sql/expression/function/RelevanceFunctionResolver::resolve → KILLED |
return Pair.of(unresolvedSignature, buildFunction); |
53 | } | |
54 | ||
55 | /** Returns a helpful error message when expected parameter type does not match the | |
56 | * specified parameter type. | |
57 | * | |
58 | * @param i 0-based index of the parameter in a function signature. | |
59 | * @param paramType the type of the ith parameter at run-time. | |
60 | * @param expectedType the expected type of the ith parameter | |
61 | * @return A user-friendly error message that informs of the type difference. | |
62 | */ | |
63 | private String getWrongParameterErrorMessage(int i, ExprType paramType, ExprType expectedType) { | |
64 |
1
1. getWrongParameterErrorMessage : replaced return value with "" for org/opensearch/sql/expression/function/RelevanceFunctionResolver::getWrongParameterErrorMessage → KILLED |
return String.format("Expected type %s instead of %s for parameter #%d", |
65 |
1
1. getWrongParameterErrorMessage : Replaced integer addition with subtraction → KILLED |
expectedType.typeName(), paramType.typeName(), i + 1); |
66 | } | |
67 | } | |
Mutations | ||
28 |
1.1 |
|
36 |
1.1 |
|
42 |
1.1 2.2 |
|
44 |
1.1 |
|
51 |
1.1 |
|
52 |
1.1 |
|
64 |
1.1 |
|
65 |
1.1 |