Skip to content

Commit

Permalink
Adding base structure for UTC_TIME UTC_DATE UTC_TIMESTAMP
Browse files Browse the repository at this point in the history
Signed-off-by: MitchellGale-BitQuill <[email protected]>
  • Loading branch information
MitchellGale committed Sep 19, 2022
1 parent 929ebfe commit 3e3930c
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 2 deletions.
12 changes: 12 additions & 0 deletions core/src/main/java/org/opensearch/sql/expression/DSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")),

Expand Down
3 changes: 3 additions & 0 deletions ppl/src/main/antlr/OpenSearchPPLLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ppl/src/main/antlr/OpenSearchPPLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions sql/src/main/antlr/OpenSearchSQLLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 2 additions & 1 deletion sql/src/main/antlr/OpenSearchSQLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3e3930c

Please sign in to comment.