ExprTimestampValue.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 static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_VARIABLE_NANOS;
10
import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_WITHOUT_NANO;
11
12
import java.time.Instant;
13
import java.time.LocalDate;
14
import java.time.LocalDateTime;
15
import java.time.LocalTime;
16
import java.time.ZoneId;
17
import java.time.format.DateTimeParseException;
18
import java.time.temporal.ChronoUnit;
19
import java.util.Objects;
20
import lombok.RequiredArgsConstructor;
21
import org.opensearch.sql.data.type.ExprCoreType;
22
import org.opensearch.sql.data.type.ExprType;
23
import org.opensearch.sql.exception.SemanticCheckException;
24
25
/**
26
 * Expression Timestamp Value.
27
 */
28
@RequiredArgsConstructor
29
public class ExprTimestampValue extends AbstractExprValue {
30
  /**
31
   * todo. only support UTC now.
32
   */
33
  private static final ZoneId ZONE = ZoneId.of("UTC");
34
35
  private final Instant timestamp;
36
37
  /**
38
   * Constructor.
39
   */
40
  public ExprTimestampValue(String timestamp) {
41
    try {
42
      this.timestamp = LocalDateTime.parse(timestamp, DATE_TIME_FORMATTER_VARIABLE_NANOS)
43
          .atZone(ZONE)
44
          .toInstant();
45
    } catch (DateTimeParseException e) {
46
      throw new SemanticCheckException(String.format("timestamp:%s in unsupported format, please "
47
          + "use yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]", timestamp));
48
    }
49
50
  }
51
52
  @Override
53
  public String value() {
54 2 1. value : negated conditional → KILLED
2. value : replaced return value with "" for org/opensearch/sql/data/model/ExprTimestampValue::value → KILLED
    return timestamp.getNano() == 0 ? DATE_TIME_FORMATTER_WITHOUT_NANO.withZone(ZONE)
55
        .format(timestamp.truncatedTo(ChronoUnit.SECONDS))
56
        : DATE_TIME_FORMATTER_VARIABLE_NANOS.withZone(ZONE).format(timestamp);
57
  }
58
59
  @Override
60
  public ExprType type() {
61 1 1. type : replaced return value with null for org/opensearch/sql/data/model/ExprTimestampValue::type → KILLED
    return ExprCoreType.TIMESTAMP;
62
  }
63
64
  @Override
65
  public Instant timestampValue() {
66 1 1. timestampValue : replaced return value with null for org/opensearch/sql/data/model/ExprTimestampValue::timestampValue → KILLED
    return timestamp;
67
  }
68
69
  @Override
70
  public LocalDate dateValue() {
71 1 1. dateValue : replaced return value with null for org/opensearch/sql/data/model/ExprTimestampValue::dateValue → KILLED
    return timestamp.atZone(ZONE).toLocalDate();
72
  }
73
74
  @Override
75
  public LocalTime timeValue() {
76 1 1. timeValue : replaced return value with null for org/opensearch/sql/data/model/ExprTimestampValue::timeValue → KILLED
    return timestamp.atZone(ZONE).toLocalTime();
77
  }
78
79
  @Override
80
  public LocalDateTime datetimeValue() {
81 1 1. datetimeValue : replaced return value with null for org/opensearch/sql/data/model/ExprTimestampValue::datetimeValue → KILLED
    return timestamp.atZone(ZONE).toLocalDateTime();
82
  }
83
84
  @Override
85
  public String toString() {
86 1 1. toString : replaced return value with "" for org/opensearch/sql/data/model/ExprTimestampValue::toString → KILLED
    return String.format("TIMESTAMP '%s'", value());
87
  }
88
89
  @Override
90
  public int compare(ExprValue other) {
91 1 1. compare : replaced int return with 0 for org/opensearch/sql/data/model/ExprTimestampValue::compare → KILLED
    return timestamp.compareTo(other.timestampValue().atZone(ZONE).toInstant());
92
  }
93
94
  @Override
95
  public boolean equal(ExprValue other) {
96 2 1. equal : replaced boolean return with true for org/opensearch/sql/data/model/ExprTimestampValue::equal → SURVIVED
2. equal : replaced boolean return with false for org/opensearch/sql/data/model/ExprTimestampValue::equal → KILLED
    return timestamp.equals(other.timestampValue().atZone(ZONE).toInstant());
97
  }
98
99
  @Override
100
  public int hashCode() {
101 1 1. hashCode : replaced int return with 0 for org/opensearch/sql/data/model/ExprTimestampValue::hashCode → SURVIVED
    return Objects.hashCode(timestamp);
102
  }
103
}

Mutations

54

1.1
Location : value
Killed by : org.opensearch.sql.expression.datetime.DateTimeFunctionTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.datetime.DateTimeFunctionTest]/[method:microsecond()]
negated conditional → KILLED

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

61

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

66

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

71

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

76

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

81

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

86

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

91

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

96

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

2.2
Location : equal
Killed by : none
replaced boolean return with true for org/opensearch/sql/data/model/ExprTimestampValue::equal → SURVIVED

101

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

Active mutators

Tests examined


Report generated by PIT 1.9.0