ExprStringValue.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.time.LocalDate;
10
import java.time.LocalDateTime;
11
import java.time.LocalTime;
12
import java.util.Objects;
13
import lombok.RequiredArgsConstructor;
14
import org.opensearch.sql.data.type.ExprCoreType;
15
import org.opensearch.sql.data.type.ExprType;
16
import org.opensearch.sql.exception.SemanticCheckException;
17
18
/**
19
 * Expression String Value.
20
 */
21
@RequiredArgsConstructor
22
public class ExprStringValue extends AbstractExprValue {
23
  private final String value;
24
25
  @Override
26
  public Object value() {
27 1 1. value : replaced return value with null for org/opensearch/sql/data/model/ExprStringValue::value → KILLED
    return value;
28
  }
29
30
  @Override
31
  public ExprType type() {
32 1 1. type : replaced return value with null for org/opensearch/sql/data/model/ExprStringValue::type → KILLED
    return ExprCoreType.STRING;
33
  }
34
35
  @Override
36
  public String stringValue() {
37 1 1. stringValue : replaced return value with "" for org/opensearch/sql/data/model/ExprStringValue::stringValue → KILLED
    return value;
38
  }
39
40
  @Override
41
  public LocalDateTime datetimeValue() {
42
    try {
43 1 1. datetimeValue : replaced return value with null for org/opensearch/sql/data/model/ExprStringValue::datetimeValue → KILLED
      return new ExprDatetimeValue(value).datetimeValue();
44
    } catch (SemanticCheckException e) {
45
      try {
46 1 1. datetimeValue : replaced return value with null for org/opensearch/sql/data/model/ExprStringValue::datetimeValue → KILLED
        return new ExprDatetimeValue(
47
            LocalDateTime.of(new ExprDateValue(value).dateValue(), LocalTime.of(0, 0, 0)))
48
            .datetimeValue();
49
      } catch (SemanticCheckException exception) {
50
        throw new SemanticCheckException(String.format("datetime:%s in unsupported format, please "
51
            + "use yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]", value));
52
      }
53
    }
54
  }
55
56
  @Override
57
  public LocalDate dateValue() {
58
    try {
59 1 1. dateValue : replaced return value with null for org/opensearch/sql/data/model/ExprStringValue::dateValue → KILLED
      return new ExprDatetimeValue(value).dateValue();
60
    } catch (SemanticCheckException e) {
61 1 1. dateValue : replaced return value with null for org/opensearch/sql/data/model/ExprStringValue::dateValue → KILLED
      return new ExprDateValue(value).dateValue();
62
    }
63
  }
64
65
  @Override
66
  public LocalTime timeValue() {
67
    try {
68 1 1. timeValue : replaced return value with null for org/opensearch/sql/data/model/ExprStringValue::timeValue → KILLED
      return new ExprDatetimeValue(value).timeValue();
69
    } catch (SemanticCheckException e) {
70 1 1. timeValue : replaced return value with null for org/opensearch/sql/data/model/ExprStringValue::timeValue → KILLED
      return new ExprTimeValue(value).timeValue();
71
    }
72
  }
73
74
  @Override
75
  public String toString() {
76 1 1. toString : replaced return value with "" for org/opensearch/sql/data/model/ExprStringValue::toString → KILLED
    return String.format("\"%s\"", value);
77
  }
78
79
  @Override
80
  public int compare(ExprValue other) {
81 1 1. compare : replaced int return with 0 for org/opensearch/sql/data/model/ExprStringValue::compare → KILLED
    return value.compareTo(other.stringValue());
82
  }
83
84
  @Override
85
  public boolean equal(ExprValue other) {
86 2 1. equal : replaced boolean return with false for org/opensearch/sql/data/model/ExprStringValue::equal → KILLED
2. equal : replaced boolean return with true for org/opensearch/sql/data/model/ExprStringValue::equal → KILLED
    return value.equals(other.stringValue());
87
  }
88
89
  @Override
90
  public int hashCode() {
91 1 1. hashCode : replaced int return with 0 for org/opensearch/sql/data/model/ExprStringValue::hashCode → SURVIVED
    return Objects.hashCode(value);
92
  }
93
}

Mutations

27

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:#7]
replaced return value with null for org/opensearch/sql/data/model/ExprStringValue::value → KILLED

32

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:#7]
replaced return value with null for org/opensearch/sql/data/model/ExprStringValue::type → KILLED

37

1.1
Location : stringValue
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:#7]
replaced return value with "" for org/opensearch/sql/data/model/ExprStringValue::stringValue → KILLED

43

1.1
Location : datetimeValue
Killed by : org.opensearch.sql.data.model.DateTimeValueTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.DateTimeValueTest]/[method:stringDateTimeValue()]
replaced return value with null for org/opensearch/sql/data/model/ExprStringValue::datetimeValue → KILLED

46

1.1
Location : datetimeValue
Killed by : org.opensearch.sql.data.model.DateTimeValueTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.DateTimeValueTest]/[method:stringDateValue()]
replaced return value with null for org/opensearch/sql/data/model/ExprStringValue::datetimeValue → KILLED

59

1.1
Location : dateValue
Killed by : org.opensearch.sql.data.model.DateTimeValueTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.DateTimeValueTest]/[method:stringDateTimeValue()]
replaced return value with null for org/opensearch/sql/data/model/ExprStringValue::dateValue → KILLED

61

1.1
Location : dateValue
Killed by : org.opensearch.sql.data.model.DateTimeValueTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.DateTimeValueTest]/[method:stringDateValue()]
replaced return value with null for org/opensearch/sql/data/model/ExprStringValue::dateValue → KILLED

68

1.1
Location : timeValue
Killed by : org.opensearch.sql.data.model.DateTimeValueTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.DateTimeValueTest]/[method:stringDateTimeValue()]
replaced return value with null for org/opensearch/sql/data/model/ExprStringValue::timeValue → KILLED

70

1.1
Location : timeValue
Killed by : org.opensearch.sql.data.model.DateTimeValueTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.DateTimeValueTest]/[method:stringTimeValue()]
replaced return value with null for org/opensearch/sql/data/model/ExprStringValue::timeValue → KILLED

76

1.1
Location : toString
Killed by : org.opensearch.sql.data.model.DateTimeValueTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.DateTimeValueTest]/[method:stringTimeValue()]
replaced return value with "" for org/opensearch/sql/data/model/ExprStringValue::toString → KILLED

81

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_string_value()]
replaced int return with 0 for org/opensearch/sql/data/model/ExprStringValue::compare → KILLED

86

1.1
Location : equal
Killed by : org.opensearch.sql.analysis.ExpressionAnalyzerTest.[engine:junit-jupiter]/[class:org.opensearch.sql.analysis.ExpressionAnalyzerTest]/[method:all_fields()]
replaced boolean return with false for org/opensearch/sql/data/model/ExprStringValue::equal → KILLED

2.2
Location : equal
Killed by : org.opensearch.sql.expression.window.CurrentRowWindowFrameTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.window.CurrentRowWindowFrameTest]/[method:should_return_new_partition_if_partition_by_field_value_changed()]
replaced boolean return with true for org/opensearch/sql/data/model/ExprStringValue::equal → KILLED

91

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

Active mutators

Tests examined


Report generated by PIT 1.9.0