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 |
|
40 |
1.1 |
|
45 |
1.1 |
|
50 |
1.1 |
|
52 |
1.1 |
|
58 |
1.1 2.2 |
|
63 |
1.1 |
|
68 |
1.1 |
|
76 |
1.1 |
|
77 |
1.1 |
|
82 |
1.1 2.2 |
|
85 |
1.1 |
|
86 |
1.1 |
|
87 |
1.1 |
|
90 |
1.1 2.2 3.3 |
|
99 |
1.1 |
|
104 |
1.1 |