Coverage Report

Created: 2026-03-18 20:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exec/partitioner/partitioner.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "exec/partitioner/partitioner.h"
19
20
#include "common/cast_set.h"
21
#include "common/status.h"
22
#include "core/column/column_const.h"
23
#include "exec/exchange/local_exchange_sink_operator.h"
24
#include "exec/exchange/vdata_stream_sender.h"
25
#include "runtime/thread_context.h"
26
27
namespace doris {
28
#include "common/compile_check_begin.h"
29
30
template <typename ChannelIds>
31
335k
Status Crc32HashPartitioner<ChannelIds>::do_partitioning(RuntimeState* state, Block* block) const {
32
335k
    size_t rows = block->rows();
33
34
335k
    if (rows > 0) {
35
61.1k
        auto column_to_keep = block->columns();
36
37
61.1k
        int result_size = cast_set<int>(_partition_expr_ctxs.size());
38
61.1k
        std::vector<int> result(result_size);
39
40
61.1k
        _initialize_hash_vals(rows);
41
61.1k
        auto* __restrict hashes = _hash_vals.data();
42
61.1k
        RETURN_IF_ERROR(_get_partition_column_result(block, result));
43
154k
        for (int j = 0; j < result_size; ++j) {
44
93.2k
            const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
45
93.2k
            if (is_const) {
46
3
                continue;
47
3
            }
48
93.2k
            _do_hash(col, hashes, j);
49
93.2k
        }
50
51
39.4M
        for (size_t i = 0; i < rows; i++) {
52
39.4M
            hashes[i] = ChannelIds()(hashes[i], _partition_count);
53
39.4M
        }
54
55
61.1k
        Block::erase_useless_column(block, column_to_keep);
56
61.1k
    }
57
335k
    return Status::OK();
58
335k
}
_ZNK5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEE15do_partitioningEPNS_12RuntimeStateEPNS_5BlockE
Line
Count
Source
31
20.4k
Status Crc32HashPartitioner<ChannelIds>::do_partitioning(RuntimeState* state, Block* block) const {
32
20.4k
    size_t rows = block->rows();
33
34
20.4k
    if (rows > 0) {
35
6.20k
        auto column_to_keep = block->columns();
36
37
6.20k
        int result_size = cast_set<int>(_partition_expr_ctxs.size());
38
6.20k
        std::vector<int> result(result_size);
39
40
6.20k
        _initialize_hash_vals(rows);
41
6.20k
        auto* __restrict hashes = _hash_vals.data();
42
6.20k
        RETURN_IF_ERROR(_get_partition_column_result(block, result));
43
13.2k
        for (int j = 0; j < result_size; ++j) {
44
7.07k
            const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
45
7.07k
            if (is_const) {
46
0
                continue;
47
0
            }
48
7.07k
            _do_hash(col, hashes, j);
49
7.07k
        }
50
51
4.66M
        for (size_t i = 0; i < rows; i++) {
52
4.65M
            hashes[i] = ChannelIds()(hashes[i], _partition_count);
53
4.65M
        }
54
55
6.20k
        Block::erase_useless_column(block, column_to_keep);
56
6.20k
    }
57
20.4k
    return Status::OK();
58
20.4k
}
_ZNK5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEE15do_partitioningEPNS_12RuntimeStateEPNS_5BlockE
Line
Count
Source
31
8
Status Crc32HashPartitioner<ChannelIds>::do_partitioning(RuntimeState* state, Block* block) const {
32
8
    size_t rows = block->rows();
33
34
8
    if (rows > 0) {
35
8
        auto column_to_keep = block->columns();
36
37
8
        int result_size = cast_set<int>(_partition_expr_ctxs.size());
38
8
        std::vector<int> result(result_size);
39
40
8
        _initialize_hash_vals(rows);
41
8
        auto* __restrict hashes = _hash_vals.data();
42
8
        RETURN_IF_ERROR(_get_partition_column_result(block, result));
43
16
        for (int j = 0; j < result_size; ++j) {
44
8
            const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
45
8
            if (is_const) {
46
0
                continue;
47
0
            }
48
8
            _do_hash(col, hashes, j);
49
8
        }
50
51
3.14M
        for (size_t i = 0; i < rows; i++) {
52
3.14M
            hashes[i] = ChannelIds()(hashes[i], _partition_count);
53
3.14M
        }
54
55
8
        Block::erase_useless_column(block, column_to_keep);
56
8
    }
57
8
    return Status::OK();
58
8
}
_ZNK5doris20Crc32HashPartitionerINS_26SpillRePartitionChannelIdsEE15do_partitioningEPNS_12RuntimeStateEPNS_5BlockE
Line
Count
Source
31
8
Status Crc32HashPartitioner<ChannelIds>::do_partitioning(RuntimeState* state, Block* block) const {
32
8
    size_t rows = block->rows();
33
34
8
    if (rows > 0) {
35
8
        auto column_to_keep = block->columns();
36
37
8
        int result_size = cast_set<int>(_partition_expr_ctxs.size());
38
8
        std::vector<int> result(result_size);
39
40
8
        _initialize_hash_vals(rows);
41
8
        auto* __restrict hashes = _hash_vals.data();
42
8
        RETURN_IF_ERROR(_get_partition_column_result(block, result));
43
16
        for (int j = 0; j < result_size; ++j) {
44
8
            const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
45
8
            if (is_const) {
46
0
                continue;
47
0
            }
48
8
            _do_hash(col, hashes, j);
49
8
        }
50
51
28
        for (size_t i = 0; i < rows; i++) {
52
20
            hashes[i] = ChannelIds()(hashes[i], _partition_count);
53
20
        }
54
55
8
        Block::erase_useless_column(block, column_to_keep);
56
8
    }
57
8
    return Status::OK();
58
8
}
_ZNK5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEE15do_partitioningEPNS_12RuntimeStateEPNS_5BlockE
Line
Count
Source
31
314k
Status Crc32HashPartitioner<ChannelIds>::do_partitioning(RuntimeState* state, Block* block) const {
32
314k
    size_t rows = block->rows();
33
34
314k
    if (rows > 0) {
35
54.9k
        auto column_to_keep = block->columns();
36
37
54.9k
        int result_size = cast_set<int>(_partition_expr_ctxs.size());
38
54.9k
        std::vector<int> result(result_size);
39
40
54.9k
        _initialize_hash_vals(rows);
41
54.9k
        auto* __restrict hashes = _hash_vals.data();
42
54.9k
        RETURN_IF_ERROR(_get_partition_column_result(block, result));
43
141k
        for (int j = 0; j < result_size; ++j) {
44
86.1k
            const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
45
86.1k
            if (is_const) {
46
3
                continue;
47
3
            }
48
86.1k
            _do_hash(col, hashes, j);
49
86.1k
        }
50
51
31.6M
        for (size_t i = 0; i < rows; i++) {
52
31.6M
            hashes[i] = ChannelIds()(hashes[i], _partition_count);
53
31.6M
        }
54
55
54.9k
        Block::erase_useless_column(block, column_to_keep);
56
54.9k
    }
57
314k
    return Status::OK();
58
314k
}
59
60
template <typename ChannelIds>
61
void Crc32HashPartitioner<ChannelIds>::_do_hash(const ColumnPtr& column,
62
7.09k
                                                HashValType* __restrict result, int idx) const {
63
7.09k
    column->update_crcs_with_value(
64
7.09k
            result, _partition_expr_ctxs[idx]->root()->data_type()->get_primitive_type(),
65
7.09k
            cast_set<HashValType>(column->size()));
66
7.09k
}
_ZNK5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEE8_do_hashERKNS_3COWINS_7IColumnEE13immutable_ptrIS4_EEPji
Line
Count
Source
62
7.07k
                                                HashValType* __restrict result, int idx) const {
63
7.07k
    column->update_crcs_with_value(
64
7.07k
            result, _partition_expr_ctxs[idx]->root()->data_type()->get_primitive_type(),
65
7.07k
            cast_set<HashValType>(column->size()));
66
7.07k
}
_ZNK5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEE8_do_hashERKNS_3COWINS_7IColumnEE13immutable_ptrIS4_EEPji
Line
Count
Source
62
8
                                                HashValType* __restrict result, int idx) const {
63
8
    column->update_crcs_with_value(
64
8
            result, _partition_expr_ctxs[idx]->root()->data_type()->get_primitive_type(),
65
8
            cast_set<HashValType>(column->size()));
66
8
}
_ZNK5doris20Crc32HashPartitionerINS_26SpillRePartitionChannelIdsEE8_do_hashERKNS_3COWINS_7IColumnEE13immutable_ptrIS4_EEPji
Line
Count
Source
62
8
                                                HashValType* __restrict result, int idx) const {
63
8
    column->update_crcs_with_value(
64
8
            result, _partition_expr_ctxs[idx]->root()->data_type()->get_primitive_type(),
65
8
            cast_set<HashValType>(column->size()));
66
8
}
Unexecuted instantiation: _ZNK5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEE8_do_hashERKNS_3COWINS_7IColumnEE13immutable_ptrIS4_EEPji
67
68
template <typename ChannelIds>
69
Status Crc32HashPartitioner<ChannelIds>::clone(RuntimeState* state,
70
4.36k
                                               std::unique_ptr<PartitionerBase>& partitioner) {
71
4.36k
    auto* new_partitioner = new Crc32HashPartitioner<ChannelIds>(_partition_count);
72
4.36k
    partitioner.reset(new_partitioner);
73
4.36k
    return _clone_expr_ctxs(state, new_partitioner->_partition_expr_ctxs);
74
4.36k
}
_ZN5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS_15PartitionerBaseESt14default_deleteIS6_EE
Line
Count
Source
70
4.35k
                                               std::unique_ptr<PartitionerBase>& partitioner) {
71
4.35k
    auto* new_partitioner = new Crc32HashPartitioner<ChannelIds>(_partition_count);
72
4.35k
    partitioner.reset(new_partitioner);
73
4.35k
    return _clone_expr_ctxs(state, new_partitioner->_partition_expr_ctxs);
74
4.35k
}
_ZN5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS_15PartitionerBaseESt14default_deleteIS6_EE
Line
Count
Source
70
5
                                               std::unique_ptr<PartitionerBase>& partitioner) {
71
5
    auto* new_partitioner = new Crc32HashPartitioner<ChannelIds>(_partition_count);
72
5
    partitioner.reset(new_partitioner);
73
5
    return _clone_expr_ctxs(state, new_partitioner->_partition_expr_ctxs);
74
5
}
_ZN5doris20Crc32HashPartitionerINS_26SpillRePartitionChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS_15PartitionerBaseESt14default_deleteIS6_EE
Line
Count
Source
70
4
                                               std::unique_ptr<PartitionerBase>& partitioner) {
71
4
    auto* new_partitioner = new Crc32HashPartitioner<ChannelIds>(_partition_count);
72
4
    partitioner.reset(new_partitioner);
73
4
    return _clone_expr_ctxs(state, new_partitioner->_partition_expr_ctxs);
74
4
}
Unexecuted instantiation: _ZN5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS_15PartitionerBaseESt14default_deleteIS6_EE
75
76
void Crc32CHashPartitioner::_do_hash(const ColumnPtr& column, HashValType* __restrict result,
77
86.1k
                                     int idx) const {
78
86.1k
    column->update_crc32c_batch(result, nullptr);
79
86.1k
}
80
81
Status Crc32CHashPartitioner::clone(RuntimeState* state,
82
187k
                                    std::unique_ptr<PartitionerBase>& partitioner) {
83
187k
    auto* new_partitioner = new Crc32CHashPartitioner(_partition_count);
84
187k
    partitioner.reset(new_partitioner);
85
187k
    return _clone_expr_ctxs(state, new_partitioner->_partition_expr_ctxs);
86
187k
}
87
88
template class Crc32HashPartitioner<ShuffleChannelIds>;
89
template class Crc32HashPartitioner<SpillPartitionChannelIds>;
90
template class Crc32HashPartitioner<SpillRePartitionChannelIds>;
91
92
} // namespace doris