Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[date](parser) Support DateV1 keyword #25414

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion be/src/olap/comparison_predicate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -735,6 +735,8 @@ primitiveColType:
| type=TIME
| type=DATEV2
| type=DATETIMEV2
| type=DATEV1
| type=DATETIMEV1
| type=BITMAP
| type=QUANTILE_STATE
| type=HLL
Expand Down Expand Up @@ -874,6 +876,8 @@ nonReserved
| DATETIME
| DATETIMEV2
| DATEV2
| DATETIMEV1
| DATEV1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nereids should update LogicalPlanBuilder and other files too.
please add create table and query test for legacy planner and Nereids

| DAY
| DAYS_ADD
| DAYS_SUB
Expand Down
12 changes: 12 additions & 0 deletions fe/fe-core/src/main/cup/sql_parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ terminal String
KW_DATETIME,
KW_DATETIMEV2,
KW_DATEV2,
KW_DATETIMEV1,
KW_DATEV1,
KW_DAY,
KW_DECIMAL,
KW_DECIMALV3,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions fe/fe-core/src/main/jflex/sql_scanner.flex
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
51 changes: 51 additions & 0 deletions regression-test/data/datatype_p0/date/test_datev1.out
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
84 changes: 84 additions & 0 deletions regression-test/suites/datatype_p0/date/test_datev1.groovy
Original file line number Diff line number Diff line change
@@ -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}"
}
Loading