Coverage Report

Created: 2026-03-13 03:47

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
356k
Status Crc32HashPartitioner<ChannelIds>::do_partitioning(RuntimeState* state, Block* block) const {
32
356k
    size_t rows = block->rows();
33
34
356k
    if (rows > 0) {
35
45.8k
        auto column_to_keep = block->columns();
36
37
45.8k
        int result_size = cast_set<int>(_partition_expr_ctxs.size());
38
45.8k
        std::vector<int> result(result_size);
39
40
45.8k
        _initialize_hash_vals(rows);
41
45.8k
        auto* __restrict hashes = _hash_vals.data();
42
45.8k
        RETURN_IF_ERROR(_get_partition_column_result(block, result));
43
120k
        for (int j = 0; j < result_size; ++j) {
44
74.1k
            const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
45
74.1k
            if (is_const) {
46
1
                continue;
47
1
            }
48
74.1k
            _do_hash(col, hashes, j);
49
74.1k
        }
50
51
17.5M
        for (size_t i = 0; i < rows; i++) {
52
17.4M
            hashes[i] = ChannelIds()(hashes[i], _partition_count);
53
17.4M
        }
54
55
45.8k
        Block::erase_useless_column(block, column_to_keep);
56
45.8k
    }
57
356k
    return Status::OK();
58
356k
}
_ZNK5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEE15do_partitioningEPNS_12RuntimeStateEPNS_5BlockE
Line
Count
Source
31
18.7k
Status Crc32HashPartitioner<ChannelIds>::do_partitioning(RuntimeState* state, Block* block) const {
32
18.7k
    size_t rows = block->rows();
33
34
18.7k
    if (rows > 0) {
35
6.60k
        auto column_to_keep = block->columns();
36
37
6.60k
        int result_size = cast_set<int>(_partition_expr_ctxs.size());
38
6.60k
        std::vector<int> result(result_size);
39
40
6.60k
        _initialize_hash_vals(rows);
41
6.60k
        auto* __restrict hashes = _hash_vals.data();
42
6.60k
        RETURN_IF_ERROR(_get_partition_column_result(block, result));
43
13.2k
        for (int j = 0; j < result_size; ++j) {
44
6.60k
            const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
45
6.60k
            if (is_const) {
46
0
                continue;
47
0
            }
48
6.60k
            _do_hash(col, hashes, j);
49
6.60k
        }
50
51
2.61M
        for (size_t i = 0; i < rows; i++) {
52
2.61M
            hashes[i] = ChannelIds()(hashes[i], _partition_count);
53
2.61M
        }
54
55
6.60k
        Block::erase_useless_column(block, column_to_keep);
56
6.60k
    }
57
18.7k
    return Status::OK();
58
18.7k
}
_ZNK5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEE15do_partitioningEPNS_12RuntimeStateEPNS_5BlockE
Line
Count
Source
31
6
Status Crc32HashPartitioner<ChannelIds>::do_partitioning(RuntimeState* state, Block* block) const {
32
6
    size_t rows = block->rows();
33
34
6
    if (rows > 0) {
35
6
        auto column_to_keep = block->columns();
36
37
6
        int result_size = cast_set<int>(_partition_expr_ctxs.size());
38
6
        std::vector<int> result(result_size);
39
40
6
        _initialize_hash_vals(rows);
41
6
        auto* __restrict hashes = _hash_vals.data();
42
6
        RETURN_IF_ERROR(_get_partition_column_result(block, result));
43
12
        for (int j = 0; j < result_size; ++j) {
44
6
            const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
45
6
            if (is_const) {
46
0
                continue;
47
0
            }
48
6
            _do_hash(col, hashes, j);
49
6
        }
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
6
        Block::erase_useless_column(block, column_to_keep);
56
6
    }
57
6
    return Status::OK();
58
6
}
_ZNK5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEE15do_partitioningEPNS_12RuntimeStateEPNS_5BlockE
Line
Count
Source
31
337k
Status Crc32HashPartitioner<ChannelIds>::do_partitioning(RuntimeState* state, Block* block) const {
32
337k
    size_t rows = block->rows();
33
34
337k
    if (rows > 0) {
35
39.2k
        auto column_to_keep = block->columns();
36
37
39.2k
        int result_size = cast_set<int>(_partition_expr_ctxs.size());
38
39.2k
        std::vector<int> result(result_size);
39
40
39.2k
        _initialize_hash_vals(rows);
41
39.2k
        auto* __restrict hashes = _hash_vals.data();
42
39.2k
        RETURN_IF_ERROR(_get_partition_column_result(block, result));
43
106k
        for (int j = 0; j < result_size; ++j) {
44
67.5k
            const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
45
67.5k
            if (is_const) {
46
1
                continue;
47
1
            }
48
67.5k
            _do_hash(col, hashes, j);
49
67.5k
        }
50
51
11.7M
        for (size_t i = 0; i < rows; i++) {
52
11.7M
            hashes[i] = ChannelIds()(hashes[i], _partition_count);
53
11.7M
        }
54
55
39.2k
        Block::erase_useless_column(block, column_to_keep);
56
39.2k
    }
57
337k
    return Status::OK();
58
337k
}
59
60
template <typename ChannelIds>
61
void Crc32HashPartitioner<ChannelIds>::_do_hash(const ColumnPtr& column,
62
6.61k
                                                HashValType* __restrict result, int idx) const {
63
6.61k
    column->update_crcs_with_value(
64
6.61k
            result, _partition_expr_ctxs[idx]->root()->data_type()->get_primitive_type(),
65
6.61k
            cast_set<HashValType>(column->size()));
66
6.61k
}
_ZNK5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEE8_do_hashERKNS_3COWINS_7IColumnEE13immutable_ptrIS4_EEPji
Line
Count
Source
62
6.60k
                                                HashValType* __restrict result, int idx) const {
63
6.60k
    column->update_crcs_with_value(
64
6.60k
            result, _partition_expr_ctxs[idx]->root()->data_type()->get_primitive_type(),
65
6.60k
            cast_set<HashValType>(column->size()));
66
6.60k
}
_ZNK5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEE8_do_hashERKNS_3COWINS_7IColumnEE13immutable_ptrIS4_EEPji
Line
Count
Source
62
6
                                                HashValType* __restrict result, int idx) const {
63
6
    column->update_crcs_with_value(
64
6
            result, _partition_expr_ctxs[idx]->root()->data_type()->get_primitive_type(),
65
6
            cast_set<HashValType>(column->size()));
66
6
}
Unexecuted instantiation: _ZNK5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEE8_do_hashERKNS_3COWINS_7IColumnEE13immutable_ptrIS4_EEPji
67
68
template <typename ChannelIds>
69
Status Crc32HashPartitioner<ChannelIds>::clone(RuntimeState* state,
70
6.49k
                                               std::unique_ptr<PartitionerBase>& partitioner) {
71
6.49k
    auto* new_partitioner = new Crc32HashPartitioner<ChannelIds>(_partition_count);
72
6.49k
    partitioner.reset(new_partitioner);
73
6.49k
    return _clone_expr_ctxs(state, new_partitioner->_partition_expr_ctxs);
74
6.49k
}
_ZN5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS_15PartitionerBaseESt14default_deleteIS6_EE
Line
Count
Source
70
6.49k
                                               std::unique_ptr<PartitionerBase>& partitioner) {
71
6.49k
    auto* new_partitioner = new Crc32HashPartitioner<ChannelIds>(_partition_count);
72
6.49k
    partitioner.reset(new_partitioner);
73
6.49k
    return _clone_expr_ctxs(state, new_partitioner->_partition_expr_ctxs);
74
6.49k
}
_ZN5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS_15PartitionerBaseESt14default_deleteIS6_EE
Line
Count
Source
70
3
                                               std::unique_ptr<PartitionerBase>& partitioner) {
71
3
    auto* new_partitioner = new Crc32HashPartitioner<ChannelIds>(_partition_count);
72
3
    partitioner.reset(new_partitioner);
73
3
    return _clone_expr_ctxs(state, new_partitioner->_partition_expr_ctxs);
74
3
}
Unexecuted instantiation: _ZN5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS_15PartitionerBaseESt14default_deleteIS6_EE
75
76
void Crc32CHashPartitioner::_do_hash(const ColumnPtr& column, HashValType* __restrict result,
77
67.5k
                                     int idx) const {
78
67.5k
    column->update_crc32c_batch(result, nullptr);
79
67.5k
}
80
81
Status Crc32CHashPartitioner::clone(RuntimeState* state,
82
217k
                                    std::unique_ptr<PartitionerBase>& partitioner) {
83
217k
    auto* new_partitioner = new Crc32CHashPartitioner(_partition_count);
84
217k
    partitioner.reset(new_partitioner);
85
217k
    return _clone_expr_ctxs(state, new_partitioner->_partition_expr_ctxs);
86
217k
}
87
88
template class Crc32HashPartitioner<ShuffleChannelIds>;
89
template class Crc32HashPartitioner<SpillPartitionChannelIds>;
90
91
} // namespace doris