Skip to content

Commit

Permalink
rebasing upstream changes and fixing formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Wells <matthew.wells@improving.com>
  • Loading branch information
matthewryanwells committed Aug 14, 2023
1 parent 43a394e commit 13e9db1
Show file tree
Hide file tree
Showing 23 changed files with 171 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.google.common.base.Objects;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeParseException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ public ExprTimestampValue(String timestamp) {
}

/** localDateTime Constructor. */
public ExprTimestampValue(LocalDateTime localDateTime ) {
this.timestamp = localDateTime
.atZone(UTC_ZONE_ID)
.toInstant();
public ExprTimestampValue(LocalDateTime localDateTime) {
this.timestamp = localDateTime.atZone(UTC_ZONE_ID).toInstant();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.io.Serializable;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.TemporalAmount;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ public void avg_time() {
public void avg_timestamp() {
var result = aggregation(DSL.avg(DSL.timestamp(DSL.ref("timestamp_value", STRING))), tuples);
assertEquals(TIMESTAMP, result.type());
assertEquals(LocalDateTime.of(2012, 7, 2, 3, 30), result.timestampValue().atZone(UTC_ZONE_ID).toLocalDateTime());
assertEquals(
LocalDateTime.of(2012, 7, 2, 3, 30),
result.timestampValue().atZone(UTC_ZONE_ID).toLocalDateTime());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,35 +78,43 @@ private static Stream<Arguments> getTestData() {
Arguments.of(
LocalDate.of(1961, 4, 12),
LocalTime.of(9, 7),
LocalDateTime.of(1961, 4, 12, 9, 7),
LocalDateTime.of(1961, 4, 11, 14, 53)),
Arguments.of(
LocalDate.of(1961, 4, 12),
LocalDate.of(2000, 1, 1),
LocalDateTime.of(1961, 4, 12, 0, 0),
LocalDateTime.of(1961, 4, 12, 0, 0)),
Arguments.of(
LocalDate.of(1961, 4, 12),
LocalDateTime.of(1235, 5, 6, 1, 48),
LocalDateTime.of(1961, 4, 12, 1, 48),
LocalDateTime.of(1961, 4, 11, 22, 12)),
Arguments.of(
LocalDate.of(1961, 4, 12),
Instant.ofEpochSecond(42),
LocalDateTime.of(1961, 4, 12, 0, 0, 42),
LocalDateTime.of(1961, 4, 11, 23, 59, 18)),
// TIMESTAMP and TIME/DATE/TIMESTAMP
Arguments.of(
Instant.ofEpochSecond(42),
LocalTime.of(9, 7),
LocalDateTime.of(1970, 1, 1, 9, 7, 42),
LocalDateTime.of(1969, 12, 31, 14, 53, 42)),
Arguments.of(
Instant.ofEpochSecond(42),
LocalDate.of(1961, 4, 12),
LocalDateTime.of(1970, 1, 1, 0, 0, 42),
LocalDateTime.of(1970, 1, 1, 0, 0, 42)),
Arguments.of(
Instant.ofEpochSecond(42),
LocalDateTime.of(1961, 4, 12, 9, 7),
LocalDateTime.of(1970, 1, 1, 9, 7, 42),
LocalDateTime.of(1969, 12, 31, 14, 53, 42)),
Arguments.of(
Instant.ofEpochSecond(42),
Instant.ofEpochMilli(42),
LocalDateTime.of(1970, 1, 1, 0, 0, 42, 42000000),
LocalDateTime.of(1970, 1, 1, 0, 0, 41, 958000000)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,18 @@ class ConvertTZTest extends ExpressionTestBase {
public void invalidDate() {
FunctionExpression expr =
DSL.convert_tz(
DSL.datetime(DSL.literal("2021-04-31 10:00:00")),
DSL.timestamp(DSL.literal("2021-04-31 10:00:00")),
DSL.literal("+00:00"),
DSL.literal("+00:00"));
assertEquals(TIMESTAMP, expr.type());
assertThrows(SemanticCheckException.class,
expr::valueOf
);
assertThrows(SemanticCheckException.class, expr::valueOf);
}

@Test
public void conversionFromNoOffset() {
FunctionExpression expr =
DSL.convert_tz(
DSL.datetime(DSL.literal("2008-05-15 22:00:00")),
DSL.timestamp(DSL.literal("2008-05-15 22:00:00")),
DSL.literal("+00:00"),
DSL.literal("+10:00"));
assertEquals(TIMESTAMP, expr.type());
Expand All @@ -47,7 +45,7 @@ public void conversionFromNoOffset() {
public void conversionToInvalidInput3Over() {
FunctionExpression expr =
DSL.convert_tz(
DSL.datetime(DSL.literal("2008-05-15 22:00:00")),
DSL.timestamp(DSL.literal("2008-05-15 22:00:00")),
DSL.literal("+00:00"),
DSL.literal("+16:00"));
assertEquals(TIMESTAMP, expr.type());
Expand All @@ -58,7 +56,7 @@ public void conversionToInvalidInput3Over() {
public void conversionToInvalidInput3Under() {
FunctionExpression expr =
DSL.convert_tz(
DSL.datetime(DSL.literal("2008-05-15 22:00:00")),
DSL.timestamp(DSL.literal("2008-05-15 22:00:00")),
DSL.literal("+00:00"),
DSL.literal("-16:00"));
assertEquals(TIMESTAMP, expr.type());
Expand All @@ -69,7 +67,7 @@ public void conversionToInvalidInput3Under() {
public void conversionFromPositiveToPositive() {
FunctionExpression expr =
DSL.convert_tz(
DSL.datetime(DSL.literal("2008-05-15 22:00:00")),
DSL.timestamp(DSL.literal("2008-05-15 22:00:00")),
DSL.literal("+15:00"),
DSL.literal("+01:00"));
assertEquals(TIMESTAMP, expr.type());
Expand All @@ -80,7 +78,7 @@ public void conversionFromPositiveToPositive() {
public void invalidInput2Under() {
FunctionExpression expr =
DSL.convert_tz(
DSL.datetime(DSL.literal("2008-05-15 22:00:00")),
DSL.timestamp(DSL.literal("2008-05-15 22:00:00")),
DSL.literal("-15:00"),
DSL.literal("+01:00"));
assertEquals(TIMESTAMP, expr.type());
Expand All @@ -91,7 +89,7 @@ public void invalidInput2Under() {
public void invalidInput3Over() {
FunctionExpression expr =
DSL.convert_tz(
DSL.datetime(DSL.literal("2008-05-15 22:00:00")),
DSL.timestamp(DSL.literal("2008-05-15 22:00:00")),
DSL.literal("-12:00"),
DSL.literal("+15:00"));
assertEquals(TIMESTAMP, expr.type());
Expand All @@ -102,7 +100,7 @@ public void invalidInput3Over() {
public void conversionToPositiveEdge() {
FunctionExpression expr =
DSL.convert_tz(
DSL.datetime(DSL.literal("2008-05-15 22:00:00")),
DSL.timestamp(DSL.literal("2008-05-15 22:00:00")),
DSL.literal("+00:00"),
DSL.literal("+14:00"));
assertEquals(TIMESTAMP, expr.type());
Expand All @@ -113,7 +111,7 @@ public void conversionToPositiveEdge() {
public void conversionToNegativeEdge() {
FunctionExpression expr =
DSL.convert_tz(
DSL.datetime(DSL.literal("2008-05-15 22:00:00")),
DSL.timestamp(DSL.literal("2008-05-15 22:00:00")),
DSL.literal("+00:01"),
DSL.literal("-13:59"));
assertEquals(TIMESTAMP, expr.type());
Expand All @@ -124,7 +122,7 @@ public void conversionToNegativeEdge() {
public void invalidInput2() {
FunctionExpression expr =
DSL.convert_tz(
DSL.datetime(DSL.literal("2008-05-15 22:00:00")),
DSL.timestamp(DSL.literal("2008-05-15 22:00:00")),
DSL.literal("+)()"),
DSL.literal("+12:00"));
assertEquals(TIMESTAMP, expr.type());
Expand All @@ -135,7 +133,7 @@ public void invalidInput2() {
public void invalidInput3() {
FunctionExpression expr =
DSL.convert_tz(
DSL.datetime(DSL.literal("2008-05-15 22:00:00")),
DSL.timestamp(DSL.literal("2008-05-15 22:00:00")),
DSL.literal("+00:00"),
DSL.literal("test"));
assertEquals(TIMESTAMP, expr.type());
Expand All @@ -154,35 +152,32 @@ public void invalidInput1() {
public void invalidDateFeb30() {
FunctionExpression expr =
DSL.convert_tz(
DSL.datetime(DSL.literal("2021-02-30 10:00:00")),
DSL.timestamp(DSL.literal("2021-02-30 10:00:00")),
DSL.literal("+00:00"),
DSL.literal("+00:00"));
assertEquals(TIMESTAMP, expr.type());
assertThrows(SemanticCheckException.class,
expr::valueOf);
assertThrows(SemanticCheckException.class, expr::valueOf);
}

@Test
public void invalidDateApril31() {
FunctionExpression expr =
DSL.convert_tz(
DSL.datetime(DSL.literal("2021-04-31 10:00:00")),
DSL.timestamp(DSL.literal("2021-04-31 10:00:00")),
DSL.literal("+00:00"),
DSL.literal("+00:00"));
assertEquals(TIMESTAMP, expr.type());
assertThrows(SemanticCheckException.class,
expr::valueOf);
assertThrows(SemanticCheckException.class, expr::valueOf);
}

@Test
public void invalidMonth13() {
FunctionExpression expr =
DSL.convert_tz(
DSL.datetime(DSL.literal("2021-13-03 10:00:00")),
DSL.timestamp(DSL.literal("2021-13-03 10:00:00")),
DSL.literal("+00:00"),
DSL.literal("+00:00"));
assertEquals(TIMESTAMP, expr.type());
assertThrows(SemanticCheckException.class,
expr::valueOf);
assertThrows(SemanticCheckException.class, expr::valueOf);
}
}
Loading

0 comments on commit 13e9db1

Please sign in to comment.