This is an automated email from the ASF dual-hosted git repository.
kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new ee16dcfe8e9 [fix](grouping sets) fix grouping sets have multiple empty
sets (#32317) (#32407)
ee16dcfe8e9 is described below
commit ee16dcfe8e991347ef66753a826eac3569cef947
Author: Mryange <[email protected]>
AuthorDate: Tue Mar 19 19:20:15 2024 +0800
[fix](grouping sets) fix grouping sets have multiple empty sets (#32317)
(#32407)
---
be/src/vec/exec/vrepeat_node.cpp | 29 ++++++---
be/src/vec/exec/vrepeat_node.h | 3 +
.../correctness_p0/test_grouping_sets_empty.out | 39 ++++++++++++
.../correctness_p0/test_grouping_sets_empty.groovy | 69 ++++++++++++++++++++++
4 files changed, 132 insertions(+), 8 deletions(-)
diff --git a/be/src/vec/exec/vrepeat_node.cpp b/be/src/vec/exec/vrepeat_node.cpp
index 58c993c8b32..750f2c39013 100644
--- a/be/src/vec/exec/vrepeat_node.cpp
+++ b/be/src/vec/exec/vrepeat_node.cpp
@@ -148,8 +148,16 @@ Status VRepeatNode::get_repeated_block(Block* child_block,
int repeat_id_idx, Bl
}
cur_col++;
}
-
+ auto rows = _child_block.rows();
// Fill grouping ID to block
+ RETURN_IF_ERROR(add_grouping_id_column(rows, cur_col, columns,
repeat_id_idx));
+ DCHECK_EQ(cur_col, column_size);
+ output_block->set_columns(std::move(columns));
+ return Status::OK();
+}
+
+Status VRepeatNode::add_grouping_id_column(std::size_t rows, std::size_t&
cur_col,
+ vectorized::MutableColumns&
columns, int repeat_id_idx) {
for (auto slot_idx = 0; slot_idx < _grouping_list.size(); slot_idx++) {
DCHECK_LT(slot_idx, _output_tuple_desc->slots().size());
const SlotDescriptor* _virtual_slot_desc =
_output_tuple_desc->slots()[cur_col];
@@ -158,16 +166,11 @@ Status VRepeatNode::get_repeated_block(Block*
child_block, int repeat_id_idx, Bl
int64_t val = _grouping_list[slot_idx][repeat_id_idx];
auto* column_ptr = columns[cur_col].get();
DCHECK(!_output_slots[cur_col]->is_nullable());
-
auto* col = assert_cast<ColumnVector<Int64>*>(column_ptr);
- for (size_t i = 0; i < child_block->rows(); ++i) {
- col->insert_value(val);
- }
+ col->insert_raw_integers(val, rows);
cur_col++;
}
- DCHECK_EQ(cur_col, column_size);
-
return Status::OK();
}
@@ -191,6 +194,17 @@ Status VRepeatNode::pull(doris::RuntimeState* state,
vectorized::Block* output_b
release_block_memory(_child_block);
_repeat_id_idx = 0;
}
+ } else if (_expr_ctxs.empty()) {
+ auto m_block =
vectorized::VectorizedUtils::build_mutable_mem_reuse_block(output_block,
+
_output_slots);
+ auto rows = _child_block.rows();
+ auto& columns = m_block.mutable_columns();
+
+ for (int repeat_id_idx = 0; repeat_id_idx < _repeat_id_list.size();
repeat_id_idx++) {
+ std::size_t cur_col = 0;
+ RETURN_IF_ERROR(add_grouping_id_column(rows, cur_col, columns,
repeat_id_idx));
+ }
+ release_block_memory(_child_block);
}
RETURN_IF_ERROR(VExprContext::filter_block(_conjuncts, output_block,
output_block->columns()));
*eos = _child_eos && _child_block.rows() == 0;
@@ -202,7 +216,6 @@ Status VRepeatNode::pull(doris::RuntimeState* state,
vectorized::Block* output_b
Status VRepeatNode::push(RuntimeState* state, vectorized::Block* input_block,
bool eos) {
_child_eos = eos;
DCHECK(!_intermediate_block || _intermediate_block->rows() == 0);
- DCHECK(!_expr_ctxs.empty());
if (input_block->rows() > 0) {
_intermediate_block = Block::create_unique();
diff --git a/be/src/vec/exec/vrepeat_node.h b/be/src/vec/exec/vrepeat_node.h
index 837b4c8aca1..32ac9aaa667 100644
--- a/be/src/vec/exec/vrepeat_node.h
+++ b/be/src/vec/exec/vrepeat_node.h
@@ -64,6 +64,9 @@ public:
private:
Status get_repeated_block(Block* child_block, int repeat_id_idx, Block*
output_block);
+ Status add_grouping_id_column(std::size_t rows, std::size_t& cur_col,
+ vectorized::MutableColumns& columns, int
repeat_id_idx);
+
// Slot id set used to indicate those slots need to set to null.
std::vector<std::set<SlotId>> _slot_id_set_list;
// all slot id
diff --git a/regression-test/data/correctness_p0/test_grouping_sets_empty.out
b/regression-test/data/correctness_p0/test_grouping_sets_empty.out
new file mode 100644
index 00000000000..fde7e6420da
--- /dev/null
+++ b/regression-test/data/correctness_p0/test_grouping_sets_empty.out
@@ -0,0 +1,39 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !select1 --
+3
+
+-- !select2 --
+3
+
+-- !select3 --
+3
+3
+3
+
+-- !select4 --
+\N
+\N
+\N
+1
+2
+3
+
+-- !select5 --
+3
+
+-- !select6 --
+3
+
+-- !select7 --
+3
+3
+3
+
+-- !select8 --
+\N
+\N
+\N
+1
+2
+3
+
diff --git
a/regression-test/suites/correctness_p0/test_grouping_sets_empty.groovy
b/regression-test/suites/correctness_p0/test_grouping_sets_empty.groovy
new file mode 100644
index 00000000000..b0bd6b19039
--- /dev/null
+++ b/regression-test/suites/correctness_p0/test_grouping_sets_empty.groovy
@@ -0,0 +1,69 @@
+// 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_grouping_sets_empty") {
+
+ sql"""
+ drop table if exists test_grouping_sets_empty;
+ """
+
+ sql"""
+ create table test_grouping_sets_empty (a int) distributed by hash(a)
buckets 1 properties ( 'replication_num' = '1');
+ """
+
+ sql """
+ insert into test_grouping_sets_empty values (1),(2),(3);
+ """
+
+ qt_select1 """
+ select count(a) from test_grouping_sets_empty group by grouping sets
(());
+ """
+
+
+ qt_select2 """
+ select count(*) from test_grouping_sets_empty group by grouping sets
(());
+ """
+
+ qt_select3 """
+ select count(*) from test_grouping_sets_empty group by grouping sets
((),(),());
+ """
+
+ qt_select4 """
+ select a from test_grouping_sets_empty group by grouping sets
((),(),(),(a)) order by a;
+ """
+
+
+ qt_select5 """
+ select count(a) from test_grouping_sets_empty group by grouping sets
(());
+ """
+
+
+ qt_select6 """
+ select count(*) from test_grouping_sets_empty group by grouping sets
(());
+ """
+
+ qt_select7 """
+ select count(*) from test_grouping_sets_empty group by grouping sets
((),(),());
+ """
+
+ qt_select8 """
+ select a from test_grouping_sets_empty group by grouping sets
((),(),(),(a)) order by a;
+ """
+
+
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]