Skip to content

Commit

Permalink
[branch-2.1](fix) fix incorrect result of hash join with const column (
Browse files Browse the repository at this point in the history
  • Loading branch information
DarvenDuan authored Dec 19, 2024
1 parent f966088 commit 4b7c2ea
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
6 changes: 5 additions & 1 deletion be/src/vec/runtime/partitioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ Status Partitioner<HashValueType, ChannelIds>::do_partitioning(RuntimeState* sta
RETURN_IF_ERROR(_get_partition_column_result(block, result));
}
for (int j = 0; j < result_size; ++j) {
_do_hash(unpack_if_const(block->get_by_position(result[j]).column).first, hashes, j);
const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
if (is_const) {
continue;
}
_do_hash(col, hashes, j);
}

for (int i = 0; i < rows; i++) {
Expand Down
9 changes: 9 additions & 0 deletions regression-test/data/query_p0/join/test_join_with_const.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql1 --
0 2024-10-31 1 \N \N \N
0 2024-11-01 1 0 2024-11-01 2

-- !sql1 --
0 2024-10-31 1 \N \N \N
0 2024-11-01 1 0 2024-11-01 2

71 changes: 71 additions & 0 deletions regression-test/suites/query_p0/join/test_join_with_const.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

// 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_join_with_const", "query,p0") {
def left_table = "left_table"
def right_table = "right_table"
sql " drop table if exists ${left_table}; ";
sql " drop table if exists ${right_table}; ";
sql """
create table ${left_table} (c1 datev2, c2 bigint sum)
aggregate key (c1)
DISTRIBUTED BY HASH(c1)
BUCKETS 3
properties ("replication_num" = "1");
"""
sql """
create table ${right_table} (c1 datev2, c2 bigint sum)
aggregate key (c1)
DISTRIBUTED BY HASH(c1)
BUCKETS 3
properties ("replication_num" = "1");
"""

sql """ insert into ${left_table} values ("2024-10-31", 1), ("2024-11-01", 1); """
sql """ insert into ${right_table} values ("2024-11-01", 2); """

def join_sql_str = """
select
*
from
(
select 0 z, c1, sum(c2) c2
from ${left_table}
group by 1, 2
) t1
FULL JOIN [shuffle]
(
select 0 z, c1, sum(c2) c2
from ${right_table}
group by 1, 2
) t2
on t1.z = t2.z
and t1.c1 = t2.c1
order by t1.c1
"""

sql "set enable_nereids_planner = false;"
qt_sql1 "${join_sql_str}"

sql "set enable_nereids_planner = true;"
qt_sql1 "${join_sql_str}"

sql "drop table ${left_table}"
sql "drop table ${right_table}"

}

0 comments on commit 4b7c2ea

Please sign in to comment.