From cf1f1a38c96058b25a047a3e9b5a3e24caadb946 Mon Sep 17 00:00:00 2001 From: zhaochangle Date: Wed, 25 Dec 2024 16:45:18 +0800 Subject: [PATCH] fix --- .../function_date_or_datetime_computation.h | 4 +- .../query_p0/sql_functions/test_years_add.out | 163 +++++++++++++++ .../test_quarters_add.groovy | 67 ++++++- .../sql_functions/test_years_add.groovy | 185 ++++++++++++++++++ 4 files changed, 417 insertions(+), 2 deletions(-) create mode 100644 regression-test/data/query_p0/sql_functions/test_years_add.out create mode 100644 regression-test/suites/query_p0/sql_functions/test_years_add.groovy diff --git a/be/src/vec/functions/function_date_or_datetime_computation.h b/be/src/vec/functions/function_date_or_datetime_computation.h index 1b2827c19b74bfd..df7dc20a312ea37 100644 --- a/be/src/vec/functions/function_date_or_datetime_computation.h +++ b/be/src/vec/functions/function_date_or_datetime_computation.h @@ -142,7 +142,9 @@ struct AddQuartersImpl { return date_time_add(t, 3 * delta, is_null); } - static DataTypes get_variadic_argument_types() { return {std::make_shared()}; } + static DataTypes get_variadic_argument_types() { + return {std::make_shared(), std::make_shared()}; + } }; template diff --git a/regression-test/data/query_p0/sql_functions/test_years_add.out b/regression-test/data/query_p0/sql_functions/test_years_add.out new file mode 100644 index 000000000000000..a12a4598656092a --- /dev/null +++ b/regression-test/data/query_p0/sql_functions/test_years_add.out @@ -0,0 +1,163 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !empty_nullable -- + +-- !empty_not_nullable -- + +-- !empty_partial_nullable -- + +-- !nullable -- +\N +\N +\N +\N +\N +\N +\N +\N +\N +1999-12-31T23:59:59 +2000-12-31T23:59:59 +2001-12-31T23:59:59 +2004-12-31T23:59:59 +2019-01-01T00:00 +2019-02-28T00:00 +2020-01-01T00:00 +2020-02-29T00:00 +2021-01-01T00:00 +2021-02-28T00:00 +2022-06-15T12:30:45 +2023-06-15T12:30:45 +2024-01-01T00:00 +2024-02-29T00:00 +2024-06-15T12:30:45 +2027-06-15T12:30:45 + +-- !not_nullable -- +1998-12-31T00:00 +1999-12-31T00:00 +1999-12-31T23:59:59 +2000-12-31T00:00 +2000-12-31T23:59:59 +2001-12-31T23:59:59 +2003-12-31T00:00 +2004-12-31T23:59:59 +2019-01-01T00:00 +2019-02-28T00:00 +2020-01-01T00:00 +2020-02-29T00:00 +2021-01-01T00:00 +2021-02-28T00:00 +2022-06-15T12:30:45 +2023-06-15T12:30:45 +2024-01-01T00:00 +2024-02-29T00:00 +2024-06-15T12:30:45 +2027-06-15T12:30:45 +2099-12-31T00:00 +2100-12-31T23:59:59 +2120-01-01T00:00 +2120-02-29T00:00 +2123-06-15T12:30:45 + +-- !partial_nullable -- +\N +\N +\N +\N +\N +1998-12-31T00:00 +1999-12-31T00:00 +1999-12-31T23:59:59 +2000-12-31T00:00 +2000-12-31T23:59:59 +2001-12-31T23:59:59 +2003-12-31T00:00 +2004-12-31T23:59:59 +2019-01-01T00:00 +2019-02-28T00:00 +2020-01-01T00:00 +2020-02-29T00:00 +2021-01-01T00:00 +2021-02-28T00:00 +2022-06-15T12:30:45 +2023-06-15T12:30:45 +2024-01-01T00:00 +2024-02-29T00:00 +2024-06-15T12:30:45 +2027-06-15T12:30:45 + +-- !nullable_no_null -- +1998-12-31T00:00 +1999-12-31T00:00 +1999-12-31T23:59:59 +2000-12-31T00:00 +2000-12-31T23:59:59 +2001-12-31T23:59:59 +2003-12-31T00:00 +2004-12-31T23:59:59 +2019-01-01T00:00 +2019-02-28T00:00 +2020-01-01T00:00 +2020-02-29T00:00 +2021-01-01T00:00 +2021-02-28T00:00 +2022-06-15T12:30:45 +2023-06-15T12:30:45 +2024-01-01T00:00 +2024-02-29T00:00 +2024-06-15T12:30:45 +2027-06-15T12:30:45 +2099-12-31T00:00 +2100-12-31T23:59:59 +2120-01-01T00:00 +2120-02-29T00:00 +2123-06-15T12:30:45 + +-- !const_nullable -- +\N +\N +\N +\N +\N + +-- !partial_const_nullable -- +\N +\N +\N +\N +\N + +-- !const_not_nullable -- +2021-01-01T00:00 +2021-01-01T00:00 +2021-01-01T00:00 +2021-01-01T00:00 +2021-01-01T00:00 + +-- !const_other_nullable -- +\N +2019-01-01T00:00 +2020-01-01T00:00 +2021-01-01T00:00 +2024-01-01T00:00 + +-- !const_other_not_nullable -- +2000-12-31T00:00 +2001-12-31T23:59:59 +2021-01-01T00:00 +2021-02-28T00:00 +2024-06-15T12:30:45 + +-- !const_nullable_no_null -- +2021-01-01T00:00 + +-- !const_nullable_no_null_multirows -- +2021-01-01T00:00 +2021-01-01T00:00 +2021-01-01T00:00 +2021-01-01T00:00 +2021-01-01T00:00 + +-- !const_partial_nullable_no_null -- +2021-01-01T00:00 + diff --git a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_quarters_add.groovy b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_quarters_add.groovy index 4fb999a7032b978..915d2eabcb420ad 100644 --- a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_quarters_add.groovy +++ b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_quarters_add.groovy @@ -150,5 +150,70 @@ suite("test_quarters_add") { /// special grammar qt_datediff1 "select date_sub('2020-12-12', interval 1 quarter)" qt_datediff2 "select date_add('2020-12-12', interval 1 quarter)" - //TODO: after #45265 merged add some exception test. + + // Exception test cases for boundary conditions on BE + sql "set debug_skip_fold_constant=true;" + test { + sql """select quarters_add('9999-12-31', 1) from hits_two_args_quar_add;""" + check { result, exception, startTime, endTime -> + assertTrue(exception != null) + } + } + + test { + sql """select quarters_add('0000-01-01', -1) from hits_two_args_quar_add;""" + check { result, exception, startTime, endTime -> + assertTrue(exception != null) + } + } + + test { + sql """select quarters_add('2023-01-01', 40000) from hits_two_args_quar_add;""" + check { result, exception, startTime, endTime -> + assertTrue(exception != null) + } + } + + test { + sql """select quarters_add('2023-01-01', -40000) from hits_two_args_quar_add;""" + check { result, exception, startTime, endTime -> + assertTrue(exception != null) + } + } + + // Exception test cases for nullable scenarios + test { + sql """select quarters_add(nullable('9999-12-31'), 1) from hits_two_args_quar_add;""" + check { result, exception, startTime, endTime -> + assertTrue(exception != null) + } + } + + test { + sql """select quarters_add('9999-12-31', nullable(1)) from hits_two_args_quar_add;""" + check { result, exception, startTime, endTime -> + assertTrue(exception != null) + } + } + + test { + sql """select quarters_add(nullable('0000-01-01'), nullable(-1)) from hits_two_args_quar_add;""" + check { result, exception, startTime, endTime -> + assertTrue(exception != null) + } + } + + test { + sql """select quarters_add(nullable('2023-01-01'), nullable(40000)) from hits_two_args_quar_add;""" + check { result, exception, startTime, endTime -> + assertTrue(exception != null) + } + } + + test { + sql """select quarters_add(nullable('2023-01-01'), nullable(-40000)) from hits_two_args_quar_add;""" + check { result, exception, startTime, endTime -> + assertTrue(exception != null) + } + } } \ No newline at end of file diff --git a/regression-test/suites/query_p0/sql_functions/test_years_add.groovy b/regression-test/suites/query_p0/sql_functions/test_years_add.groovy new file mode 100644 index 000000000000000..99e9652266675d1 --- /dev/null +++ b/regression-test/suites/query_p0/sql_functions/test_years_add.groovy @@ -0,0 +1,185 @@ +// 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_years_add") { + // this table has nothing todo. just make it easier to generate query + sql "drop table if exists hits_years_add" + sql """ + create table hits_years_add( + nothing boolean + ) + properties("replication_num" = "1"); + """ + sql "insert into hits_years_add values(true);" + + sql "drop table if exists dates_tbl" + sql """ + create table dates_tbl ( + k0 int, + dt_val datetime not null, + dt_null datetime null + ) + DISTRIBUTED BY HASH(k0) + PROPERTIES + ( + "replication_num" = "1" + ); + """ + + sql "drop table if exists years_tbl" + sql """ + create table years_tbl ( + k0 int, + years_val int not null, + years_null int null + ) + DISTRIBUTED BY HASH(k0) + PROPERTIES + ( + "replication_num" = "1" + ); + """ + + // Empty table tests + order_qt_empty_nullable "select years_add(dt_null, years_val) from dates_tbl, years_tbl" + order_qt_empty_not_nullable "select years_add(dt_val, years_val) from dates_tbl, years_tbl" + order_qt_empty_partial_nullable "select years_add(dt_val, years_null) from dates_tbl, years_tbl" + + // Insert test data + sql """ + insert into dates_tbl values + (1, '2020-01-01 00:00:00', '2020-01-01 00:00:00'), -- regular date + (2, '2020-02-29 00:00:00', '2020-02-29 00:00:00'), -- leap year date + (3, '2000-12-31 23:59:59', '2000-12-31 23:59:59'), -- century leap year + (4, '2023-06-15 12:30:45', '2023-06-15 12:30:45'), -- date with time + (5, '1999-12-31 00:00:00', null) -- null value + """ + + sql """ + insert into years_tbl values + (1, 0, 0), -- no change + (2, 1, 1), -- add one year + (3, -1, -1), -- subtract one year + (4, 4, 4), -- leap year cycle + (5, 100, null) -- null value + """ + + // All values cross join test + order_qt_nullable """ + SELECT years_add(t.dt, t.years) as result + FROM ( + SELECT hits_years_add.nothing, TABLE1.dt, TABLE1.order1, TABLE2.years, TABLE2.order2 + FROM hits_years_add + CROSS JOIN ( + SELECT dt_null as dt, k0 as order1 + FROM dates_tbl + ) as TABLE1 + CROSS JOIN ( + SELECT years_null as years, k0 as order2 + FROM years_tbl + ) as TABLE2 + )t; + """ + + // Nullable tests + order_qt_not_nullable "select years_add(dt_val, years_val) from dates_tbl, years_tbl" + order_qt_partial_nullable "select years_add(dt_val, years_null) from dates_tbl, years_tbl" + order_qt_nullable_no_null "select years_add(dt_val, nullable(years_val)) from dates_tbl, years_tbl" + + // Constant tests + order_qt_const_nullable "select years_add(NULL, NULL) from dates_tbl" + order_qt_partial_const_nullable "select years_add(NULL, years_val) from years_tbl" + order_qt_const_not_nullable "select years_add('2020-01-01 00:00:00', 1) from dates_tbl" + order_qt_const_other_nullable "select years_add('2020-01-01 00:00:00', years_null) from years_tbl" + order_qt_const_other_not_nullable "select years_add(dt_val, 1) from dates_tbl" + order_qt_const_nullable_no_null "select years_add(nullable('2020-01-01 00:00:00'), nullable(1))" + order_qt_const_nullable_no_null_multirows "select years_add(nullable('2020-01-01 00:00:00'), nullable(1)) from dates_tbl" + order_qt_const_partial_nullable_no_null "select years_add('2020-01-01 00:00:00', nullable(1))" + + // Constant folding tests + check_fold_consistency "years_add('2020-01-01 00:00:00', 1)" + check_fold_consistency "years_add('2020-02-29 00:00:00', 1)" // leap year to non-leap year + check_fold_consistency "years_add('2000-12-31 23:59:59', 100)" + check_fold_consistency "years_add('1999-12-31 00:00:00', -10)" + check_fold_consistency "years_add('2023-06-15 12:30:45', 0)" + + // Exception test cases for boundary conditions on BE + sql "set debug_skip_fold_constant=true;" + test { + sql """select years_add('9999-12-31', 1) from hits_years_add;""" + check { result, exception, startTime, endTime -> + assertTrue(exception != null) + } + } + + test { + sql """select years_add('0000-01-01', -1) from hits_years_add;""" + check { result, exception, startTime, endTime -> + assertTrue(exception != null) + } + } + + test { + sql """select years_add('2023-01-01', 10000) from hits_years_add;""" + check { result, exception, startTime, endTime -> + assertTrue(exception != null) + } + } + + test { + sql """select years_add('2023-01-01', -10000) from hits_years_add;""" + check { result, exception, startTime, endTime -> + assertTrue(exception != null) + } + } + + // Exception test cases for nullable scenarios + test { + sql """select years_add(nullable('9999-12-31'), 1) from hits_years_add;""" + check { result, exception, startTime, endTime -> + assertTrue(exception != null) + } + } + + test { + sql """select years_add('9999-12-31', nullable(1)) from hits_years_add;""" + check { result, exception, startTime, endTime -> + assertTrue(exception != null) + } + } + + test { + sql """select years_add(nullable('0000-01-01'), nullable(-1)) from hits_years_add;""" + check { result, exception, startTime, endTime -> + assertTrue(exception != null) + } + } + + test { + sql """select years_add(nullable('2023-01-01'), nullable(10000)) from hits_years_add;""" + check { result, exception, startTime, endTime -> + assertTrue(exception != null) + } + } + + test { + sql """select years_add(nullable('2023-01-01'), nullable(-10000)) from hits_years_add;""" + check { result, exception, startTime, endTime -> + assertTrue(exception != null) + } + } +}