OpenSearchFunctions.java

1
/*
2
 * Copyright OpenSearch Contributors
3
 * SPDX-License-Identifier: Apache-2.0
4
 */
5
6
package org.opensearch.sql.expression.function;
7
8
import static org.opensearch.sql.data.type.ExprCoreType.STRING;
9
import static org.opensearch.sql.data.type.ExprCoreType.STRUCT;
10
11
import com.google.common.collect.ImmutableMap;
12
import java.util.List;
13
import java.util.stream.Collectors;
14
import lombok.experimental.UtilityClass;
15
import org.opensearch.sql.data.model.ExprValue;
16
import org.opensearch.sql.data.type.ExprCoreType;
17
import org.opensearch.sql.data.type.ExprType;
18
import org.opensearch.sql.expression.Expression;
19
import org.opensearch.sql.expression.FunctionExpression;
20
import org.opensearch.sql.expression.NamedArgumentExpression;
21
import org.opensearch.sql.expression.env.Environment;
22
23
@UtilityClass
24
public class OpenSearchFunctions {
25
  /**
26
   * Add functions specific to OpenSearch to repository.
27
   */
28
  public void register(BuiltinFunctionRepository repository) {
29 1 1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED
    repository.register(match_bool_prefix());
30 1 1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED
    repository.register(match());
31 1 1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED
    repository.register(multi_match());
32 1 1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED
    repository.register(simple_query_string());
33 1 1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED
    repository.register(query());
34 1 1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED
    repository.register(query_string());
35
    // Register MATCHPHRASE as MATCH_PHRASE as well for backwards
36
    // compatibility.
37 1 1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED
    repository.register(match_phrase(BuiltinFunctionName.MATCH_PHRASE));
38 1 1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED
    repository.register(match_phrase(BuiltinFunctionName.MATCHPHRASE));
39 1 1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED
    repository.register(match_phrase_prefix());
40
  }
41
42
  private static FunctionResolver match_bool_prefix() {
43
    FunctionName name = BuiltinFunctionName.MATCH_BOOL_PREFIX.getName();
44 1 1. match_bool_prefix : replaced return value with null for org/opensearch/sql/expression/function/OpenSearchFunctions::match_bool_prefix → KILLED
    return new RelevanceFunctionResolver(name, STRING);
45
  }
46
47
  private static FunctionResolver match() {
48
    FunctionName funcName = BuiltinFunctionName.MATCH.getName();
49 1 1. match : replaced return value with null for org/opensearch/sql/expression/function/OpenSearchFunctions::match → KILLED
    return new RelevanceFunctionResolver(funcName, STRING);
50
  }
51
52
  private static FunctionResolver match_phrase_prefix() {
53
    FunctionName funcName = BuiltinFunctionName.MATCH_PHRASE_PREFIX.getName();
54 1 1. match_phrase_prefix : replaced return value with null for org/opensearch/sql/expression/function/OpenSearchFunctions::match_phrase_prefix → KILLED
    return new RelevanceFunctionResolver(funcName, STRING);
55
  }
56
57
  private static FunctionResolver match_phrase(BuiltinFunctionName matchPhrase) {
58
    FunctionName funcName = matchPhrase.getName();
59 1 1. match_phrase : replaced return value with null for org/opensearch/sql/expression/function/OpenSearchFunctions::match_phrase → KILLED
    return new RelevanceFunctionResolver(funcName, STRING);
60
  }
61
62
  private static FunctionResolver multi_match() {
63
    FunctionName funcName = BuiltinFunctionName.MULTI_MATCH.getName();
64 1 1. multi_match : replaced return value with null for org/opensearch/sql/expression/function/OpenSearchFunctions::multi_match → KILLED
    return new RelevanceFunctionResolver(funcName, STRUCT);
65
  }
66
67
  private static FunctionResolver simple_query_string() {
68
    FunctionName funcName = BuiltinFunctionName.SIMPLE_QUERY_STRING.getName();
69 1 1. simple_query_string : replaced return value with null for org/opensearch/sql/expression/function/OpenSearchFunctions::simple_query_string → KILLED
    return new RelevanceFunctionResolver(funcName, STRUCT);
70
  }
71
72
  private static FunctionResolver query() {
73
    FunctionName funcName = BuiltinFunctionName.QUERY.getName();
74 1 1. query : replaced return value with null for org/opensearch/sql/expression/function/OpenSearchFunctions::query → KILLED
    return new RelevanceFunctionResolver(funcName, STRING);
75
  }
76
77
  private static FunctionResolver query_string() {
78
    FunctionName funcName = BuiltinFunctionName.QUERY_STRING.getName();
79 1 1. query_string : replaced return value with null for org/opensearch/sql/expression/function/OpenSearchFunctions::query_string → KILLED
    return new RelevanceFunctionResolver(funcName, STRUCT);
80
  }
81
82
  public static class OpenSearchFunction extends FunctionExpression {
83
    private final FunctionName functionName;
84
    private final List<Expression> arguments;
85
86
    /**
87
     * Required argument constructor.
88
     * @param functionName name of the function
89
     * @param arguments a list of expressions
90
     */
91
    public OpenSearchFunction(FunctionName functionName, List<Expression> arguments) {
92
      super(functionName, arguments);
93
      this.functionName = functionName;
94
      this.arguments = arguments;
95
    }
96
97
    @Override
98
    public ExprValue valueOf(Environment<Expression, ExprValue> valueEnv) {
99
      throw new UnsupportedOperationException(String.format(
100
          "OpenSearch defined function [%s] is only supported in WHERE and HAVING clause.",
101
          functionName));
102
    }
103
104
    @Override
105
    public ExprType type() {
106 1 1. type : replaced return value with null for org/opensearch/sql/expression/function/OpenSearchFunctions$OpenSearchFunction::type → KILLED
      return ExprCoreType.BOOLEAN;
107
    }
108
109
    @Override
110
    public String toString() {
111
      List<String> args = arguments.stream()
112 1 1. lambda$toString$0 : replaced return value with "" for org/opensearch/sql/expression/function/OpenSearchFunctions$OpenSearchFunction::lambda$toString$0 → KILLED
          .map(arg -> String.format("%s=%s", ((NamedArgumentExpression) arg)
113
              .getArgName(), ((NamedArgumentExpression) arg).getValue().toString()))
114
          .collect(Collectors.toList());
115 1 1. toString : replaced return value with "" for org/opensearch/sql/expression/function/OpenSearchFunctions$OpenSearchFunction::toString → KILLED
      return String.format("%s(%s)", functionName, String.join(", ", args));
116
    }
117
  }
118
}

Mutations

29

1.1
Location : register
Killed by : none
removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED

30

1.1
Location : register
Killed by : none
removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED

31

1.1
Location : register
Killed by : none
removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED

32

1.1
Location : register
Killed by : none
removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED

33

1.1
Location : register
Killed by : none
removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED

34

1.1
Location : register
Killed by : none
removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED

37

1.1
Location : register
Killed by : none
removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED

38

1.1
Location : register
Killed by : none
removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED

39

1.1
Location : register
Killed by : none
removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED

44

1.1
Location : match_bool_prefix
Killed by : org.opensearch.sql.expression.operator.convert.TypeCastOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.convert.TypeCastOperatorTest]/[method:castStringToLongException()]
replaced return value with null for org/opensearch/sql/expression/function/OpenSearchFunctions::match_bool_prefix → KILLED

49

1.1
Location : match
Killed by : org.opensearch.sql.expression.operator.convert.TypeCastOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.convert.TypeCastOperatorTest]/[method:castStringToLongException()]
replaced return value with null for org/opensearch/sql/expression/function/OpenSearchFunctions::match → KILLED

54

1.1
Location : match_phrase_prefix
Killed by : org.opensearch.sql.expression.operator.convert.TypeCastOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.convert.TypeCastOperatorTest]/[method:castStringToLongException()]
replaced return value with null for org/opensearch/sql/expression/function/OpenSearchFunctions::match_phrase_prefix → KILLED

59

1.1
Location : match_phrase
Killed by : org.opensearch.sql.expression.operator.convert.TypeCastOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.convert.TypeCastOperatorTest]/[method:castStringToLongException()]
replaced return value with null for org/opensearch/sql/expression/function/OpenSearchFunctions::match_phrase → KILLED

64

1.1
Location : multi_match
Killed by : org.opensearch.sql.expression.operator.convert.TypeCastOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.convert.TypeCastOperatorTest]/[method:castStringToLongException()]
replaced return value with null for org/opensearch/sql/expression/function/OpenSearchFunctions::multi_match → KILLED

69

1.1
Location : simple_query_string
Killed by : org.opensearch.sql.expression.operator.convert.TypeCastOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.convert.TypeCastOperatorTest]/[method:castStringToLongException()]
replaced return value with null for org/opensearch/sql/expression/function/OpenSearchFunctions::simple_query_string → KILLED

74

1.1
Location : query
Killed by : org.opensearch.sql.expression.operator.convert.TypeCastOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.convert.TypeCastOperatorTest]/[method:castStringToLongException()]
replaced return value with null for org/opensearch/sql/expression/function/OpenSearchFunctions::query → KILLED

79

1.1
Location : query_string
Killed by : org.opensearch.sql.expression.operator.convert.TypeCastOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.convert.TypeCastOperatorTest]/[method:castStringToLongException()]
replaced return value with null for org/opensearch/sql/expression/function/OpenSearchFunctions::query_string → KILLED

106

1.1
Location : type
Killed by : org.opensearch.sql.expression.function.OpenSearchFunctionsTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.function.OpenSearchFunctionsTest]/[method:match_phrase()]
replaced return value with null for org/opensearch/sql/expression/function/OpenSearchFunctions$OpenSearchFunction::type → KILLED

112

1.1
Location : lambda$toString$0
Killed by : org.opensearch.sql.expression.function.OpenSearchFunctionsTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.function.OpenSearchFunctionsTest]/[method:query()]
replaced return value with "" for org/opensearch/sql/expression/function/OpenSearchFunctions$OpenSearchFunction::lambda$toString$0 → KILLED

115

1.1
Location : toString
Killed by : org.opensearch.sql.expression.function.OpenSearchFunctionsTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.function.OpenSearchFunctionsTest]/[method:query()]
replaced return value with "" for org/opensearch/sql/expression/function/OpenSearchFunctions$OpenSearchFunction::toString → KILLED

Active mutators

Tests examined


Report generated by PIT 1.9.0