Skip to content

Commit

Permalink
feat(static): switch partial datetime parser to use UTC by default (#…
Browse files Browse the repository at this point in the history
…3473)

With this change the ROWTIME rewriter and static queries will use UTC by default for datetime strings, if not explicit timezone is provided.
  • Loading branch information
big-andy-coates authored Oct 3, 2019
1 parent 9deb431 commit 81557e3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private static String getTimezone(final String time) {

private static ZoneId parseTimezone(final String timezone) {
if (timezone.trim().isEmpty()) {
return ZoneId.systemDefault();
return ZoneId.of("+0000");
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class PartialStringToTimestampParserTest {

private static final StringToTimestampParser FULL_PARSER =
new StringToTimestampParser(KsqlConstants.DATE_TIME_PATTERN);
new StringToTimestampParser(KsqlConstants.DATE_TIME_PATTERN + "X");

@Rule
public final ExpectedException expectedException = ExpectedException.none();
Expand All @@ -43,44 +43,44 @@ public void init() {
@Test
public void shouldParseYear() {
// When:
assertThat(parser.parse("2017"), is(fullParse("2017-01-01T00:00:00.000")));
assertThat(parser.parse("2017"), is(fullParse("2017-01-01T00:00:00.000+0000")));
}

@Test
public void shouldParseYearMonth() {
// When:
assertThat(parser.parse("2020-02"), is(fullParse("2020-02-01T00:00:00.000")));
assertThat(parser.parse("2020-02"), is(fullParse("2020-02-01T00:00:00.000+0000")));
}

@Test
public void shouldParseFullDate() {
// When:
assertThat(parser.parse("2020-01-02"), is(fullParse("2020-01-02T00:00:00.000")));
assertThat(parser.parse("2020-01-02T"), is(fullParse("2020-01-02T00:00:00.000")));
assertThat(parser.parse("2020-01-02"), is(fullParse("2020-01-02T00:00:00.000+0000")));
assertThat(parser.parse("2020-01-02T"), is(fullParse("2020-01-02T00:00:00.000+0000")));
}

@Test
public void shouldParseDateWithHour() {
// When:
assertThat(parser.parse("2020-12-02T13"), is(fullParse("2020-12-02T13:00:00.000")));
assertThat(parser.parse("2020-12-02T13"), is(fullParse("2020-12-02T13:00:00.000+0000")));
}

@Test
public void shouldParseDateWithHourMinute() {
// When:
assertThat(parser.parse("2020-12-02T13:59"), is(fullParse("2020-12-02T13:59:00.000")));
assertThat(parser.parse("2020-12-02T13:59"), is(fullParse("2020-12-02T13:59:00.000+0000")));
}

@Test
public void shouldParseDateWithHourMinuteSecond() {
// When:
assertThat(parser.parse("2020-12-02T13:59:58"), is(fullParse("2020-12-02T13:59:58.000")));
assertThat(parser.parse("2020-12-02T13:59:58"), is(fullParse("2020-12-02T13:59:58.000+0000")));
}

@Test
public void shouldParseFullDateTime() {
// When:
assertThat(parser.parse("2020-12-02T13:59:58.123"), is(fullParse("2020-12-02T13:59:58.123")));
assertThat(parser.parse("2020-12-02T13:59:58.123"), is(fullParse("2020-12-02T13:59:58.123+0000")));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@
"statements": [
"CREATE STREAM INPUT (IGNORED INT) WITH (kafka_topic='test_topic', value_format='JSON');",
"CREATE TABLE AGGREGATE AS SELECT COUNT(1) AS COUNT FROM INPUT WINDOW TUMBLING(SIZE 1 SECOND) GROUP BY ROWKEY;",
"SELECT * FROM AGGREGATE WHERE ROWKEY='10' AND WindowStart='2020-02-23T23:45:12.000+0000';"
"SELECT * FROM AGGREGATE WHERE ROWKEY='10' AND WindowStart='2020-02-23T23:45:12.000';"
],
"inputs": [
{"topic": "test_topic", "timestamp": 1582501512456, "key": "11", "value": {}},
Expand Down

0 comments on commit 81557e3

Please sign in to comment.