RenameOperator.java

1
/*
2
 * Copyright OpenSearch Contributors
3
 * SPDX-License-Identifier: Apache-2.0
4
 */
5
6
7
package org.opensearch.sql.planner.physical;
8
9
import static org.opensearch.sql.data.type.ExprCoreType.STRUCT;
10
11
import com.google.common.collect.ImmutableMap;
12
import com.google.common.collect.ImmutableMap.Builder;
13
import java.util.Collections;
14
import java.util.List;
15
import java.util.Map;
16
import java.util.stream.Collectors;
17
import lombok.EqualsAndHashCode;
18
import lombok.Getter;
19
import lombok.ToString;
20
import org.opensearch.sql.data.model.ExprTupleValue;
21
import org.opensearch.sql.data.model.ExprValue;
22
import org.opensearch.sql.data.model.ExprValueUtils;
23
import org.opensearch.sql.expression.ReferenceExpression;
24
import org.opensearch.sql.storage.bindingtuple.BindingTuple;
25
26
/**
27
 * Rename the binding name in {@link BindingTuple}.
28
 * The mapping maintain the relation between source and target.
29
 * it means BindingTuple.resolve(target) = BindingTuple.resolve(source).
30
 */
31
@EqualsAndHashCode(callSuper = false)
32
@ToString
33
public class RenameOperator extends PhysicalPlan {
34
  @Getter
35
  private final PhysicalPlan input;
36
  @Getter
37
  private final Map<ReferenceExpression, ReferenceExpression> mapping;
38
  /**
39
   * Todo. This is the temporary solution that add the mapping between string and ref. because when
40
   * rename the field from input, there we can only get the string field.
41
   */
42
  @ToString.Exclude
43
  @EqualsAndHashCode.Exclude
44
  private final Map<String, ReferenceExpression> nameMapping;
45
46
  /**
47
   * Constructor of RenameOperator.
48
   */
49
  public RenameOperator(PhysicalPlan input,
50
                        Map<ReferenceExpression, ReferenceExpression> mapping) {
51
    this.input = input;
52
    this.mapping = mapping;
53
    this.nameMapping =
54 1 1. lambda$new$0 : replaced return value with "" for org/opensearch/sql/planner/physical/RenameOperator::lambda$new$0 → KILLED
        mapping.entrySet().stream().collect(Collectors.toMap(entry -> entry.getKey().getAttr(),
55 1 1. lambda$new$1 : replaced return value with null for org/opensearch/sql/planner/physical/RenameOperator::lambda$new$1 → KILLED
            entry -> entry.getValue()));
56
  }
57
58
  @Override
59
  public <R, C> R accept(PhysicalPlanNodeVisitor<R, C> visitor, C context) {
60 1 1. accept : replaced return value with null for org/opensearch/sql/planner/physical/RenameOperator::accept → KILLED
    return visitor.visitRename(this, context);
61
  }
62
63
  @Override
64
  public List<PhysicalPlan> getChild() {
65 1 1. getChild : replaced return value with Collections.emptyList for org/opensearch/sql/planner/physical/RenameOperator::getChild → KILLED
    return Collections.singletonList(input);
66
  }
67
68
  @Override
69
  public boolean hasNext() {
70 2 1. hasNext : replaced boolean return with true for org/opensearch/sql/planner/physical/RenameOperator::hasNext → TIMED_OUT
2. hasNext : replaced boolean return with false for org/opensearch/sql/planner/physical/RenameOperator::hasNext → KILLED
    return input.hasNext();
71
  }
72
73
  @Override
74
  public ExprValue next() {
75
    ExprValue inputValue = input.next();
76 1 1. next : negated conditional → KILLED
    if (STRUCT == inputValue.type()) {
77
      Map<String, ExprValue> tupleValue = ExprValueUtils.getTupleValue(inputValue);
78
      ImmutableMap.Builder<String, ExprValue> mapBuilder = new Builder<>();
79
      for (String bindName : tupleValue.keySet()) {
80 1 1. next : negated conditional → KILLED
        if (nameMapping.containsKey(bindName)) {
81
          mapBuilder.put(nameMapping.get(bindName).getAttr(), tupleValue.get(bindName));
82
        } else {
83
          mapBuilder.put(bindName, tupleValue.get(bindName));
84
        }
85
      }
86 1 1. next : replaced return value with null for org/opensearch/sql/planner/physical/RenameOperator::next → KILLED
      return ExprTupleValue.fromExprValueMap(mapBuilder.build());
87
    } else {
88 1 1. next : replaced return value with null for org/opensearch/sql/planner/physical/RenameOperator::next → KILLED
      return inputValue;
89
    }
90
  }
91
}

Mutations

54

1.1
Location : lambda$new$0
Killed by : org.opensearch.sql.planner.physical.RenameOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.planner.physical.RenameOperatorTest]/[method:avg_aggregation_rename()]
replaced return value with "" for org/opensearch/sql/planner/physical/RenameOperator::lambda$new$0 → KILLED

55

1.1
Location : lambda$new$1
Killed by : org.opensearch.sql.planner.physical.RenameOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.planner.physical.RenameOperatorTest]/[method:rename_int_value()]
replaced return value with null for org/opensearch/sql/planner/physical/RenameOperator::lambda$new$1 → KILLED

60

1.1
Location : accept
Killed by : org.opensearch.sql.planner.physical.PhysicalPlanNodeVisitorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.planner.physical.PhysicalPlanNodeVisitorTest]/[method:print_physical_plan()]
replaced return value with null for org/opensearch/sql/planner/physical/RenameOperator::accept → KILLED

65

1.1
Location : getChild
Killed by : org.opensearch.sql.planner.physical.RenameOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.planner.physical.RenameOperatorTest]/[method:avg_aggregation_rename()]
replaced return value with Collections.emptyList for org/opensearch/sql/planner/physical/RenameOperator::getChild → KILLED

70

1.1
Location : hasNext
Killed by : org.opensearch.sql.planner.physical.RenameOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.planner.physical.RenameOperatorTest]/[method:rename_int_value()]
replaced boolean return with false for org/opensearch/sql/planner/physical/RenameOperator::hasNext → KILLED

2.2
Location : hasNext
Killed by : none
replaced boolean return with true for org/opensearch/sql/planner/physical/RenameOperator::hasNext → TIMED_OUT

76

1.1
Location : next
Killed by : org.opensearch.sql.planner.physical.RenameOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.planner.physical.RenameOperatorTest]/[method:rename_int_value()]
negated conditional → KILLED

80

1.1
Location : next
Killed by : org.opensearch.sql.planner.physical.RenameOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.planner.physical.RenameOperatorTest]/[method:avg_aggregation_rename()]
negated conditional → KILLED

86

1.1
Location : next
Killed by : org.opensearch.sql.planner.physical.RenameOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.planner.physical.RenameOperatorTest]/[method:avg_aggregation_rename()]
replaced return value with null for org/opensearch/sql/planner/physical/RenameOperator::next → KILLED

88

1.1
Location : next
Killed by : org.opensearch.sql.planner.physical.RenameOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.planner.physical.RenameOperatorTest]/[method:rename_int_value()]
replaced return value with null for org/opensearch/sql/planner/physical/RenameOperator::next → KILLED

Active mutators

Tests examined


Report generated by PIT 1.9.0