ExprDateValue.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_OPTIONAL;
10
11
import com.google.common.base.Objects;
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.ZonedDateTime;
18
import java.time.format.DateTimeFormatter;
19
import java.time.format.DateTimeParseException;
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 Date Value.
27
 */
28
@RequiredArgsConstructor
29
public class ExprDateValue extends AbstractExprValue {
30
31
  private final LocalDate date;
32
33
  /**
34
   * Constructor of ExprDateValue.
35
   */
36
  public ExprDateValue(String date) {
37
    try {
38
      this.date = LocalDate.parse(date, DATE_TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL);
39
    } catch (DateTimeParseException e) {
40
      throw new SemanticCheckException(String.format("date:%s in unsupported format, please use "
41
          + "yyyy-MM-dd", date));
42
    }
43
  }
44
45
  @Override
46
  public String value() {
47 1 1. value : replaced return value with "" for org/opensearch/sql/data/model/ExprDateValue::value → KILLED
    return DateTimeFormatter.ISO_LOCAL_DATE.format(date);
48
  }
49
50
  @Override
51
  public ExprType type() {
52 1 1. type : replaced return value with null for org/opensearch/sql/data/model/ExprDateValue::type → KILLED
    return ExprCoreType.DATE;
53
  }
54
55
  @Override
56
  public LocalDate dateValue() {
57 1 1. dateValue : replaced return value with null for org/opensearch/sql/data/model/ExprDateValue::dateValue → KILLED
    return date;
58
  }
59
60
  @Override
61
  public LocalTime timeValue() {
62 1 1. timeValue : replaced return value with null for org/opensearch/sql/data/model/ExprDateValue::timeValue → KILLED
    return LocalTime.of(0, 0, 0);
63
  }
64
65
  @Override
66
  public LocalDateTime datetimeValue() {
67 1 1. datetimeValue : replaced return value with null for org/opensearch/sql/data/model/ExprDateValue::datetimeValue → KILLED
    return LocalDateTime.of(date, timeValue());
68
  }
69
70
  @Override
71
  public Instant timestampValue() {
72 1 1. timestampValue : replaced return value with null for org/opensearch/sql/data/model/ExprDateValue::timestampValue → KILLED
    return ZonedDateTime.of(date, timeValue(), ZoneId.systemDefault()).toInstant();
73
  }
74
75
  @Override
76
  public String toString() {
77 1 1. toString : replaced return value with "" for org/opensearch/sql/data/model/ExprDateValue::toString → KILLED
    return String.format("DATE '%s'", value());
78
  }
79
80
  @Override
81
  public int compare(ExprValue other) {
82 1 1. compare : replaced int return with 0 for org/opensearch/sql/data/model/ExprDateValue::compare → KILLED
    return date.compareTo(other.dateValue());
83
  }
84
85
  @Override
86
  public boolean equal(ExprValue other) {
87 2 1. equal : replaced boolean return with true for org/opensearch/sql/data/model/ExprDateValue::equal → SURVIVED
2. equal : replaced boolean return with false for org/opensearch/sql/data/model/ExprDateValue::equal → KILLED
    return date.equals(other.dateValue());
88
  }
89
90
  @Override
91
  public int hashCode() {
92 1 1. hashCode : replaced int return with 0 for org/opensearch/sql/data/model/ExprDateValue::hashCode → SURVIVED
    return Objects.hashCode(date);
93
  }
94
}

Mutations

47

1.1
Location : value
Killed by : org.opensearch.sql.expression.datetime.DateTimeFunctionTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.datetime.DateTimeFunctionTest]/[method:day()]
replaced return value with "" for org/opensearch/sql/data/model/ExprDateValue::value → KILLED

52

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

57

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

62

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

67

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

72

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

77

1.1
Location : toString
Killed by : org.opensearch.sql.expression.datetime.DateTimeFunctionTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.datetime.DateTimeFunctionTest]/[method:day()]
replaced return value with "" for org/opensearch/sql/data/model/ExprDateValue::toString → KILLED

82

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

87

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/ExprDateValue::equal → KILLED

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

92

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

Active mutators

Tests examined


Report generated by PIT 1.9.0