Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
add support for HH:mm:ss (#850)
Browse files Browse the repository at this point in the history
* add STRICT_DATE_FORMATTER

* fix chekstyle error

* update for HH:MM:SS

Co-authored-by: Rupal Mahajan <>
  • Loading branch information
rupal-bq authored Nov 25, 2020
1 parent 2f6ec33 commit 200a76d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public class ElasticsearchDateFormatters {
.toFormatter(Locale.ROOT)
.withResolverStyle(ResolverStyle.STRICT);

public static final DateTimeFormatter STRICT_HOUR_MINUTE_SECOND_FORMATTER =
new DateTimeFormatterBuilder()
.appendValue(HOUR_OF_DAY, 2, 2, SignStyle.NOT_NEGATIVE)
.appendLiteral(':')
.appendValue(MINUTE_OF_HOUR, 2, 2, SignStyle.NOT_NEGATIVE)
.appendLiteral(':')
.appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE)
.toFormatter(Locale.ROOT)
.withResolverStyle(ResolverStyle.STRICT);

public static final DateTimeFormatter STRICT_DATE_OPTIONAL_TIME_FORMATTER =
new DateTimeFormatterBuilder()
.append(STRICT_YEAR_MONTH_DAY_FORMATTER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import static com.amazon.opendistroforelasticsearch.sql.elasticsearch.data.type.ElasticsearchDataType.ES_TEXT_KEYWORD;
import static com.amazon.opendistroforelasticsearch.sql.elasticsearch.data.value.ElasticsearchDateFormatters.SQL_LITERAL_DATE_TIME_FORMAT;
import static com.amazon.opendistroforelasticsearch.sql.elasticsearch.data.value.ElasticsearchDateFormatters.STRICT_DATE_OPTIONAL_TIME_FORMATTER;
import static com.amazon.opendistroforelasticsearch.sql.elasticsearch.data.value.ElasticsearchDateFormatters.STRICT_HOUR_MINUTE_SECOND_FORMATTER;

import com.amazon.opendistroforelasticsearch.sql.data.model.ExprBooleanValue;
import com.amazon.opendistroforelasticsearch.sql.data.model.ExprByteValue;
Expand Down Expand Up @@ -77,6 +78,7 @@ public class ElasticsearchExprValueFactory {
new DateTimeFormatterBuilder()
.appendOptional(SQL_LITERAL_DATE_TIME_FORMAT)
.appendOptional(STRICT_DATE_OPTIONAL_TIME_FORMATTER)
.appendOptional(STRICT_HOUR_MINUTE_SECOND_FORMATTER)
.toFormatter();

private static final String TOP_PATH = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.amazon.opendistroforelasticsearch.sql.data.model.ExprCollectionValue;
import com.amazon.opendistroforelasticsearch.sql.data.model.ExprTimeValue;
import com.amazon.opendistroforelasticsearch.sql.data.model.ExprTimestampValue;
import com.amazon.opendistroforelasticsearch.sql.data.model.ExprTupleValue;
import com.amazon.opendistroforelasticsearch.sql.data.model.ExprValue;
Expand Down Expand Up @@ -169,11 +170,14 @@ public void constructDate() {
new ExprTimestampValue("2015-01-01 12:10:30"),
tupleValue("{\"dateV\":\"2015-01-01T12:10:30\"}").get("dateV"));
assertEquals(
new ExprTimestampValue("2015-01-01 12:10:30"),
tupleValue("{\"dateV\":\"2015-01-01 12:10:30\"}").get("dateV"));
new ExprTimestampValue("2015-01-01 12:10:30"),
tupleValue("{\"dateV\":\"2015-01-01 12:10:30\"}").get("dateV"));
assertEquals(
new ExprTimestampValue(Instant.ofEpochMilli(1420070400001L)),
tupleValue("{\"dateV\":1420070400001}").get("dateV"));
assertEquals(
new ExprTimeValue("19:36:22"),
tupleValue("{\"dateV\":\"19:36:22\"}").get("dateV"));

assertEquals(
new ExprTimestampValue(Instant.ofEpochMilli(1420070400001L)),
Expand Down

0 comments on commit 200a76d

Please sign in to comment.