[date](parser) Support DateV1 keyword (#25414)

This commit is contained in:
Gabriel
2023-10-30 18:39:22 +08:00
committed by GitHub
parent 6761dc4113
commit 6eb2cb2d48
10 changed files with 174 additions and 3 deletions

View File

@ -439,6 +439,18 @@ public class ScalarType extends Type {
}
}
@SuppressWarnings("checkstyle:MissingJavadocMethod")
public static ScalarType createDatetimeV1Type() {
Preconditions.checkState(!Config.disable_datev1, "Datev1 is disable in fe.conf!");
return new ScalarType(PrimitiveType.DATETIME);
}
@SuppressWarnings("checkstyle:MissingJavadocMethod")
public static ScalarType createDateV1Type() {
Preconditions.checkState(!Config.disable_datev1, "Datev1 is disable in fe.conf!");
return new ScalarType(PrimitiveType.DATE);
}
@SuppressWarnings("checkstyle:MissingJavadocMethod")
public static ScalarType createTimeType() {
if (!Config.enable_date_conversion) {

View File

@ -187,6 +187,8 @@ DATEDIFF: 'DATEDIFF';
DATETIME: 'DATETIME';
DATETIMEV2: 'DATETIMEV2';
DATEV2: 'DATEV2';
DATETIMEV1: 'DATETIMEV1';
DATEV1: 'DATEV1';
DAY: 'DAY';
DAYS_ADD: 'DAYS_ADD';
DAYS_SUB: 'DAYS_SUB';

View File

@ -683,7 +683,7 @@ specifiedPartition
constant
: NULL #nullLiteral
| type=(DATE | DATEV2 | TIMESTAMP) STRING_LITERAL #typeConstructor
| type=(DATE | DATEV1 | DATEV2 | TIMESTAMP) STRING_LITERAL #typeConstructor
| number #numericLiteral
| booleanValue #booleanLiteral
| STRING_LITERAL #stringLiteral
@ -735,6 +735,8 @@ primitiveColType:
| type=TIME
| type=DATEV2
| type=DATETIMEV2
| type=DATEV1
| type=DATETIMEV1
| type=BITMAP
| type=QUANTILE_STATE
| type=HLL
@ -876,6 +878,8 @@ nonReserved
| DATETIME
| DATETIMEV2
| DATEV2
| DATETIMEV1
| DATEV1
| DAY
| DAYS_ADD
| DAYS_SUB

View File

@ -328,6 +328,8 @@ terminal String
KW_DATETIME,
KW_DATETIMEV2,
KW_DATEV2,
KW_DATETIMEV1,
KW_DATEV1,
KW_DAY,
KW_DECIMAL,
KW_DECIMALV3,
@ -6362,6 +6364,10 @@ type ::=
{: RESULT = ScalarType.createDatetimeV2Type(precision.intValue()); :}
| KW_DATETIME
{: RESULT = ScalarType.createDatetimeType(); :}
| KW_DATEV1
{: RESULT = ScalarType.createDateV1Type(); :}
| KW_DATETIMEV1
{: RESULT = ScalarType.createDatetimeV1Type(); :}
| KW_TIME LPAREN INTEGER_LITERAL:precision RPAREN
{: RESULT = ScalarType.createTimeV2Type(precision.intValue()); :}
| KW_TIME
@ -6750,6 +6756,8 @@ non_pred_expr ::=
{: RESULT = e; :}
| KW_DATE STRING_LITERAL:l
{: RESULT = new CastExpr(TypeDef.create(PrimitiveType.DATE), new StringLiteral(l)); :}
| KW_DATEV1 STRING_LITERAL:l
{: RESULT = new CastExpr(TypeDef.create(PrimitiveType.DATE), new StringLiteral(l)); :}
| KW_DATEV2 STRING_LITERAL:l
{: RESULT = new CastExpr(TypeDef.create(PrimitiveType.DATEV2), new StringLiteral(l)); :}
| KW_TIMESTAMP STRING_LITERAL:l
@ -7567,6 +7575,10 @@ keyword ::=
{: RESULT = id; :}
| KW_DATETIMEV2:id
{: RESULT = id; :}
| KW_DATEV1:id
{: RESULT = id; :}
| KW_DATETIMEV1:id
{: RESULT = id; :}
| KW_DECIMAL:id
{: RESULT = id; :}
| KW_DEFERRED:id

View File

@ -1646,6 +1646,8 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
return Config.enable_date_conversion ? new DateTimeV2Literal(value) : new DateTimeLiteral(value);
case "DATEV2":
return new DateV2Literal(value);
case "DATEV1":
return new DateLiteral(value);
default:
throw new ParseException("Unsupported data type : " + type, ctx);
}

View File

@ -174,8 +174,10 @@ import org.apache.doris.qe.SqlModeHelper;
keywordMap.put("database", new Integer(SqlParserSymbols.KW_DATABASE));
keywordMap.put("databases", new Integer(SqlParserSymbols.KW_DATABASES));
keywordMap.put("date", new Integer(SqlParserSymbols.KW_DATE));
keywordMap.put("datev1", new Integer(SqlParserSymbols.KW_DATEV1));
keywordMap.put("datev2", new Integer(SqlParserSymbols.KW_DATEV2));
keywordMap.put("datetime", new Integer(SqlParserSymbols.KW_DATETIME));
keywordMap.put("datetimev1", new Integer(SqlParserSymbols.KW_DATETIMEV1));
keywordMap.put("datetimev2", new Integer(SqlParserSymbols.KW_DATETIMEV2));
keywordMap.put("time", new Integer(SqlParserSymbols.KW_TIME));
keywordMap.put("day", new Integer(SqlParserSymbols.KW_DAY));