From 3e3930c5bfe17ca92995fda61585ec16791bc55e Mon Sep 17 00:00:00 2001 From: MitchellGale-BitQuill Date: Mon, 19 Sep 2022 01:18:51 -0700 Subject: [PATCH] Adding base structure for UTC_TIME UTC_DATE UTC_TIMESTAMP Signed-off-by: MitchellGale-BitQuill --- .../org/opensearch/sql/expression/DSL.java | 12 +++++ .../expression/datetime/DateTimeFunction.java | 54 +++++++++++++++++++ .../function/BuiltinFunctionName.java | 3 ++ ppl/src/main/antlr/OpenSearchPPLLexer.g4 | 3 ++ ppl/src/main/antlr/OpenSearchPPLParser.g4 | 2 +- sql/src/main/antlr/OpenSearchSQLLexer.g4 | 3 ++ sql/src/main/antlr/OpenSearchSQLParser.g4 | 3 +- 7 files changed, 78 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/opensearch/sql/expression/DSL.java b/core/src/main/java/org/opensearch/sql/expression/DSL.java index bd2d075613..dcc5352136 100644 --- a/core/src/main/java/org/opensearch/sql/expression/DSL.java +++ b/core/src/main/java/org/opensearch/sql/expression/DSL.java @@ -359,6 +359,18 @@ public FunctionExpression to_days(Expression... expressions) { return function(BuiltinFunctionName.TO_DAYS, expressions); } + public FunctionExpression utc_date(Expression... expressions) { + return function(BuiltinFunctionName.UTC_DATE, expressions); + } + + public FunctionExpression utc_time(Expression... expressions) { + return function(BuiltinFunctionName.UTC_TIME, expressions); + } + + public FunctionExpression utc_timestamp(Expression... expressions) { + return function(BuiltinFunctionName.UTC_TIMESTAMP, expressions); + } + public FunctionExpression week(Expression... expressions) { return function(BuiltinFunctionName.WEEK, expressions); } diff --git a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java index 469f7e2011..407e2ff1e2 100644 --- a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java @@ -81,6 +81,9 @@ public void register(BuiltinFunctionRepository repository) { repository.register(time()); repository.register(time_to_sec()); repository.register(timestamp()); + repository.register(utc_date()); + repository.register(utc_time()); + repository.register(utc_timestamp()); repository.register(date_format()); repository.register(to_days()); repository.register(week()); @@ -379,6 +382,30 @@ private DefaultFunctionResolver to_days() { impl(nullMissingHandling(DateTimeFunction::exprToDays), LONG, DATETIME)); } + /** + * UTC_DATE(). return the current UTC Date + */ + private DefaultFunctionResolver utc_date() { + return define(BuiltinFunctionName.UTC_DATE.getName(), + impl(nullMissingHandling(DateTimeFunction::exprUtcDate), DATE)); + } + + /** + * UTC_TIME(). return the current UTC Time + */ + private DefaultFunctionResolver utc_time() { + return define(BuiltinFunctionName.UTC_TIME.getName(), + impl(nullMissingHandling(DateTimeFunction::exprUtcTime), TIME)); + } + + /** + * UTC_TIMESTAMP(). return the current UTC TimeStamp + */ + private DefaultFunctionResolver utc_timestamp() { + return define(BuiltinFunctionName.UTC_TIMESTAMP.getName(), + impl(nullMissingHandling(DateTimeFunction::exprUtcTimeStamp), TIMESTAMP)); + } + /** * WEEK(DATE[,mode]). return the week number for date. */ @@ -700,6 +727,33 @@ private ExprValue exprTimeToSec(ExprValue time) { return new ExprLongValue(time.timeValue().toSecondOfDay()); } + /** + * To_days implementation for ExprValue. + * + * @return ExprValue. + */ + private ExprValue exprUtcDate() { + return new ExprDateValue(); + } + + /** + * To_days implementation for ExprValue. + * + * @return ExprValue. + */ + private ExprValue exprUtcTime() { + return new ExprTimeValue(); + } + + /** + * To_days implementation for ExprValue. + * + * @return ExprValue. + */ + private ExprValue exprUtcTimeStamp() { + return new ExprTimestampValue(); + } + /** * To_days implementation for ExprValue. * diff --git a/core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionName.java b/core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionName.java index b3821d6e41..3f3cb10df8 100644 --- a/core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionName.java +++ b/core/src/main/java/org/opensearch/sql/expression/function/BuiltinFunctionName.java @@ -82,6 +82,9 @@ public enum BuiltinFunctionName { TIMESTAMP(FunctionName.of("timestamp")), DATE_FORMAT(FunctionName.of("date_format")), TO_DAYS(FunctionName.of("to_days")), + UTC_DATE(FunctionName.of("utc_date")), + UTC_TIME(FunctionName.of("utc_time")), + UTC_TIMESTAMP(FunctionName.of("utc_timestamp")), WEEK(FunctionName.of("week")), YEAR(FunctionName.of("year")), diff --git a/ppl/src/main/antlr/OpenSearchPPLLexer.g4 b/ppl/src/main/antlr/OpenSearchPPLLexer.g4 index 93df64d0b3..525c3bbbfc 100644 --- a/ppl/src/main/antlr/OpenSearchPPLLexer.g4 +++ b/ppl/src/main/antlr/OpenSearchPPLLexer.g4 @@ -101,6 +101,9 @@ DAY_MICROSECOND: 'DAY_MICROSECOND'; DAY_SECOND: 'DAY_SECOND'; DAY_MINUTE: 'DAY_MINUTE'; DAY_HOUR: 'DAY_HOUR'; +UTC_DATE: 'UTC_DATE'; +UTC_TIME: 'UTC_TIME'; +UTC_TIMESTAMP: 'UTC_TIMESTAMP'; YEAR_MONTH: 'YEAR_MONTH'; // DATASET TYPES diff --git a/ppl/src/main/antlr/OpenSearchPPLParser.g4 b/ppl/src/main/antlr/OpenSearchPPLParser.g4 index c83297459d..564748a015 100644 --- a/ppl/src/main/antlr/OpenSearchPPLParser.g4 +++ b/ppl/src/main/antlr/OpenSearchPPLParser.g4 @@ -334,7 +334,7 @@ relevanceArgName | FUZZY_REWRITE | FUZZY_TRANSPOSITIONS | LENIENT | LOW_FREQ_OPERATOR | MAX_DETERMINIZED_STATES | MAX_EXPANSIONS | MINIMUM_SHOULD_MATCH | OPERATOR | PHRASE_SLOP | PREFIX_LENGTH | QUOTE_ANALYZER | QUOTE_FIELD_SUFFIX | REWRITE | SLOP | TIE_BREAKER | TIME_ZONE | TYPE - | ZERO_TERMS_QUERY + | UTC_DATE | UTC_TIME | UTC_DATETIME | ZERO_TERMS_QUERY ; relevanceFieldAndWeight diff --git a/sql/src/main/antlr/OpenSearchSQLLexer.g4 b/sql/src/main/antlr/OpenSearchSQLLexer.g4 index 6d2d7d8a64..b011aaeaa3 100644 --- a/sql/src/main/antlr/OpenSearchSQLLexer.g4 +++ b/sql/src/main/antlr/OpenSearchSQLLexer.g4 @@ -246,6 +246,9 @@ TIMESTAMP: 'TIMESTAMP'; TRUNCATE: 'TRUNCATE'; TO_DAYS: 'TO_DAYS'; UPPER: 'UPPER'; +UTC_DATE: 'UTC_DATE'; +UTC_TIME: 'UTC_TIME'; +UTC_TIMESTAMP: 'UTC_TIMESTAMP'; D: 'D'; T: 'T'; diff --git a/sql/src/main/antlr/OpenSearchSQLParser.g4 b/sql/src/main/antlr/OpenSearchSQLParser.g4 index 40207df82a..6ff2ea35bf 100644 --- a/sql/src/main/antlr/OpenSearchSQLParser.g4 +++ b/sql/src/main/antlr/OpenSearchSQLParser.g4 @@ -385,7 +385,8 @@ trigonometricFunctionName dateTimeFunctionName : ADDDATE | DATE | DATE_ADD | DATE_SUB | DAY | DAYNAME | DAYOFMONTH | DAYOFWEEK | DAYOFYEAR | FROM_DAYS | HOUR | MICROSECOND | MINUTE | MONTH | MONTHNAME | QUARTER | SECOND | SUBDATE | TIME | TIME_TO_SEC - | TIMESTAMP | TO_DAYS | YEAR | WEEK | DATE_FORMAT | MAKETIME | MAKEDATE + | TIMESTAMP | TO_DAYS | YEAR | WEEK | DATE_FORMAT | MAKETIME | MAKEDATE | UTC_DATE | UTC_TIME + | UTC_DATETIME ; textFunctionName