FunctionSignature.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 java.util.List;
9
import java.util.stream.Collectors;
10
import lombok.EqualsAndHashCode;
11
import lombok.Getter;
12
import lombok.RequiredArgsConstructor;
13
import org.opensearch.sql.data.type.ExprType;
14
import org.opensearch.sql.data.type.WideningTypeRule;
15
16
/**
17
 * Function signature is composed by function name and arguments list.
18
 */
19
@Getter
20
@RequiredArgsConstructor
21
@EqualsAndHashCode
22
public class FunctionSignature {
23
  public static final Integer NOT_MATCH = Integer.MAX_VALUE;
24
  public static final Integer EXACTLY_MATCH = 0;
25
26
  private final FunctionName functionName;
27
  private final List<ExprType> paramTypeList;
28
29
  /**
30
   * calculate the function signature match degree.
31
   *
32
   * @return  EXACTLY_MATCH: exactly match
33
   *          NOT_MATCH: not match
34
   *          By widening rule, the small number means better match
35
   */
36
  public int match(FunctionSignature functionSignature) {
37
    List<ExprType> functionTypeList = functionSignature.getParamTypeList();
38 1 1. match : negated conditional → KILLED
    if (!functionName.equals(functionSignature.getFunctionName())
39 1 1. match : negated conditional → KILLED
        || paramTypeList.size() != functionTypeList.size()) {
40 1 1. match : replaced int return with 0 for org/opensearch/sql/expression/function/FunctionSignature::match → KILLED
      return NOT_MATCH;
41
    }
42
43
    int matchDegree = EXACTLY_MATCH;
44 2 1. match : changed conditional boundary → KILLED
2. match : negated conditional → KILLED
    for (int i = 0; i < paramTypeList.size(); i++) {
45
      ExprType paramType = paramTypeList.get(i);
46
      ExprType funcType = functionTypeList.get(i);
47
      int match = WideningTypeRule.distance(paramType, funcType);
48 1 1. match : negated conditional → KILLED
      if (match == WideningTypeRule.IMPOSSIBLE_WIDENING) {
49 1 1. match : replaced int return with 0 for org/opensearch/sql/expression/function/FunctionSignature::match → KILLED
        return NOT_MATCH;
50
      } else {
51 1 1. match : Replaced integer addition with subtraction → KILLED
        matchDegree += match;
52
      }
53
    }
54 1 1. match : replaced int return with 0 for org/opensearch/sql/expression/function/FunctionSignature::match → KILLED
    return matchDegree;
55
  }
56
57
  /**
58
   * util function for formatted arguments list.
59
   */
60
  public String formatTypes() {
61 1 1. formatTypes : replaced return value with "" for org/opensearch/sql/expression/function/FunctionSignature::formatTypes → KILLED
    return getParamTypeList().stream()
62
        .map(ExprType::typeName)
63
        .collect(Collectors.joining(",", "[", "]"));
64
  }
65
}

Mutations

38

1.1
Location : match
Killed by : org.opensearch.sql.expression.function.FunctionSignatureTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.function.FunctionSignatureTest]/[method:signature_arguments_size_not_match()]
negated conditional → KILLED

39

1.1
Location : match
Killed by : org.opensearch.sql.expression.function.FunctionSignatureTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.function.FunctionSignatureTest]/[method:signature_exactly_match()]
negated conditional → KILLED

40

1.1
Location : match
Killed by : org.opensearch.sql.expression.function.FunctionSignatureTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.function.FunctionSignatureTest]/[method:signature_name_not_match()]
replaced int return with 0 for org/opensearch/sql/expression/function/FunctionSignature::match → KILLED

44

1.1
Location : match
Killed by : org.opensearch.sql.expression.function.FunctionSignatureTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.function.FunctionSignatureTest]/[method:signature_exactly_match()]
changed conditional boundary → KILLED

2.2
Location : match
Killed by : org.opensearch.sql.expression.function.FunctionSignatureTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.function.FunctionSignatureTest]/[method:signature_not_match()]
negated conditional → KILLED

48

1.1
Location : match
Killed by : org.opensearch.sql.expression.function.FunctionSignatureTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.function.FunctionSignatureTest]/[method:signature_exactly_match()]
negated conditional → KILLED

49

1.1
Location : match
Killed by : org.opensearch.sql.expression.function.FunctionSignatureTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.function.FunctionSignatureTest]/[method:signature_not_match()]
replaced int return with 0 for org/opensearch/sql/expression/function/FunctionSignature::match → KILLED

51

1.1
Location : match
Killed by : org.opensearch.sql.expression.function.FunctionSignatureTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.function.FunctionSignatureTest]/[method:signature_widening_match()]
Replaced integer addition with subtraction → KILLED

54

1.1
Location : match
Killed by : org.opensearch.sql.expression.function.FunctionSignatureTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.function.FunctionSignatureTest]/[method:signature_widening_match()]
replaced int return with 0 for org/opensearch/sql/expression/function/FunctionSignature::match → KILLED

61

1.1
Location : formatTypes
Killed by : org.opensearch.sql.expression.function.FunctionSignatureTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.function.FunctionSignatureTest]/[method:format_types()]
replaced return value with "" for org/opensearch/sql/expression/function/FunctionSignature::formatTypes → KILLED

Active mutators

Tests examined


Report generated by PIT 1.9.0