Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
CURRENT_DATE
CURRENT_TIME
CURRENT_TIMESTAMP
LOCALTIME
LOCALTIMESTAMP
CURRENT_USER
keywords
  • Loading branch information
sjyango committed Jan 30, 2024
1 parent c4e6669 commit 441a184
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ CROSS: 'CROSS';
CUBE: 'CUBE';
CURRENT: 'CURRENT';
CURRENT_CATALOG: 'CURRENT_CATALOG';
CURRENT_DATE: 'CURRENT_DATE';
CURRENT_TIME: 'CURRENT_TIME';
CURRENT_TIMESTAMP: 'CURRENT_TIMESTAMP';
CURRENT_USER: 'CURRENT_USER';
DATA: 'DATA';
Expand Down Expand Up @@ -332,6 +334,8 @@ LINK: 'LINK';
LIST: 'LIST';
LOAD: 'LOAD';
LOCAL: 'LOCAL';
LOCALTIME: 'LOCALTIME';
LOCALTIMESTAMP: 'LOCALTIMESTAMP';
LOCATION: 'LOCATION';
LOCK: 'LOCK';
LOGICAL: 'LOGICAL';
Expand Down
11 changes: 11 additions & 0 deletions fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,12 @@ primaryExpression
(INTERVAL unitsAmount=valueExpression unit=datetimeUnit
| unitsAmount=valueExpression)
RIGHT_PAREN #dateCeil
| name=CURRENT_DATE #currentDate
| name=CURRENT_TIME #currentTime
| name=CURRENT_TIMESTAMP #currentTimestamp
| name=LOCALTIME #localTime
| name=LOCALTIMESTAMP #localTimestamp
| name=CURRENT_USER #currentUser
| CASE whenClause+ (ELSE elseExpression=expression)? END #searchedCase
| CASE value=expression whenClause+ (ELSE elseExpression=expression)? END #simpleCase
| name=CAST LEFT_PAREN expression AS dataType RIGHT_PAREN #cast
Expand Down Expand Up @@ -947,7 +953,10 @@ nonReserved
| CREATION
| CRON
| CURRENT_CATALOG
| CURRENT_DATE
| CURRENT_TIME
| CURRENT_TIMESTAMP
| CURRENT_USER
| DATA
| DATE
| DATE_ADD
Expand Down Expand Up @@ -1036,6 +1045,8 @@ nonReserved
| LINES
| LINK
| LOCAL
| LOCALTIME
| LOCALTIMESTAMP
| LOCATION
| LOCK
| LOGICAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@
import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySlice;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Char;
import org.apache.doris.nereids.trees.expressions.functions.scalar.ConvertTo;
import org.apache.doris.nereids.trees.expressions.functions.scalar.CurrentDate;
import org.apache.doris.nereids.trees.expressions.functions.scalar.CurrentTime;
import org.apache.doris.nereids.trees.expressions.functions.scalar.CurrentUser;
import org.apache.doris.nereids.trees.expressions.functions.scalar.DayCeil;
import org.apache.doris.nereids.trees.expressions.functions.scalar.DayFloor;
import org.apache.doris.nereids.trees.expressions.functions.scalar.DaysAdd;
Expand All @@ -285,6 +288,7 @@
import org.apache.doris.nereids.trees.expressions.functions.scalar.MonthsAdd;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MonthsDiff;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MonthsSub;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Now;
import org.apache.doris.nereids.trees.expressions.functions.scalar.SecondCeil;
import org.apache.doris.nereids.trees.expressions.functions.scalar.SecondFloor;
import org.apache.doris.nereids.trees.expressions.functions.scalar.SecondsAdd;
Expand Down Expand Up @@ -1751,6 +1755,36 @@ public Expression visitDateCeil(DateCeilContext ctx) {
+ ", supported time unit: YEAR/MONTH/WEEK/DAY/HOUR/MINUTE/SECOND", ctx);
}

@Override
public Expression visitCurrentDate(DorisParser.CurrentDateContext ctx) {
return new CurrentDate().alias("CURRENT_DATE");
}

@Override
public Expression visitCurrentTime(DorisParser.CurrentTimeContext ctx) {
return new CurrentTime().alias("CURRENT_TIME");
}

@Override
public Expression visitCurrentTimestamp(DorisParser.CurrentTimestampContext ctx) {
return new Now().alias("CURRENT_TIMESTAMP");
}

@Override
public Expression visitLocalTime(DorisParser.LocalTimeContext ctx) {
return new CurrentTime().alias("LOCALTIME");
}

@Override
public Expression visitLocalTimestamp(DorisParser.LocalTimestampContext ctx) {
return new Now().alias("LOCALTIMESTAMP");
}

@Override
public Expression visitCurrentUser(DorisParser.CurrentUserContext ctx) {
return new CurrentUser().alias("CURRENT_USER");
}

@Override
public Expression visitDoublePipes(DorisParser.DoublePipesContext ctx) {
return ParserUtils.withOrigin(ctx, () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ suite("test_date_acquire") {
sql 'set enable_fallback_to_original_planner=false'
sql 'set enable_fold_nondeterministic_fn=true'

String res = sql 'explain select now(), now(3), curdate(), current_date(), current_timestamp(), current_timestamp(3)'
res = res.split('VUNION')[1]
assertFalse(res.contains("()") || res.contains("(3)"))
String res1 = sql 'explain select now(), now(3), curdate(), current_date(), current_timestamp(), current_timestamp(3)'
res1 = res1.split('VUNION')[1]
assertFalse(res1.contains("()") || res1.contains("(3)"))

String res2 = sql 'explain select CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, LOCALTIME, LOCALTIMESTAMP, CURRENT_USER'
assertTrue(res2.contains("CURRENT_DATE") || res2.contains("CURRENT_TIME") || res2.contains("CURRENT_TIMESTAMP") || res2.contains("LOCALTIME") || res2.contains("LOCALTIMESTAMP") || res2.contains("CURRENT_USER"))

sql "set enable_fold_constant_by_be=true"

Expand Down

0 comments on commit 441a184

Please sign in to comment.