From 982070107125d33cadb107334c45740a84df3b76 Mon Sep 17 00:00:00 2001 From: vamsi-amazon Date: Fri, 4 Mar 2022 08:45:16 -0800 Subject: [PATCH 1/8] Supported ISO 8601 Format by allowing basic characters Signed-off-by: vamsi-amazon --- .../datetime/DateTimeFormatterUtil.java | 10 +++++++++- .../opensearch/sql/ppl/DateTimeFunctionIT.java | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java index 02fb3a6915..44643cd186 100644 --- a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java +++ b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java @@ -79,6 +79,7 @@ interface DateTimeFormatHandler { .build(); private static final Pattern pattern = Pattern.compile("%."); + private static final Pattern CHARACTERS_WITH_NO_MOD_LITERAL_BEHIND_PATTERN = Pattern.compile("(? Date: Fri, 4 Mar 2022 08:56:35 -0800 Subject: [PATCH 2/8] Fixed Checkstyle Error Signed-off-by: vamsi-amazon --- .../sql/expression/datetime/DateTimeFormatterUtil.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java index 44643cd186..d076b39ebe 100644 --- a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java +++ b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java @@ -79,7 +79,8 @@ interface DateTimeFormatHandler { .build(); private static final Pattern pattern = Pattern.compile("%."); - private static final Pattern CHARACTERS_WITH_NO_MOD_LITERAL_BEHIND_PATTERN = Pattern.compile("(? Date: Fri, 4 Mar 2022 09:43:01 -0800 Subject: [PATCH 3/8] Added Unit Tests Signed-off-by: vamsi-amazon --- .../sql/expression/datetime/DateTimeFunctionTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java index 11b10dfa7f..8594d3dde3 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java @@ -123,7 +123,10 @@ public void setup() { new DateFormatTester("2008-12-31", ImmutableList.of("%v","%V","%u","%U"), ImmutableList.of("53","52","53","52") - ) + ), + new DateFormatTester("1998-01-31 13:14:15.012345", + ImmutableList.of("%Y-%m-%dT%TZ"), + ImmutableList.of("1998-01-31T13:14:15Z")) ); @AllArgsConstructor From d678648ed697ff703367de997b470c6e2de34dde Mon Sep 17 00:00:00 2001 From: vamsi-amazon Date: Fri, 4 Mar 2022 10:39:40 -0800 Subject: [PATCH 4/8] Fixed Integration Tests Signed-off-by: vamsi-amazon --- .../sql/expression/datetime/DateTimeFormatterUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java index d076b39ebe..aabc25c665 100644 --- a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java +++ b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java @@ -80,7 +80,7 @@ interface DateTimeFormatHandler { private static final Pattern pattern = Pattern.compile("%."); private static final Pattern CHARACTERS_WITH_NO_MOD_LITERAL_BEHIND_PATTERN - = Pattern.compile("(? Date: Fri, 4 Mar 2022 11:05:09 -0800 Subject: [PATCH 5/8] Corrected regex to exclude Hours, Seconds, Minutes Signed-off-by: vamsi-amazon --- .../sql/expression/datetime/DateTimeFormatterUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java index aabc25c665..153776d83a 100644 --- a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java +++ b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java @@ -80,7 +80,7 @@ interface DateTimeFormatHandler { private static final Pattern pattern = Pattern.compile("%."); private static final Pattern CHARACTERS_WITH_NO_MOD_LITERAL_BEHIND_PATTERN - = Pattern.compile("(? Date: Fri, 4 Mar 2022 11:12:04 -0800 Subject: [PATCH 6/8] Corrected regex to exclude few more edge cases Signed-off-by: vamsi-amazon --- .../sql/expression/datetime/DateTimeFormatterUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java index 153776d83a..d351a8808a 100644 --- a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java +++ b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFormatterUtil.java @@ -80,7 +80,7 @@ interface DateTimeFormatHandler { private static final Pattern pattern = Pattern.compile("%."); private static final Pattern CHARACTERS_WITH_NO_MOD_LITERAL_BEHIND_PATTERN - = Pattern.compile("(? Date: Fri, 4 Mar 2022 17:15:04 -0800 Subject: [PATCH 7/8] Added additional test cases and updated docs Signed-off-by: vamsi-amazon --- .../sql/expression/datetime/DateTimeFunctionTest.java | 10 +++++++++- docs/user/dql/functions.rst | 2 ++ docs/user/ppl/functions/datetime.rst | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java index 8594d3dde3..79efa2a015 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java @@ -126,7 +126,15 @@ public void setup() { ), new DateFormatTester("1998-01-31 13:14:15.012345", ImmutableList.of("%Y-%m-%dT%TZ"), - ImmutableList.of("1998-01-31T13:14:15Z")) + ImmutableList.of("1998-01-31T13:14:15Z") + ), + new DateFormatTester("1998-01-31 13:14:15.012345", + ImmutableList.of("%Y-%m-%da %T a"), + ImmutableList.of("1998-01-31PM 13:14:15 PM") + ), + new DateFormatTester("1998-01-31 13:14:15.012345", + ImmutableList.of("%Y-%m-%db %T b"), + ImmutableList.of("1998-01-31b 13:14:15 b")) ); @AllArgsConstructor diff --git a/docs/user/dql/functions.rst b/docs/user/dql/functions.rst index cd6be34383..188c326f6d 100644 --- a/docs/user/dql/functions.rst +++ b/docs/user/dql/functions.rst @@ -1004,6 +1004,8 @@ Usage: date_format(date, format) formats the date argument using the specifiers - A literal % character * - %x - x, for any “x” not listed above + * - x + - x, for any smallcase/uppercase alphabet except [aydmshiHIMYDSEL] Argument type: STRING/DATE/DATETIME/TIMESTAMP, STRING diff --git a/docs/user/ppl/functions/datetime.rst b/docs/user/ppl/functions/datetime.rst index 01293f8853..5be5686c34 100644 --- a/docs/user/ppl/functions/datetime.rst +++ b/docs/user/ppl/functions/datetime.rst @@ -173,6 +173,8 @@ Usage: date_format(date, format) formats the date argument using the specifiers - A literal % character * - %x - x, for any “x” not listed above + * - x + - x, for any smallcase/uppercase alphabet except [aydmshiHIMYDSEL] Argument type: STRING/DATE/DATETIME/TIMESTAMP, STRING From 38ae7ca6d7a476228d4017ba45343abaa4677f71 Mon Sep 17 00:00:00 2001 From: vamsi-amazon Date: Fri, 4 Mar 2022 17:55:51 -0800 Subject: [PATCH 8/8] Fixed ITs Signed-off-by: vamsi-amazon --- .../script/aggregation/dsl/BucketAggregationBuilderTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/BucketAggregationBuilderTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/BucketAggregationBuilderTest.java index 4abdb6e076..5c158e0940 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/BucketAggregationBuilderTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/BucketAggregationBuilderTest.java @@ -94,6 +94,7 @@ void should_build_bucket_with_parse_expression() { + " \"lang\" : \"opensearch_query_expression\"\n" + " },\n" + " \"missing_bucket\" : true,\n" + + " \"missing_order\" : \"first\",\n" + " \"order\" : \"asc\"\n" + " }\n" + "}",