diff --git a/be/src/vec/exprs/table_function/vexplode_numbers.cpp b/be/src/vec/exprs/table_function/vexplode_numbers.cpp index 8149d4d958..c2f8d36c22 100644 --- a/be/src/vec/exprs/table_function/vexplode_numbers.cpp +++ b/be/src/vec/exprs/table_function/vexplode_numbers.cpp @@ -63,6 +63,8 @@ Status VExplodeNumbersTableFunction::process_init(Block* block, RuntimeState* st _cur_size = column_nested->get_int(0); } ((ColumnInt32*)_elements_column.get())->clear(); + //_cur_size may be a negative number + _cur_size = std::max(0L, _cur_size); if (_cur_size && _cur_size <= state->batch_size()) { // avoid elements_column too big or empty _is_const = true; // use const optimize diff --git a/regression-test/data/correctness/test_explode_numbers.out b/regression-test/data/correctness/test_explode_numbers.out new file mode 100644 index 0000000000..b302a51a92 --- /dev/null +++ b/regression-test/data/correctness/test_explode_numbers.out @@ -0,0 +1,13 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select1 -- +0 +1 +2 +3 +4 + +-- !select2 -- + +-- !select3 -- + +-- !select4 -- diff --git a/regression-test/suites/correctness/test_explode_numbers.groovy b/regression-test/suites/correctness/test_explode_numbers.groovy new file mode 100644 index 0000000000..cd85ba835e --- /dev/null +++ b/regression-test/suites/correctness/test_explode_numbers.groovy @@ -0,0 +1,32 @@ +// 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_explode_numbers") { + sql 'set enable_nereids_planner=true' + qt_select1 """ + select e1 from (select 1 k1) as t lateral view explode_numbers(5) tmp1 as e1 order by e1; + """ + qt_select2 """ + select e1 from (select 1 k1) as t lateral view explode_numbers(0) tmp1 as e1; + """ + qt_select3 """ + select e1 from (select 1 k1) as t lateral view explode_numbers(null) tmp1 as e1; + """ + qt_select4 """ + select e1 from (select 1 k1) as t lateral view explode_numbers(-5) tmp1 as e1; + """ +} \ No newline at end of file