Coverage Report

Created: 2026-07-12 08:37

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
29
template <typename ChannelIds>
30
283k
Status Crc32HashPartitioner<ChannelIds>::do_partitioning(RuntimeState* state, Block* block) const {
31
283k
    size_t rows = block->rows();
32
33
283k
    if (rows > 0) {
34
69.0k
        auto column_to_keep = block->columns();
35
36
69.0k
        int result_size = cast_set<int>(_partition_expr_ctxs.size());
37
69.0k
        std::vector<int> result(result_size);
38
39
69.0k
        _initialize_hash_vals(rows);
40
69.0k
        auto* __restrict hashes = _hash_vals.data();
41
69.0k
        RETURN_IF_ERROR(_get_partition_column_result(block, result));
42
164k
        for (int j = 0; j < result_size; ++j) {
43
95.4k
            const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
44
95.4k
            if (is_const) {
45
1
                continue;
46
1
            }
47
95.4k
            _do_hash(col, hashes, j);
48
95.4k
        }
49
50
96.3M
        for (size_t i = 0; i < rows; i++) {
51
96.2M
            hashes[i] = ChannelIds()(hashes[i], _partition_count);
52
96.2M
        }
53
54
69.0k
        Block::erase_useless_column(block, column_to_keep);
55
69.0k
    }
56
283k
    return Status::OK();
57
283k
}
_ZNK5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEE15do_partitioningEPNS_12RuntimeStateEPNS_5BlockE
Line
Count
Source
30
9.98k
Status Crc32HashPartitioner<ChannelIds>::do_partitioning(RuntimeState* state, Block* block) const {
31
9.98k
    size_t rows = block->rows();
32
33
9.98k
    if (rows > 0) {
34
5.13k
        auto column_to_keep = block->columns();
35
36
5.13k
        int result_size = cast_set<int>(_partition_expr_ctxs.size());
37
5.13k
        std::vector<int> result(result_size);
38
39
5.13k
        _initialize_hash_vals(rows);
40
5.13k
        auto* __restrict hashes = _hash_vals.data();
41
5.13k
        RETURN_IF_ERROR(_get_partition_column_result(block, result));
42
11.1k
        for (int j = 0; j < result_size; ++j) {
43
6.01k
            const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
44
6.01k
            if (is_const) {
45
0
                continue;
46
0
            }
47
6.01k
            _do_hash(col, hashes, j);
48
6.01k
        }
49
50
7.11M
        for (size_t i = 0; i < rows; i++) {
51
7.11M
            hashes[i] = ChannelIds()(hashes[i], _partition_count);
52
7.11M
        }
53
54
5.13k
        Block::erase_useless_column(block, column_to_keep);
55
5.13k
    }
56
9.98k
    return Status::OK();
57
9.98k
}
_ZNK5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEE15do_partitioningEPNS_12RuntimeStateEPNS_5BlockE
Line
Count
Source
30
16
Status Crc32HashPartitioner<ChannelIds>::do_partitioning(RuntimeState* state, Block* block) const {
31
16
    size_t rows = block->rows();
32
33
16
    if (rows > 0) {
34
16
        auto column_to_keep = block->columns();
35
36
16
        int result_size = cast_set<int>(_partition_expr_ctxs.size());
37
16
        std::vector<int> result(result_size);
38
39
16
        _initialize_hash_vals(rows);
40
16
        auto* __restrict hashes = _hash_vals.data();
41
16
        RETURN_IF_ERROR(_get_partition_column_result(block, result));
42
32
        for (int j = 0; j < result_size; ++j) {
43
16
            const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
44
16
            if (is_const) {
45
0
                continue;
46
0
            }
47
16
            _do_hash(col, hashes, j);
48
16
        }
49
50
6.29M
        for (size_t i = 0; i < rows; i++) {
51
6.29M
            hashes[i] = ChannelIds()(hashes[i], _partition_count);
52
6.29M
        }
53
54
16
        Block::erase_useless_column(block, column_to_keep);
55
16
    }
56
16
    return Status::OK();
57
16
}
_ZNK5doris20Crc32HashPartitionerINS_26SpillRePartitionChannelIdsEE15do_partitioningEPNS_12RuntimeStateEPNS_5BlockE
Line
Count
Source
30
16
Status Crc32HashPartitioner<ChannelIds>::do_partitioning(RuntimeState* state, Block* block) const {
31
16
    size_t rows = block->rows();
32
33
16
    if (rows > 0) {
34
16
        auto column_to_keep = block->columns();
35
36
16
        int result_size = cast_set<int>(_partition_expr_ctxs.size());
37
16
        std::vector<int> result(result_size);
38
39
16
        _initialize_hash_vals(rows);
40
16
        auto* __restrict hashes = _hash_vals.data();
41
16
        RETURN_IF_ERROR(_get_partition_column_result(block, result));
42
32
        for (int j = 0; j < result_size; ++j) {
43
16
            const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
44
16
            if (is_const) {
45
0
                continue;
46
0
            }
47
16
            _do_hash(col, hashes, j);
48
16
        }
49
50
56
        for (size_t i = 0; i < rows; i++) {
51
40
            hashes[i] = ChannelIds()(hashes[i], _partition_count);
52
40
        }
53
54
16
        Block::erase_useless_column(block, column_to_keep);
55
16
    }
56
16
    return Status::OK();
57
16
}
_ZNK5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEE15do_partitioningEPNS_12RuntimeStateEPNS_5BlockE
Line
Count
Source
30
273k
Status Crc32HashPartitioner<ChannelIds>::do_partitioning(RuntimeState* state, Block* block) const {
31
273k
    size_t rows = block->rows();
32
33
273k
    if (rows > 0) {
34
63.9k
        auto column_to_keep = block->columns();
35
36
63.9k
        int result_size = cast_set<int>(_partition_expr_ctxs.size());
37
63.9k
        std::vector<int> result(result_size);
38
39
63.9k
        _initialize_hash_vals(rows);
40
63.9k
        auto* __restrict hashes = _hash_vals.data();
41
63.9k
        RETURN_IF_ERROR(_get_partition_column_result(block, result));
42
153k
        for (int j = 0; j < result_size; ++j) {
43
89.4k
            const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
44
89.4k
            if (is_const) {
45
1
                continue;
46
1
            }
47
89.4k
            _do_hash(col, hashes, j);
48
89.4k
        }
49
50
82.9M
        for (size_t i = 0; i < rows; i++) {
51
82.8M
            hashes[i] = ChannelIds()(hashes[i], _partition_count);
52
82.8M
        }
53
54
63.9k
        Block::erase_useless_column(block, column_to_keep);
55
63.9k
    }
56
273k
    return Status::OK();
57
273k
}
58
59
template <typename ChannelIds>
60
void Crc32HashPartitioner<ChannelIds>::_do_hash(const ColumnPtr& column,
61
6.04k
                                                HashValType* __restrict result, int idx) const {
62
6.04k
    column->update_crcs_with_value(
63
6.04k
            result, _partition_expr_ctxs[idx]->root()->data_type()->get_primitive_type(),
64
6.04k
            cast_set<HashValType>(column->size()));
65
6.04k
}
_ZNK5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEE8_do_hashERKNS_3COWINS_7IColumnEE13immutable_ptrIS4_EEPji
Line
Count
Source
61
6.00k
                                                HashValType* __restrict result, int idx) const {
62
6.00k
    column->update_crcs_with_value(
63
6.00k
            result, _partition_expr_ctxs[idx]->root()->data_type()->get_primitive_type(),
64
6.00k
            cast_set<HashValType>(column->size()));
65
6.00k
}
_ZNK5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEE8_do_hashERKNS_3COWINS_7IColumnEE13immutable_ptrIS4_EEPji
Line
Count
Source
61
16
                                                HashValType* __restrict result, int idx) const {
62
16
    column->update_crcs_with_value(
63
16
            result, _partition_expr_ctxs[idx]->root()->data_type()->get_primitive_type(),
64
16
            cast_set<HashValType>(column->size()));
65
16
}
_ZNK5doris20Crc32HashPartitionerINS_26SpillRePartitionChannelIdsEE8_do_hashERKNS_3COWINS_7IColumnEE13immutable_ptrIS4_EEPji
Line
Count
Source
61
16
                                                HashValType* __restrict result, int idx) const {
62
16
    column->update_crcs_with_value(
63
16
            result, _partition_expr_ctxs[idx]->root()->data_type()->get_primitive_type(),
64
16
            cast_set<HashValType>(column->size()));
65
16
}
Unexecuted instantiation: _ZNK5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEE8_do_hashERKNS_3COWINS_7IColumnEE13immutable_ptrIS4_EEPji
66
67
template <typename ChannelIds>
68
Status Crc32HashPartitioner<ChannelIds>::clone(RuntimeState* state,
69
825
                                               std::unique_ptr<PartitionerBase>& partitioner) {
70
825
    auto* new_partitioner = new Crc32HashPartitioner<ChannelIds>(_partition_count);
71
825
    partitioner.reset(new_partitioner);
72
825
    return _clone_expr_ctxs(state, new_partitioner->_partition_expr_ctxs);
73
825
}
_ZN5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS_15PartitionerBaseESt14default_deleteIS6_EE
Line
Count
Source
69
807
                                               std::unique_ptr<PartitionerBase>& partitioner) {
70
807
    auto* new_partitioner = new Crc32HashPartitioner<ChannelIds>(_partition_count);
71
807
    partitioner.reset(new_partitioner);
72
807
    return _clone_expr_ctxs(state, new_partitioner->_partition_expr_ctxs);
73
807
}
_ZN5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS_15PartitionerBaseESt14default_deleteIS6_EE
Line
Count
Source
69
10
                                               std::unique_ptr<PartitionerBase>& partitioner) {
70
10
    auto* new_partitioner = new Crc32HashPartitioner<ChannelIds>(_partition_count);
71
10
    partitioner.reset(new_partitioner);
72
10
    return _clone_expr_ctxs(state, new_partitioner->_partition_expr_ctxs);
73
10
}
_ZN5doris20Crc32HashPartitionerINS_26SpillRePartitionChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS_15PartitionerBaseESt14default_deleteIS6_EE
Line
Count
Source
69
8
                                               std::unique_ptr<PartitionerBase>& partitioner) {
70
8
    auto* new_partitioner = new Crc32HashPartitioner<ChannelIds>(_partition_count);
71
8
    partitioner.reset(new_partitioner);
72
8
    return _clone_expr_ctxs(state, new_partitioner->_partition_expr_ctxs);
73
8
}
Unexecuted instantiation: _ZN5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS_15PartitionerBaseESt14default_deleteIS6_EE
74
75
void Crc32CHashPartitioner::_do_hash(const ColumnPtr& column, HashValType* __restrict result,
76
89.4k
                                     int idx) const {
77
89.4k
    column->update_crc32c_batch(result, nullptr);
78
89.4k
}
79
80
Status Crc32CHashPartitioner::clone(RuntimeState* state,
81
135k
                                    std::unique_ptr<PartitionerBase>& partitioner) {
82
135k
    auto* new_partitioner = new Crc32CHashPartitioner(_partition_count);
83
135k
    partitioner.reset(new_partitioner);
84
135k
    return _clone_expr_ctxs(state, new_partitioner->_partition_expr_ctxs);
85
135k
}
86
87
template class Crc32HashPartitioner<ShuffleChannelIds>;
88
template class Crc32HashPartitioner<SpillPartitionChannelIds>;
89
template class Crc32HashPartitioner<SpillRePartitionChannelIds>;
90
91
} // namespace doris