diff --git a/be/src/vec/functions/array/function_array_range.cpp b/be/src/vec/functions/array/function_array_range.cpp index 1a5dd08aaac858..888d7adc5f9ddf 100644 --- a/be/src/vec/functions/array/function_array_range.cpp +++ b/be/src/vec/functions/array/function_array_range.cpp @@ -197,8 +197,8 @@ struct RangeImplUtil { continue; } else { if (idx < end_row && step_row > 0 && - ((static_cast<__int128_t>(end_row) - static_cast<__int128_t>(step_row) - - 1) / static_cast<__int128_t>(step_row) + + ((static_cast<__int128_t>(end_row) - static_cast<__int128_t>(idx) - 1) / + static_cast<__int128_t>(step_row) + 1) > max_array_size_as_field) { return Status::InvalidArgument("Array size exceeds the limit {}", max_array_size_as_field); diff --git a/regression-test/data/nereids_function_p0/scalar_function/Array.out b/regression-test/data/nereids_function_p0/scalar_function/Array.out index b2e11fab37e47a..30f42223f3bfb3 100644 --- a/regression-test/data/nereids_function_p0/scalar_function/Array.out +++ b/regression-test/data/nereids_function_p0/scalar_function/Array.out @@ -14445,6 +14445,36 @@ true ["2012-03-11 11:10:11", "2012-03-11 11:10:21"] ["2012-03-12 12:11:12", "2012-03-12 12:11:23"] +-- !sql_sequence_dt_3args -- +\N +["2012-03-01 01:00:01", "2137-03-01 01:00:01", "2262-03-01 01:00:01", "2387-03-01 01:00:01", "2512-03-01 01:00:01", "2637-03-01 01:00:01", "2762-03-01 01:00:01", "2887-03-01 01:00:01", "3012-03-01 01:00:01"] +["2012-03-02 02:01:02", "2137-03-02 02:01:02", "2262-03-02 02:01:02", "2387-03-02 02:01:02", "2512-03-02 02:01:02", "2637-03-02 02:01:02", "2762-03-02 02:01:02", "2887-03-02 02:01:02", "3012-03-02 02:01:02"] +["2012-03-03 03:02:03", "2137-03-03 03:02:03", "2262-03-03 03:02:03", "2387-03-03 03:02:03", "2512-03-03 03:02:03", "2637-03-03 03:02:03", "2762-03-03 03:02:03", "2887-03-03 03:02:03", "3012-03-03 03:02:03"] +["2012-03-04 04:03:04", "2137-03-04 04:03:04", "2262-03-04 04:03:04", "2387-03-04 04:03:04", "2512-03-04 04:03:04", "2637-03-04 04:03:04", "2762-03-04 04:03:04", "2887-03-04 04:03:04", "3012-03-04 04:03:04"] +["2012-03-05 05:04:05", "2137-03-05 05:04:05", "2262-03-05 05:04:05", "2387-03-05 05:04:05", "2512-03-05 05:04:05", "2637-03-05 05:04:05", "2762-03-05 05:04:05", "2887-03-05 05:04:05", "3012-03-05 05:04:05"] +["2012-03-06 06:05:06", "2137-03-06 06:05:06", "2262-03-06 06:05:06", "2387-03-06 06:05:06", "2512-03-06 06:05:06", "2637-03-06 06:05:06", "2762-03-06 06:05:06", "2887-03-06 06:05:06", "3012-03-06 06:05:06"] +["2012-03-07 07:06:07", "2137-03-07 07:06:07", "2262-03-07 07:06:07", "2387-03-07 07:06:07", "2512-03-07 07:06:07", "2637-03-07 07:06:07", "2762-03-07 07:06:07", "2887-03-07 07:06:07", "3012-03-07 07:06:07"] +["2012-03-08 08:07:08", "2137-03-08 08:07:08", "2262-03-08 08:07:08", "2387-03-08 08:07:08", "2512-03-08 08:07:08", "2637-03-08 08:07:08", "2762-03-08 08:07:08", "2887-03-08 08:07:08", "3012-03-08 08:07:08"] +["2012-03-09 09:08:09", "2137-03-09 09:08:09", "2262-03-09 09:08:09", "2387-03-09 09:08:09", "2512-03-09 09:08:09", "2637-03-09 09:08:09", "2762-03-09 09:08:09", "2887-03-09 09:08:09", "3012-03-09 09:08:09"] +["2012-03-10 10:09:10", "2137-03-10 10:09:10", "2262-03-10 10:09:10", "2387-03-10 10:09:10", "2512-03-10 10:09:10", "2637-03-10 10:09:10", "2762-03-10 10:09:10", "2887-03-10 10:09:10", "3012-03-10 10:09:10"] +["2012-03-11 11:10:11", "2137-03-11 11:10:11", "2262-03-11 11:10:11", "2387-03-11 11:10:11", "2512-03-11 11:10:11", "2637-03-11 11:10:11", "2762-03-11 11:10:11", "2887-03-11 11:10:11", "3012-03-11 11:10:11"] +["2012-03-12 12:11:12", "2137-03-12 12:11:12", "2262-03-12 12:11:12", "2387-03-12 12:11:12", "2512-03-12 12:11:12", "2637-03-12 12:11:12", "2762-03-12 12:11:12", "2887-03-12 12:11:12", "3012-03-12 12:11:12"] + +-- !sql_sequence_int_3args -- +\N +[1, 10001, 20001, 30001, 40001, 50001, 60001, 70001, 80001, 90001] +[10, 10010, 20010, 30010, 40010, 50010, 60010, 70010, 80010, 90010] +[11, 10011, 20011, 30011, 40011, 50011, 60011, 70011, 80011, 90011] +[12, 10012, 20012, 30012, 40012, 50012, 60012, 70012, 80012, 90012] +[2, 10002, 20002, 30002, 40002, 50002, 60002, 70002, 80002, 90002] +[3, 10003, 20003, 30003, 40003, 50003, 60003, 70003, 80003, 90003] +[4, 10004, 20004, 30004, 40004, 50004, 60004, 70004, 80004, 90004] +[5, 10005, 20005, 30005, 40005, 50005, 60005, 70005, 80005, 90005] +[6, 10006, 20006, 30006, 40006, 50006, 60006, 70006, 80006, 90006] +[7, 10007, 20007, 30007, 40007, 50007, 60007, 70007, 80007, 90007] +[8, 10008, 20008, 30008, 40008, 50008, 60008, 70008, 80008, 90008] +[9, 10009, 20009, 30009, 40009, 50009, 60009, 70009, 80009, 90009] + -- !array_empty_fe -- [] diff --git a/regression-test/suites/nereids_function_p0/scalar_function/Array.groovy b/regression-test/suites/nereids_function_p0/scalar_function/Array.groovy index d7faedce88778a..ae6193d3737020 100644 --- a/regression-test/suites/nereids_function_p0/scalar_function/Array.groovy +++ b/regression-test/suites/nereids_function_p0/scalar_function/Array.groovy @@ -1281,30 +1281,25 @@ suite("nereids_scalar_fn_Array") { qt_sequence_datetime_hour """select sequence(kdtmv2s1, date_add(kdtmv2s1, interval kint-3 hour), interval kint hour) from fn_test order by kdtmv2s1;""" qt_sequence_datetime_minute """select sequence(kdtmv2s1, date_add(kdtmv2s1, interval kint+1 minute), interval kint minute) from fn_test order by kdtmv2s1;""" qt_sequence_datetime_second """select sequence(kdtmv2s1, date_add(kdtmv2s1, interval kint second), interval kint-1 second) from fn_test order by kdtmv2s1;""" - // make large error size - test { - sql "select array_size(sequence(kdtmv2s1, date_add(kdtmv2s1, interval kint+1000 year), interval kint hour)) from fn_test order by kdtmv2s1;" - check{result, exception, startTime, endTime -> - assertTrue(exception != null) - logger.info(exception.message) - } - } + + // max_array_size_as_field = 1000000; + sql "select count(sequence(kdtmv2s1, date_add(kdtmv2s1, interval kint+1000 year))) from fn_test" + sql "select count(sequence(kdtmv2s1, date_add(kdtmv2s1, interval kint+1000 year), INTERVAL 5 YEAR)) from fn_test" + order_qt_sql_sequence_dt_3args "select sequence(kdtmv2s1, date_add(kdtmv2s1, interval kint+1000 year), INTERVAL 125 YEAR) from fn_test" + sql "select count(sequence(kint, kint+100000)) from fn_test" + sql "select count(sequence(kint, kint+100000, 10000)) from fn_test" + order_qt_sql_sequence_int_3args "select sequence(kint, kint+100000, 10000) from fn_test" test { - sql "select array_size(sequence(kdtmv2s1, date_add(kdtmv2s1, interval kint+10000 month), interval kint hour)) from fn_test order by kdtmv2s1;" - check{result, exception, startTime, endTime -> - assertTrue(exception != null) - logger.info(exception.message) - } + sql "select sequence(kdtmv2s1, date_add(kdtmv2s1, interval 5000 year), interval 1 second) from fn_test" + exception "Array size exceeds the limit 1000000" } - + sql "select sequence(kdtmv2s1, date_add(kdtmv2s1, interval 5000 year), interval 500 year) from fn_test" test { - sql "select array_size(sequence(kdtmv2s1, date_add(kdtmv2s1, interval kint+1000001 day), interval kint day)) from fn_test order by kdtmv2s1;" - check{result, exception, startTime, endTime -> - assertTrue(exception != null) - logger.info(exception.message) - } + sql "select count(sequence(kint, kint+10000000)) from fn_test" + exception "Array size exceeds the limit 1000000" } + sql "select count(sequence(kint, kint+10000000, 50)) from fn_test" // with array empty qt_array_empty_fe """select array()""" diff --git a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy index 96bca3eb4ff3a5..ac12b1ffccb437 100644 --- a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy +++ b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy @@ -421,26 +421,4 @@ suite("test_array_functions") { qt_const_select "select sequence(cast('2022-35-38 12:00:10' as datetimev2(0)), cast('2022-05-18 22:00:30' as datetimev2(0))); " qt_const_select "select sequence(1, 10, 0); " qt_const_select "select sequence(cast('2022-05-15 12:00:00' as datetimev2(0)), cast('2022-05-17 12:00:00' as datetimev2(0)), interval 0 day); " - // test large size of array - test { - sql """ select sequence(cast('2022-05-01 12:00:00' as datetimev2(0)), cast('2022-05-17 12:00:00' as datetimev2(0)), interval 10000000000 week); """ - check{result, exception, startTime, endTime -> - assertTrue(exception != null) - logger.info(exception.message) - } - } - test { - sql """ select sequence(1, 10000000000); """ - check{result, exception, startTime, endTime -> - assertTrue(exception != null) - logger.info(exception.message) - } - } - test { - sql """ select sequence(1, 10000000000, 2); """ - check{result, exception, startTime, endTime -> - assertTrue(exception != null) - logger.info(exception.message) - } - } }