diff --git a/be/src/olap/comparison_predicate.h b/be/src/olap/comparison_predicate.h index 8ec1504dce5dba..1ba8eef32dc9cd 100644 --- a/be/src/olap/comparison_predicate.h +++ b/be/src/olap/comparison_predicate.h @@ -179,7 +179,9 @@ class ComparisonPredicateBase : public ColumnPredicate { 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 7271429b66d684..f15b9fb4e4a18a 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 static ScalarType createDateType() { } } + @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 1b035d96f7c694..267a2777487547 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 4c74e424e60658..81174b9927d0ca 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 @@ -874,6 +876,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 b0d487a6ca32f3..fb7c2e31a608cc 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, @@ -6360,6 +6362,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 @@ -6744,6 +6750,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 @@ -7561,6 +7569,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 0fb047abee3027..cefc2f8c63a898 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 Literal visitTypeConstructor(TypeConstructorContext ctx) { 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 c360d63701de79..7fb8c7706d2509 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 00000000000000..8397a4d7e42d90 --- /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 b1010b323899ed..9376b0fe17c06d 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 00000000000000..f99c2fb0d07f2e --- /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}" +}