UnaryPredicateOperator.java

1
/*
2
 * Copyright OpenSearch Contributors
3
 * SPDX-License-Identifier: Apache-2.0
4
 */
5
6
7
package org.opensearch.sql.expression.operator.predicate;
8
9
import static org.opensearch.sql.data.model.ExprValueUtils.LITERAL_NULL;
10
import static org.opensearch.sql.data.model.ExprValueUtils.LITERAL_TRUE;
11
import static org.opensearch.sql.data.type.ExprCoreType.BOOLEAN;
12
import static org.opensearch.sql.expression.function.FunctionDSL.impl;
13
14
import java.util.Arrays;
15
import java.util.List;
16
import java.util.stream.Collectors;
17
import lombok.experimental.UtilityClass;
18
import org.opensearch.sql.data.model.ExprBooleanValue;
19
import org.opensearch.sql.data.model.ExprValue;
20
import org.opensearch.sql.data.type.ExprCoreType;
21
import org.opensearch.sql.expression.function.BuiltinFunctionName;
22
import org.opensearch.sql.expression.function.BuiltinFunctionRepository;
23
import org.opensearch.sql.expression.function.DefaultFunctionResolver;
24
import org.opensearch.sql.expression.function.FunctionBuilder;
25
import org.opensearch.sql.expression.function.FunctionDSL;
26
import org.opensearch.sql.expression.function.FunctionName;
27
import org.opensearch.sql.expression.function.FunctionSignature;
28
import org.opensearch.sql.expression.function.SerializableFunction;
29
30
/**
31
 * The definition of unary predicate function
32
 * not, Accepts one Boolean value and produces a Boolean.
33
 */
34
@UtilityClass
35
public class UnaryPredicateOperator {
36
  /**
37
   * Register Unary Predicate Function.
38
   */
39
  public static void register(BuiltinFunctionRepository repository) {
40 1 1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED
    repository.register(not());
41 1 1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED
    repository.register(isNotNull());
42 1 1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED
    repository.register(ifNull());
43 1 1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED
    repository.register(nullIf());
44 1 1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED
    repository.register(isNull(BuiltinFunctionName.IS_NULL));
45 1 1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED
    repository.register(isNull(BuiltinFunctionName.ISNULL));
46 1 1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED
    repository.register(ifFunction());
47
  }
48
49
  private static DefaultFunctionResolver not() {
50 1 1. not : replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::not → KILLED
    return FunctionDSL.define(BuiltinFunctionName.NOT.getName(), FunctionDSL
51
        .impl(UnaryPredicateOperator::not, BOOLEAN, BOOLEAN));
52
  }
53
54
  /**
55
   * The not logic.
56
   * A       NOT A
57
   * TRUE    FALSE
58
   * FALSE   TRUE
59
   * NULL    NULL
60
   * MISSING MISSING
61
   */
62
  public ExprValue not(ExprValue v) {
63 2 1. not : negated conditional → KILLED
2. not : negated conditional → KILLED
    if (v.isMissing() || v.isNull()) {
64 1 1. not : replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::not → KILLED
      return v;
65
    } else {
66 2 1. not : negated conditional → KILLED
2. not : replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::not → KILLED
      return ExprBooleanValue.of(!v.booleanValue());
67
    }
68
  }
69
70
  private static DefaultFunctionResolver isNull(BuiltinFunctionName funcName) {
71 1 1. isNull : replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::isNull → KILLED
    return FunctionDSL
72
        .define(funcName.getName(), Arrays.stream(ExprCoreType.values())
73 1 1. lambda$isNull$0 : replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::lambda$isNull$0 → KILLED
            .map(type -> FunctionDSL
74 1 1. lambda$isNull$3b347664$1 : replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::lambda$isNull$3b347664$1 → KILLED
                .impl((v) -> ExprBooleanValue.of(v.isNull()), BOOLEAN, type))
75
            .collect(
76
                Collectors.toList()));
77
  }
78
79
  private static DefaultFunctionResolver isNotNull() {
80 1 1. isNotNull : replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::isNotNull → KILLED
    return FunctionDSL
81
        .define(BuiltinFunctionName.IS_NOT_NULL.getName(), Arrays.stream(ExprCoreType.values())
82 1 1. lambda$isNotNull$1 : replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::lambda$isNotNull$1 → KILLED
            .map(type -> FunctionDSL
83 2 1. lambda$isNotNull$12c7dc48$1 : negated conditional → KILLED
2. lambda$isNotNull$12c7dc48$1 : replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::lambda$isNotNull$12c7dc48$1 → KILLED
                .impl((v) -> ExprBooleanValue.of(!v.isNull()), BOOLEAN, type))
84
            .collect(
85
                Collectors.toList()));
86
  }
87
88
  private static DefaultFunctionResolver ifFunction() {
89
    FunctionName functionName = BuiltinFunctionName.IF.getName();
90
    List<ExprCoreType> typeList = ExprCoreType.coreTypes();
91
92
    List<SerializableFunction<FunctionName, org.apache.commons.lang3.tuple.Pair<FunctionSignature,
93
            FunctionBuilder>>> functionsOne = typeList.stream().map(v ->
94 1 1. lambda$ifFunction$2 : replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::lambda$ifFunction$2 → KILLED
            impl((UnaryPredicateOperator::exprIf), v, BOOLEAN, v, v))
95
            .collect(Collectors.toList());
96
97
    DefaultFunctionResolver functionResolver = FunctionDSL.define(functionName, functionsOne);
98 1 1. ifFunction : replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::ifFunction → KILLED
    return functionResolver;
99
  }
100
101
  private static DefaultFunctionResolver ifNull() {
102
    FunctionName functionName = BuiltinFunctionName.IFNULL.getName();
103
    List<ExprCoreType> typeList = ExprCoreType.coreTypes();
104
105
    List<SerializableFunction<FunctionName, org.apache.commons.lang3.tuple.Pair<FunctionSignature,
106
            FunctionBuilder>>> functionsOne = typeList.stream().map(v ->
107 1 1. lambda$ifNull$3 : replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::lambda$ifNull$3 → KILLED
            impl((UnaryPredicateOperator::exprIfNull), v, v, v))
108
            .collect(Collectors.toList());
109
110
    DefaultFunctionResolver functionResolver = FunctionDSL.define(functionName, functionsOne);
111 1 1. ifNull : replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::ifNull → KILLED
    return functionResolver;
112
  }
113
114
  private static DefaultFunctionResolver nullIf() {
115
    FunctionName functionName = BuiltinFunctionName.NULLIF.getName();
116
    List<ExprCoreType> typeList = ExprCoreType.coreTypes();
117
118
    DefaultFunctionResolver functionResolver =
119
        FunctionDSL.define(functionName,
120
            typeList.stream().map(v ->
121 1 1. lambda$nullIf$4 : replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::lambda$nullIf$4 → KILLED
              impl((UnaryPredicateOperator::exprNullIf), v, v, v))
122
              .collect(Collectors.toList()));
123 1 1. nullIf : replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::nullIf → KILLED
    return functionResolver;
124
  }
125
126
  /** v2 if v1 is null.
127
   *
128
   * @param v1 varable 1
129
   * @param v2 varable 2
130
   * @return v2 if v1 is null
131
   */
132
  public static ExprValue exprIfNull(ExprValue v1, ExprValue v2) {
133 3 1. exprIfNull : negated conditional → KILLED
2. exprIfNull : negated conditional → KILLED
3. exprIfNull : replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::exprIfNull → KILLED
    return (v1.isNull() || v1.isMissing()) ? v2 : v1;
134
  }
135
136
  /** return null if v1 equls to v2.
137
   *
138
   * @param v1 varable 1
139
   * @param v2 varable 2
140
   * @return null if v1 equls to v2
141
   */
142
  public static ExprValue exprNullIf(ExprValue v1, ExprValue v2) {
143 2 1. exprNullIf : negated conditional → KILLED
2. exprNullIf : replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::exprNullIf → KILLED
    return v1.equals(v2) ? LITERAL_NULL : v1;
144
  }
145
146
  public static ExprValue exprIf(ExprValue v1, ExprValue v2, ExprValue v3) {
147 4 1. exprIf : negated conditional → KILLED
2. exprIf : negated conditional → KILLED
3. exprIf : negated conditional → KILLED
4. exprIf : replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::exprIf → KILLED
    return !v1.isNull() && !v1.isMissing() && LITERAL_TRUE.equals(v1) ? v2 : v3;
148
  }
149
150
}

Mutations

40

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

41

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

42

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

43

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

44

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

45

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

46

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

50

1.1
Location : not
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/operator/predicate/UnaryPredicateOperator::not → KILLED

63

1.1
Location : not
Killed by : org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest]/[method:test_not_missing()]
negated conditional → KILLED

2.2
Location : not
Killed by : org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest]/[method:test_not_null()]
negated conditional → KILLED

64

1.1
Location : not
Killed by : org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest]/[method:test_not_null()]
replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::not → KILLED

66

1.1
Location : not
Killed by : org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest]/[test-template:test_not(java.lang.Boolean)]/[test-template-invocation:#1]
negated conditional → KILLED

2.2
Location : not
Killed by : org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest]/[test-template:test_not(java.lang.Boolean)]/[test-template-invocation:#1]
replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::not → KILLED

71

1.1
Location : isNull
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/operator/predicate/UnaryPredicateOperator::isNull → KILLED

73

1.1
Location : lambda$isNull$0
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/operator/predicate/UnaryPredicateOperator::lambda$isNull$0 → KILLED

74

1.1
Location : lambda$isNull$3b347664$1
Killed by : org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest]/[test-template:test_isnull_predicate(org.opensearch.sql.expression.Expression, org.opensearch.sql.expression.Expression)]/[test-template-invocation:#13]
replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::lambda$isNull$3b347664$1 → KILLED

80

1.1
Location : isNotNull
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/operator/predicate/UnaryPredicateOperator::isNotNull → KILLED

82

1.1
Location : lambda$isNotNull$1
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/operator/predicate/UnaryPredicateOperator::lambda$isNotNull$1 → KILLED

83

1.1
Location : lambda$isNotNull$12c7dc48$1
Killed by : org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest]/[method:test_is_not_null_predicate()]
negated conditional → KILLED

2.2
Location : lambda$isNotNull$12c7dc48$1
Killed by : org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest]/[method:test_is_not_null_predicate()]
replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::lambda$isNotNull$12c7dc48$1 → KILLED

94

1.1
Location : lambda$ifFunction$2
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/operator/predicate/UnaryPredicateOperator::lambda$ifFunction$2 → KILLED

98

1.1
Location : ifFunction
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/operator/predicate/UnaryPredicateOperator::ifFunction → KILLED

107

1.1
Location : lambda$ifNull$3
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/operator/predicate/UnaryPredicateOperator::lambda$ifNull$3 → KILLED

111

1.1
Location : ifNull
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/operator/predicate/UnaryPredicateOperator::ifNull → KILLED

121

1.1
Location : lambda$nullIf$4
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/operator/predicate/UnaryPredicateOperator::lambda$nullIf$4 → KILLED

123

1.1
Location : nullIf
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/operator/predicate/UnaryPredicateOperator::nullIf → KILLED

133

1.1
Location : exprIfNull
Killed by : org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest]/[test-template:test_exprIfNull_predicate(org.opensearch.sql.data.model.ExprValue, org.opensearch.sql.data.model.ExprValue, org.opensearch.sql.data.model.ExprValue)]/[test-template-invocation:#3]
negated conditional → KILLED

2.2
Location : exprIfNull
Killed by : org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest]/[test-template:test_exprIfNull_predicate(org.opensearch.sql.data.model.ExprValue, org.opensearch.sql.data.model.ExprValue, org.opensearch.sql.data.model.ExprValue)]/[test-template-invocation:#9]
negated conditional → KILLED

3.3
Location : exprIfNull
Killed by : org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest]/[test-template:test_exprIfNull_predicate(org.opensearch.sql.data.model.ExprValue, org.opensearch.sql.data.model.ExprValue, org.opensearch.sql.data.model.ExprValue)]/[test-template-invocation:#5]
replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::exprIfNull → KILLED

143

1.1
Location : exprNullIf
Killed by : org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest]/[test-template:test_exprNullIf_predicate(org.opensearch.sql.data.model.ExprValue, org.opensearch.sql.data.model.ExprValue, org.opensearch.sql.data.model.ExprValue)]/[test-template-invocation:#9]
negated conditional → KILLED

2.2
Location : exprNullIf
Killed by : org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest]/[test-template:test_exprNullIf_predicate(org.opensearch.sql.data.model.ExprValue, org.opensearch.sql.data.model.ExprValue, org.opensearch.sql.data.model.ExprValue)]/[test-template-invocation:#9]
replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::exprNullIf → KILLED

147

1.1
Location : exprIf
Killed by : org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest]/[test-template:test_if_predicate(org.opensearch.sql.expression.Expression, org.opensearch.sql.expression.Expression, org.opensearch.sql.expression.Expression, org.opensearch.sql.expression.Expression)]/[test-template-invocation:#2]
negated conditional → KILLED

2.2
Location : exprIf
Killed by : org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest]/[test-template:test_if_predicate(org.opensearch.sql.expression.Expression, org.opensearch.sql.expression.Expression, org.opensearch.sql.expression.Expression, org.opensearch.sql.expression.Expression)]/[test-template-invocation:#2]
negated conditional → KILLED

3.3
Location : exprIf
Killed by : org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest]/[test-template:test_if_predicate(org.opensearch.sql.expression.Expression, org.opensearch.sql.expression.Expression, org.opensearch.sql.expression.Expression, org.opensearch.sql.expression.Expression)]/[test-template-invocation:#2]
negated conditional → KILLED

4.4
Location : exprIf
Killed by : org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.predicate.UnaryPredicateOperatorTest]/[test-template:test_if_predicate(org.opensearch.sql.expression.Expression, org.opensearch.sql.expression.Expression, org.opensearch.sql.expression.Expression, org.opensearch.sql.expression.Expression)]/[test-template-invocation:#2]
replaced return value with null for org/opensearch/sql/expression/operator/predicate/UnaryPredicateOperator::exprIf → KILLED

Active mutators

Tests examined


Report generated by PIT 1.9.0