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

[fix](Nereids) fix date function rewrite on datetimev1 column bug #32569 #32719

Merged
merged 4 commits into from
Mar 25, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,10 @@ public DateTimeLiteral toBeginOfTheDay() {

/**
* 2020-01-01
* @return 2020-01-01 24:00:00
* @return 2020-01-01 23:59:59
*/
public DateTimeLiteral toEndOfTheDay() {
return new DateTimeLiteral(year, month, day, 24, 0, 0);
return new DateTimeLiteral(year, month, day, 23, 59, 59);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !date_function_test_datetimev1_gt --
2020-01-06T21:02:03
2020-01-07T09:29:39
2020-01-08T11:33:55
2020-01-09T14:43:42
2020-01-10T23:59:59

-- !date_function_test_datetimev1_gte --
2020-01-05T17:58:59
2020-01-06T21:02:03
2020-01-07T09:29:39
2020-01-08T11:33:55
2020-01-09T14:43:42
2020-01-10T23:59:59

-- !date_function_test_datetimev1_lt --
2020-01-01T19:29:39
2020-01-02T18:28:38
2020-01-03T23:37:47
2020-01-04T21:42:43

-- !date_function_test_datetimev1_lte --
2020-01-01T19:29:39
2020-01-02T18:28:38
2020-01-03T23:37:47
2020-01-04T21:42:43
2020-01-05T17:58:59

-- !date_function_test_datetimev1_eq --
2020-01-05T17:58:59

Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// 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_datetimev1_date_function", "nonConcurrent") {

/// legacy date/datetime format need to run in non concurrent mode.
sql """
admin set frontend config("enable_date_conversion" = "false");
"""

def table_dup = "test_datetimev1_date_function_dup_tbl" // duplicate key

sql "drop table if exists ${table_dup};"

sql """
CREATE TABLE IF NOT EXISTS `${table_dup}` (
`date_key1` datetimev1 NULL COMMENT "",
) ENGINE=OLAP
DUPLICATE KEY(`date_key1`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`date_key1`) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"in_memory" = "false",
"storage_format" = "V2"
)
"""

def insert_data = { table_name ->
sql """
insert into ${table_name}
values
('2020-01-01 19:29:39'),
('2020-01-02 18:28:38'),
('2020-01-03 23:37:47'),
('2020-01-04 21:42:43'),
('2020-01-05 17:58:59'),
('2020-01-06 21:02:03'),
('2020-01-07 09:29:39'),
('2020-01-08 11:33:55'),
('2020-01-09 14:43:42'),
('2020-01-10 23:59:59');
"""
}

insert_data(table_dup)

def run_compare_test = { table_name, col, col_value ->
def query1 = """
select
*
from
`${table_name}`
where
date(`${col}`) > ${col_value}
order by 1;
"""
quickTest("date_function_test_datetimev1_gt", query1)

def query2 = """
select
*
from
`${table_name}`
where
date(`${col}`) >= ${col_value}
order by 1;
"""
quickTest("date_function_test_datetimev1_gte", query2)

def query3 = """
select
*
from
`${table_name}`
where
date(`${col}`) < ${col_value}
order by 1;
"""
quickTest("date_function_test_datetimev1_lt", query3)

def query4 = """
select
*
from
`${table_name}`
where
date(`${col}`) <= ${col_value}
order by 1;
"""
quickTest("date_function_test_datetimev1_lte", query4)

def query5 = """
select
*
from
`${table_name}`
where
date(`${col}`) = ${col_value}
order by 1;
"""
quickTest("date_function_test_datetimev1_eq", query5)
}

run_compare_test(table_dup, "date_key1", "'2020-01-05'")

sql """
admin set frontend config("enable_date_conversion" = "true");
"""
}
Loading