[date](parser) Support DateV1 keyword (#25414)
This commit is contained in:
@ -179,7 +179,9 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
DCHECK_LE(sizeof(T), statistic.first->size());
|
||||
DCHECK(sizeof(T) <= statistic.first->size() || Type == TYPE_DATE)
|
||||
<< " Type: " << Type << " sizeof(T): " << sizeof(T)
|
||||
<< " statistic.first->size(): " << statistic.first->size();
|
||||
|
||||
T tmp_min_value {};
|
||||
T tmp_max_value {};
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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));
|
||||
|
||||
51
regression-test/data/datatype_p0/date/test_datev1.out
Normal file
51
regression-test/data/datatype_p0/date/test_datev1.out
Normal file
@ -0,0 +1,51 @@
|
||||
-- This file is automatically generated. You should know what you did if you want to edit this
|
||||
-- !sql1 --
|
||||
2016-11-04
|
||||
|
||||
-- !sql2 --
|
||||
2016-11-04
|
||||
|
||||
-- !sql1 --
|
||||
1 2000-01-01 2000-01-01T11:11:11
|
||||
2 2000-02-02 2000-02-02T11:11:11
|
||||
3 2000-03-02 2000-03-02T11:11:11
|
||||
|
||||
-- !sql2 --
|
||||
1 2000-01-01 2000-01-01T11:11:11 1 2000-01-01 2000-01-01T11:11:11
|
||||
2 2000-02-02 2000-02-02T11:11:11 2 2000-02-02 2000-02-02T11:11:11
|
||||
3 2000-03-02 2000-03-02T11:11:11 3 2000-03-02 2000-03-02T11:11:11
|
||||
|
||||
-- !sql2 --
|
||||
1 2000-01-01 2000-01-01T11:11:11 1 2000-01-01 2000-01-01T11:11:11
|
||||
2 2000-02-02 2000-02-02T11:11:11 2 2000-02-02 2000-02-02T11:11:11
|
||||
3 2000-03-02 2000-03-02T11:11:11 3 2000-03-02 2000-03-02T11:11:11
|
||||
|
||||
-- !sql2 --
|
||||
1 2000-01-01 2000-01-01T11:11:11 1 2000-01-01 2000-01-01T11:11:11
|
||||
2 2000-02-02 2000-02-02T11:11:11 2 2000-02-02 2000-02-02T11:11:11
|
||||
3 2000-03-02 2000-03-02T11:11:11 3 2000-03-02 2000-03-02T11:11:11
|
||||
|
||||
-- !sql2 --
|
||||
1 2000-01-01 2000-01-01T11:11:11 1 2000-01-01 2000-01-01T11:11:11
|
||||
2 2000-02-02 2000-02-02T11:11:11 2 2000-02-02 2000-02-02T11:11:11
|
||||
3 2000-03-02 2000-03-02T11:11:11 3 2000-03-02 2000-03-02T11:11:11
|
||||
|
||||
-- !sql2 --
|
||||
1 2000-01-01 2000-01-01T11:11:11 1 2000-01-01 2000-01-01T11:11:11
|
||||
2 2000-02-02 2000-02-02T11:11:11 2 2000-02-02 2000-02-02T11:11:11
|
||||
3 2000-03-02 2000-03-02T11:11:11 3 2000-03-02 2000-03-02T11:11:11
|
||||
|
||||
-- !sql2 --
|
||||
1 2000-01-01 2000-01-01T11:11:11 1 2000-01-01 2000-01-01T11:11:11
|
||||
2 2000-02-02 2000-02-02T11:11:11 2 2000-02-02 2000-02-02T11:11:11
|
||||
3 2000-03-02 2000-03-02T11:11:11 3 2000-03-02 2000-03-02T11:11:11
|
||||
|
||||
-- !sql2 --
|
||||
1 2000-01-01 2000-01-01T11:11:11 1 2000-01-01 2000-01-01T11:11:11
|
||||
2 2000-02-02 2000-02-02T11:11:11 2 2000-02-02 2000-02-02T11:11:11
|
||||
3 2000-03-02 2000-03-02T11:11:11 3 2000-03-02 2000-03-02T11:11:11
|
||||
|
||||
-- !sql2 --
|
||||
1 2000-01-01 2000-01-01T11:11:11 1 2000-01-01 2000-01-01T11:11:11
|
||||
2 2000-02-02 2000-02-02T11:11:11 2 2000-02-02 2000-02-02T11:11:11
|
||||
3 2000-03-02 2000-03-02T11:11:11 3 2000-03-02 2000-03-02T11:11:11
|
||||
@ -23,7 +23,7 @@ suite("test_date_in_predicate") {
|
||||
CREATE TABLE IF NOT EXISTS ${tbName} (
|
||||
c0 int,
|
||||
c1 char(10),
|
||||
c2 date,
|
||||
c2 datev1,
|
||||
c3 datev2
|
||||
)
|
||||
UNIQUE KEY(c0)
|
||||
|
||||
84
regression-test/suites/datatype_p0/date/test_datev1.groovy
Normal file
84
regression-test/suites/datatype_p0/date/test_datev1.groovy
Normal file
@ -0,0 +1,84 @@
|
||||
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
suite("test_datev1") {
|
||||
def tbName = "test_datev1_exprs"
|
||||
sql "DROP TABLE IF EXISTS ${tbName}"
|
||||
sql """
|
||||
create table ${tbName}(k1 datetimev1, k2 int) distributed by hash(k1) buckets 1 properties("replication_num" = "1");
|
||||
"""
|
||||
sql """ insert into ${tbName} values("2016-11-04 00:00:01", 1); """
|
||||
|
||||
qt_sql1 """ select dt
|
||||
from
|
||||
(
|
||||
select cast(k1 as datev1) as dt
|
||||
from ${tbName}
|
||||
) r; """
|
||||
qt_sql2 """ select dt
|
||||
from
|
||||
(
|
||||
select cast(k1 as date) as dt
|
||||
from ${tbName}
|
||||
) r; """
|
||||
sql "DROP TABLE ${tbName}"
|
||||
|
||||
tbName = "test_datev1_runtime_filter"
|
||||
sql "DROP TABLE IF EXISTS ${tbName}"
|
||||
sql """
|
||||
CREATE TABLE IF NOT EXISTS ${tbName} (
|
||||
c0 int,
|
||||
c2 datev1,
|
||||
c3 datetimev1
|
||||
)
|
||||
DISTRIBUTED BY HASH(c0) BUCKETS 5 properties("replication_num" = "1");
|
||||
"""
|
||||
sql "insert into ${tbName} values(1, '2000-01-01', '2000-01-01 11:11:11')"
|
||||
sql "insert into ${tbName} values(2, '2000-02-02', '2000-02-02 11:11:11')"
|
||||
sql "insert into ${tbName} values(3, '2000-03-02', '2000-03-02 11:11:11')"
|
||||
|
||||
qt_sql1 "select * from ${tbName} ORDER BY c2"
|
||||
|
||||
sql " set runtime_filter_type = 1; "
|
||||
qt_sql2 "select * from ${tbName} a, ${tbName} b WHERE a.c3 = b.c3 ORDER BY a.c2"
|
||||
|
||||
sql " set runtime_filter_type = 2; "
|
||||
qt_sql2 "select * from ${tbName} a, ${tbName} b WHERE a.c3 = b.c3 ORDER BY a.c2"
|
||||
|
||||
sql " set runtime_filter_type = 4; "
|
||||
qt_sql2 "select * from ${tbName} a, ${tbName} b WHERE a.c3 = b.c3 ORDER BY a.c2"
|
||||
|
||||
sql " set runtime_filter_type = 8; "
|
||||
qt_sql2 "select * from ${tbName} a, ${tbName} b WHERE a.c3 = b.c3 ORDER BY a.c2"
|
||||
|
||||
sql " set runtime_filter_wait_time_ms = 0; "
|
||||
|
||||
sql " set runtime_filter_type = 1; "
|
||||
qt_sql2 "select * from ${tbName} a, ${tbName} b WHERE a.c3 = b.c3 ORDER BY a.c2"
|
||||
|
||||
sql " set runtime_filter_type = 2; "
|
||||
qt_sql2 "select * from ${tbName} a, ${tbName} b WHERE a.c3 = b.c3 ORDER BY a.c2"
|
||||
|
||||
sql " set runtime_filter_type = 4; "
|
||||
qt_sql2 "select * from ${tbName} a, ${tbName} b WHERE a.c3 = b.c3 ORDER BY a.c2"
|
||||
|
||||
sql " set runtime_filter_type = 8; "
|
||||
qt_sql2 "select * from ${tbName} a, ${tbName} b WHERE a.c3 = b.c3 ORDER BY a.c2"
|
||||
|
||||
sql "DROP TABLE ${tbName}"
|
||||
}
|
||||
Reference in New Issue
Block a user