This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 6eb2cb2d485 [date](parser) Support DateV1 keyword (#25414)
6eb2cb2d485 is described below
commit 6eb2cb2d48539f448657af95af29eba463df52cb
Author: Gabriel <[email protected]>
AuthorDate: Mon Oct 30 18:39:22 2023 +0800
[date](parser) Support DateV1 keyword (#25414)
---
be/src/olap/comparison_predicate.h | 4 +-
.../java/org/apache/doris/catalog/ScalarType.java | 12 ++++
.../antlr4/org/apache/doris/nereids/DorisLexer.g4 | 2 +
.../antlr4/org/apache/doris/nereids/DorisParser.g4 | 6 +-
fe/fe-core/src/main/cup/sql_parser.cup | 12 ++++
.../doris/nereids/parser/LogicalPlanBuilder.java | 2 +
fe/fe-core/src/main/jflex/sql_scanner.flex | 2 +
.../data/datatype_p0/date/test_datev1.out | 51 +++++++++++++
.../datatype_p0/date/test_date_in_predicate.groovy | 2 +-
.../suites/datatype_p0/date/test_datev1.groovy | 84 ++++++++++++++++++++++
10 files changed, 174 insertions(+), 3 deletions(-)
diff --git a/be/src/olap/comparison_predicate.h
b/be/src/olap/comparison_predicate.h
index 2fa1d629811..522939370cf 100644
--- a/be/src/olap/comparison_predicate.h
+++ b/be/src/olap/comparison_predicate.h
@@ -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 {};
diff --git
a/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java
b/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java
index 3eb13e5cf3c..9352e6a9daa 100644
--- a/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java
+++ b/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java
@@ -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) {
diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4
b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4
index 99829b34115..27036e14fdb 100644
--- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4
+++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4
@@ -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';
diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
index 7c7fce72ce1..4b043e25f72 100644
--- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
+++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
@@ -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
diff --git a/fe/fe-core/src/main/cup/sql_parser.cup
b/fe/fe-core/src/main/cup/sql_parser.cup
index c3e16e9b4c2..e33d32ddfad 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -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
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index 15979b040c4..a05e24b6944 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -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);
}
diff --git a/fe/fe-core/src/main/jflex/sql_scanner.flex
b/fe/fe-core/src/main/jflex/sql_scanner.flex
index 6d9db3a1e28..e58c76a2354 100644
--- a/fe/fe-core/src/main/jflex/sql_scanner.flex
+++ b/fe/fe-core/src/main/jflex/sql_scanner.flex
@@ -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));
diff --git a/regression-test/data/datatype_p0/date/test_datev1.out
b/regression-test/data/datatype_p0/date/test_datev1.out
new file mode 100644
index 00000000000..8397a4d7e42
--- /dev/null
+++ b/regression-test/data/datatype_p0/date/test_datev1.out
@@ -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
diff --git
a/regression-test/suites/datatype_p0/date/test_date_in_predicate.groovy
b/regression-test/suites/datatype_p0/date/test_date_in_predicate.groovy
index b1010b32389..9376b0fe17c 100644
--- a/regression-test/suites/datatype_p0/date/test_date_in_predicate.groovy
+++ b/regression-test/suites/datatype_p0/date/test_date_in_predicate.groovy
@@ -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)
diff --git a/regression-test/suites/datatype_p0/date/test_datev1.groovy
b/regression-test/suites/datatype_p0/date/test_datev1.groovy
new file mode 100644
index 00000000000..f99c2fb0d07
--- /dev/null
+++ b/regression-test/suites/datatype_p0/date/test_datev1.groovy
@@ -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}"
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]