ExprTupleValue.java

1
/*
2
 * Copyright OpenSearch Contributors
3
 * SPDX-License-Identifier: Apache-2.0
4
 */
5
6
7
package org.opensearch.sql.data.model;
8
9
import java.util.Iterator;
10
import java.util.LinkedHashMap;
11
import java.util.Map;
12
import java.util.Map.Entry;
13
import java.util.Objects;
14
import java.util.stream.Collectors;
15
import lombok.RequiredArgsConstructor;
16
import org.opensearch.sql.data.type.ExprCoreType;
17
import org.opensearch.sql.data.type.ExprType;
18
import org.opensearch.sql.storage.bindingtuple.BindingTuple;
19
import org.opensearch.sql.storage.bindingtuple.LazyBindingTuple;
20
21
/**
22
 * Expression Tuple Value.
23
 */
24
@RequiredArgsConstructor
25
public class ExprTupleValue extends AbstractExprValue {
26
27
  private final LinkedHashMap<String, ExprValue> valueMap;
28
29
  public static ExprTupleValue fromExprValueMap(Map<String, ExprValue> map) {
30
    LinkedHashMap<String, ExprValue> linkedHashMap = new LinkedHashMap<>(map);
31 1 1. fromExprValueMap : replaced return value with null for org/opensearch/sql/data/model/ExprTupleValue::fromExprValueMap → KILLED
    return new ExprTupleValue(linkedHashMap);
32
  }
33
34
  @Override
35
  public Object value() {
36
    LinkedHashMap<String, Object> resultMap = new LinkedHashMap<>();
37
    for (Entry<String, ExprValue> entry : valueMap.entrySet()) {
38
      resultMap.put(entry.getKey(), entry.getValue().value());
39
    }
40 1 1. value : replaced return value with null for org/opensearch/sql/data/model/ExprTupleValue::value → KILLED
    return resultMap;
41
  }
42
43
  @Override
44
  public ExprType type() {
45 1 1. type : replaced return value with null for org/opensearch/sql/data/model/ExprTupleValue::type → KILLED
    return ExprCoreType.STRUCT;
46
  }
47
48
  @Override
49
  public String toString() {
50 1 1. toString : replaced return value with "" for org/opensearch/sql/data/model/ExprTupleValue::toString → SURVIVED
    return valueMap.entrySet()
51
        .stream()
52 1 1. lambda$toString$0 : replaced return value with "" for org/opensearch/sql/data/model/ExprTupleValue::lambda$toString$0 → SURVIVED
        .map(entry -> String.format("%s:%s", entry.getKey(), entry.getValue()))
53
        .collect(Collectors.joining(",", "{", "}"));
54
  }
55
56
  @Override
57
  public BindingTuple bindingTuples() {
58 2 1. bindingTuples : replaced return value with null for org/opensearch/sql/data/model/ExprTupleValue::bindingTuples → KILLED
2. lambda$bindingTuples$1 : replaced return value with null for org/opensearch/sql/data/model/ExprTupleValue::lambda$bindingTuples$1 → KILLED
    return new LazyBindingTuple(() -> this);
59
  }
60
61
  @Override
62
  public Map<String, ExprValue> tupleValue() {
63 1 1. tupleValue : replaced return value with Collections.emptyMap for org/opensearch/sql/data/model/ExprTupleValue::tupleValue → KILLED
    return valueMap;
64
  }
65
66
  @Override
67
  public ExprValue keyValue(String key) {
68 1 1. keyValue : replaced return value with null for org/opensearch/sql/data/model/ExprTupleValue::keyValue → KILLED
    return valueMap.getOrDefault(key, ExprMissingValue.of());
69
  }
70
71
  /**
72
   * Override the equals method.
73
   * @return true for equal, otherwise false.
74
   */
75
  public boolean equal(ExprValue o) {
76 1 1. equal : negated conditional → KILLED
    if (!(o instanceof ExprTupleValue)) {
77 1 1. equal : replaced boolean return with true for org/opensearch/sql/data/model/ExprTupleValue::equal → KILLED
      return false;
78
    } else {
79
      ExprTupleValue other = (ExprTupleValue) o;
80
      Iterator<Entry<String, ExprValue>> thisIterator = this.valueMap.entrySet().iterator();
81
      Iterator<Entry<String, ExprValue>> otherIterator = other.valueMap.entrySet().iterator();
82 2 1. equal : negated conditional → KILLED
2. equal : negated conditional → KILLED
      while (thisIterator.hasNext() && otherIterator.hasNext()) {
83
        Entry<String, ExprValue> thisEntry = thisIterator.next();
84
        Entry<String, ExprValue> otherEntry = otherIterator.next();
85 1 1. equal : negated conditional → KILLED
        if (!(thisEntry.getKey().equals(otherEntry.getKey())
86 1 1. equal : negated conditional → KILLED
            && thisEntry.getValue().equals(otherEntry.getValue()))) {
87 1 1. equal : replaced boolean return with true for org/opensearch/sql/data/model/ExprTupleValue::equal → KILLED
          return false;
88
        }
89
      }
90 3 1. equal : negated conditional → KILLED
2. equal : negated conditional → KILLED
3. equal : replaced boolean return with true for org/opensearch/sql/data/model/ExprTupleValue::equal → KILLED
      return !(thisIterator.hasNext() || otherIterator.hasNext());
91
    }
92
  }
93
94
  /**
95
   * Only compare the size of the map.
96
   */
97
  @Override
98
  public int compare(ExprValue other) {
99 1 1. compare : replaced int return with 0 for org/opensearch/sql/data/model/ExprTupleValue::compare → KILLED
    return Integer.compare(valueMap.size(), other.tupleValue().size());
100
  }
101
102
  @Override
103
  public int hashCode() {
104 1 1. hashCode : replaced int return with 0 for org/opensearch/sql/data/model/ExprTupleValue::hashCode → SURVIVED
    return Objects.hashCode(valueMap);
105
  }
106
}

Mutations

31

1.1
Location : fromExprValueMap
Killed by : org.opensearch.sql.expression.ReferenceExpressionTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.ReferenceExpressionTest]/[method:path_as_whole_has_highest_priority()]
replaced return value with null for org/opensearch/sql/data/model/ExprTupleValue::fromExprValueMap → KILLED

40

1.1
Location : value
Killed by : org.opensearch.sql.expression.operator.predicate.BinaryPredicateOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.operator.predicate.BinaryPredicateOperatorTest]/[test-template:test_notequal(org.opensearch.sql.data.model.ExprValue, org.opensearch.sql.data.model.ExprValue)]/[test-template-invocation:#10]
replaced return value with null for org/opensearch/sql/data/model/ExprTupleValue::value → KILLED

45

1.1
Location : type
Killed by : org.opensearch.sql.data.model.ExprValueUtilsTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.ExprValueUtilsTest]/[test-template:getType(org.opensearch.sql.data.model.ExprValue, org.opensearch.sql.data.type.ExprCoreType)]/[test-template-invocation:#10]
replaced return value with null for org/opensearch/sql/data/model/ExprTupleValue::type → KILLED

50

1.1
Location : toString
Killed by : none
replaced return value with "" for org/opensearch/sql/data/model/ExprTupleValue::toString → SURVIVED

52

1.1
Location : lambda$toString$0
Killed by : none
replaced return value with "" for org/opensearch/sql/data/model/ExprTupleValue::lambda$toString$0 → SURVIVED

58

1.1
Location : bindingTuples
Killed by : org.opensearch.sql.storage.bindingtuple.BindingTupleTest.[engine:junit-jupiter]/[class:org.opensearch.sql.storage.bindingtuple.BindingTupleTest]/[method:resolve_missing_expression()]
replaced return value with null for org/opensearch/sql/data/model/ExprTupleValue::bindingTuples → KILLED

2.2
Location : lambda$bindingTuples$1
Killed by : org.opensearch.sql.storage.bindingtuple.BindingTupleTest.[engine:junit-jupiter]/[class:org.opensearch.sql.storage.bindingtuple.BindingTupleTest]/[method:resolve_missing_expression()]
replaced return value with null for org/opensearch/sql/data/model/ExprTupleValue::lambda$bindingTuples$1 → KILLED

63

1.1
Location : tupleValue
Killed by : org.opensearch.sql.data.model.ExprValueUtilsTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.ExprValueUtilsTest]/[test-template:getValue(org.opensearch.sql.data.model.ExprValue, java.util.function.Function, java.lang.Object)]/[test-template-invocation:#10]
replaced return value with Collections.emptyMap for org/opensearch/sql/data/model/ExprTupleValue::tupleValue → KILLED

68

1.1
Location : keyValue
Killed by : org.opensearch.sql.storage.bindingtuple.BindingTupleTest.[engine:junit-jupiter]/[class:org.opensearch.sql.storage.bindingtuple.BindingTupleTest]/[method:resolve_missing_expression()]
replaced return value with null for org/opensearch/sql/data/model/ExprTupleValue::keyValue → KILLED

76

1.1
Location : equal
Killed by : org.opensearch.sql.data.model.ExprTupleValueTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.ExprTupleValueTest]/[method:tuple_compare_int()]
negated conditional → KILLED

77

1.1
Location : equal
Killed by : org.opensearch.sql.data.model.ExprTupleValueTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.ExprTupleValueTest]/[method:tuple_compare_int()]
replaced boolean return with true for org/opensearch/sql/data/model/ExprTupleValue::equal → KILLED

82

1.1
Location : equal
Killed by : org.opensearch.sql.expression.window.frame.PeerRowsWindowFrameTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.window.frame.PeerRowsWindowFrameTest]/[method:test_single_row()]
negated conditional → KILLED

2.2
Location : equal
Killed by : org.opensearch.sql.expression.window.frame.PeerRowsWindowFrameTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.window.frame.PeerRowsWindowFrameTest]/[method:test_single_row()]
negated conditional → KILLED

85

1.1
Location : equal
Killed by : org.opensearch.sql.expression.window.frame.PeerRowsWindowFrameTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.window.frame.PeerRowsWindowFrameTest]/[method:test_single_row()]
negated conditional → KILLED

86

1.1
Location : equal
Killed by : org.opensearch.sql.expression.window.frame.PeerRowsWindowFrameTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.window.frame.PeerRowsWindowFrameTest]/[method:test_single_row()]
negated conditional → KILLED

87

1.1
Location : equal
Killed by : org.opensearch.sql.data.model.ExprTupleValueTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.ExprTupleValueTest]/[method:compare_tuple_with_different_key()]
replaced boolean return with true for org/opensearch/sql/data/model/ExprTupleValue::equal → KILLED

90

1.1
Location : equal
Killed by : org.opensearch.sql.data.model.ExprTupleValueTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.ExprTupleValueTest]/[method:compare_tuple_with_different_size()]
negated conditional → KILLED

2.2
Location : equal
Killed by : org.opensearch.sql.data.model.ExprTupleValueTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.ExprTupleValueTest]/[method:compare_tuple_with_different_size()]
negated conditional → KILLED

3.3
Location : equal
Killed by : org.opensearch.sql.data.model.ExprTupleValueTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.ExprTupleValueTest]/[method:compare_tuple_with_different_size()]
replaced boolean return with true for org/opensearch/sql/data/model/ExprTupleValue::equal → KILLED

99

1.1
Location : compare
Killed by : org.opensearch.sql.data.utils.ExprValueOrderingTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.utils.ExprValueOrderingTest]/[method:natural_order_tuple_value()]
replaced int return with 0 for org/opensearch/sql/data/model/ExprTupleValue::compare → KILLED

104

1.1
Location : hashCode
Killed by : none
replaced int return with 0 for org/opensearch/sql/data/model/ExprTupleValue::hashCode → SURVIVED

Active mutators

Tests examined


Report generated by PIT 1.9.0