Coverage Report

Created: 2026-04-15 06:08

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
302k
Status Crc32HashPartitioner<ChannelIds>::do_partitioning(RuntimeState* state, Block* block) const {
31
302k
    size_t rows = block->rows();
32
33
302k
    if (rows > 0) {
34
50.7k
        auto column_to_keep = block->columns();
35
36
50.7k
        int result_size = cast_set<int>(_partition_expr_ctxs.size());
37
50.7k
        std::vector<int> result(result_size);
38
39
50.7k
        _initialize_hash_vals(rows);
40
50.7k
        auto* __restrict hashes = _hash_vals.data();
41
50.7k
        RETURN_IF_ERROR(_get_partition_column_result(block, result));
42
129k
        for (int j = 0; j < result_size; ++j) {
43
78.2k
            const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
44
78.2k
            if (is_const) {
45
0
                continue;
46
0
            }
47
78.2k
            _do_hash(col, hashes, j);
48
78.2k
        }
49
50
32.4M
        for (size_t i = 0; i < rows; i++) {
51
32.4M
            hashes[i] = ChannelIds()(hashes[i], _partition_count);
52
32.4M
        }
53
54
50.7k
        Block::erase_useless_column(block, column_to_keep);
55
50.7k
    }
56
302k
    return Status::OK();
57
302k
}
_ZNK5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEE15do_partitioningEPNS_12RuntimeStateEPNS_5BlockE
Line
Count
Source
30
10.9k
Status Crc32HashPartitioner<ChannelIds>::do_partitioning(RuntimeState* state, Block* block) const {
31
10.9k
    size_t rows = block->rows();
32
33
10.9k
    if (rows > 0) {
34
4.59k
        auto column_to_keep = block->columns();
35
36
4.59k
        int result_size = cast_set<int>(_partition_expr_ctxs.size());
37
4.59k
        std::vector<int> result(result_size);
38
39
4.59k
        _initialize_hash_vals(rows);
40
4.59k
        auto* __restrict hashes = _hash_vals.data();
41
4.59k
        RETURN_IF_ERROR(_get_partition_column_result(block, result));
42
10.0k
        for (int j = 0; j < result_size; ++j) {
43
5.47k
            const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
44
5.47k
            if (is_const) {
45
0
                continue;
46
0
            }
47
5.47k
            _do_hash(col, hashes, j);
48
5.47k
        }
49
50
2.45M
        for (size_t i = 0; i < rows; i++) {
51
2.44M
            hashes[i] = ChannelIds()(hashes[i], _partition_count);
52
2.44M
        }
53
54
4.59k
        Block::erase_useless_column(block, column_to_keep);
55
4.59k
    }
56
10.9k
    return Status::OK();
57
10.9k
}
_ZNK5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEE15do_partitioningEPNS_12RuntimeStateEPNS_5BlockE
Line
Count
Source
30
8
Status Crc32HashPartitioner<ChannelIds>::do_partitioning(RuntimeState* state, Block* block) const {
31
8
    size_t rows = block->rows();
32
33
8
    if (rows > 0) {
34
8
        auto column_to_keep = block->columns();
35
36
8
        int result_size = cast_set<int>(_partition_expr_ctxs.size());
37
8
        std::vector<int> result(result_size);
38
39
8
        _initialize_hash_vals(rows);
40
8
        auto* __restrict hashes = _hash_vals.data();
41
8
        RETURN_IF_ERROR(_get_partition_column_result(block, result));
42
16
        for (int j = 0; j < result_size; ++j) {
43
8
            const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
44
8
            if (is_const) {
45
0
                continue;
46
0
            }
47
8
            _do_hash(col, hashes, j);
48
8
        }
49
50
3.14M
        for (size_t i = 0; i < rows; i++) {
51
3.14M
            hashes[i] = ChannelIds()(hashes[i], _partition_count);
52
3.14M
        }
53
54
8
        Block::erase_useless_column(block, column_to_keep);
55
8
    }
56
8
    return Status::OK();
57
8
}
_ZNK5doris20Crc32HashPartitionerINS_26SpillRePartitionChannelIdsEE15do_partitioningEPNS_12RuntimeStateEPNS_5BlockE
Line
Count
Source
30
8
Status Crc32HashPartitioner<ChannelIds>::do_partitioning(RuntimeState* state, Block* block) const {
31
8
    size_t rows = block->rows();
32
33
8
    if (rows > 0) {
34
8
        auto column_to_keep = block->columns();
35
36
8
        int result_size = cast_set<int>(_partition_expr_ctxs.size());
37
8
        std::vector<int> result(result_size);
38
39
8
        _initialize_hash_vals(rows);
40
8
        auto* __restrict hashes = _hash_vals.data();
41
8
        RETURN_IF_ERROR(_get_partition_column_result(block, result));
42
16
        for (int j = 0; j < result_size; ++j) {
43
8
            const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
44
8
            if (is_const) {
45
0
                continue;
46
0
            }
47
8
            _do_hash(col, hashes, j);
48
8
        }
49
50
28
        for (size_t i = 0; i < rows; i++) {
51
20
            hashes[i] = ChannelIds()(hashes[i], _partition_count);
52
20
        }
53
54
8
        Block::erase_useless_column(block, column_to_keep);
55
8
    }
56
8
    return Status::OK();
57
8
}
_ZNK5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEE15do_partitioningEPNS_12RuntimeStateEPNS_5BlockE
Line
Count
Source
30
291k
Status Crc32HashPartitioner<ChannelIds>::do_partitioning(RuntimeState* state, Block* block) const {
31
291k
    size_t rows = block->rows();
32
33
291k
    if (rows > 0) {
34
46.1k
        auto column_to_keep = block->columns();
35
36
46.1k
        int result_size = cast_set<int>(_partition_expr_ctxs.size());
37
46.1k
        std::vector<int> result(result_size);
38
39
46.1k
        _initialize_hash_vals(rows);
40
46.1k
        auto* __restrict hashes = _hash_vals.data();
41
46.1k
        RETURN_IF_ERROR(_get_partition_column_result(block, result));
42
118k
        for (int j = 0; j < result_size; ++j) {
43
72.7k
            const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
44
72.7k
            if (is_const) {
45
0
                continue;
46
0
            }
47
72.7k
            _do_hash(col, hashes, j);
48
72.7k
        }
49
50
26.8M
        for (size_t i = 0; i < rows; i++) {
51
26.8M
            hashes[i] = ChannelIds()(hashes[i], _partition_count);
52
26.8M
        }
53
54
46.1k
        Block::erase_useless_column(block, column_to_keep);
55
46.1k
    }
56
291k
    return Status::OK();
57
291k
}
58
59
template <typename ChannelIds>
60
void Crc32HashPartitioner<ChannelIds>::_do_hash(const ColumnPtr& column,
61
5.48k
                                                HashValType* __restrict result, int idx) const {
62
5.48k
    column->update_crcs_with_value(
63
5.48k
            result, _partition_expr_ctxs[idx]->root()->data_type()->get_primitive_type(),
64
5.48k
            cast_set<HashValType>(column->size()));
65
5.48k
}
_ZNK5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEE8_do_hashERKNS_3COWINS_7IColumnEE13immutable_ptrIS4_EEPji
Line
Count
Source
61
5.46k
                                                HashValType* __restrict result, int idx) const {
62
5.46k
    column->update_crcs_with_value(
63
5.46k
            result, _partition_expr_ctxs[idx]->root()->data_type()->get_primitive_type(),
64
5.46k
            cast_set<HashValType>(column->size()));
65
5.46k
}
_ZNK5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEE8_do_hashERKNS_3COWINS_7IColumnEE13immutable_ptrIS4_EEPji
Line
Count
Source
61
8
                                                HashValType* __restrict result, int idx) const {
62
8
    column->update_crcs_with_value(
63
8
            result, _partition_expr_ctxs[idx]->root()->data_type()->get_primitive_type(),
64
8
            cast_set<HashValType>(column->size()));
65
8
}
_ZNK5doris20Crc32HashPartitionerINS_26SpillRePartitionChannelIdsEE8_do_hashERKNS_3COWINS_7IColumnEE13immutable_ptrIS4_EEPji
Line
Count
Source
61
8
                                                HashValType* __restrict result, int idx) const {
62
8
    column->update_crcs_with_value(
63
8
            result, _partition_expr_ctxs[idx]->root()->data_type()->get_primitive_type(),
64
8
            cast_set<HashValType>(column->size()));
65
8
}
Unexecuted instantiation: _ZNK5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEE8_do_hashERKNS_3COWINS_7IColumnEE13immutable_ptrIS4_EEPji
66
67
template <typename ChannelIds>
68
Status Crc32HashPartitioner<ChannelIds>::clone(RuntimeState* state,
69
3.29k
                                               std::unique_ptr<PartitionerBase>& partitioner) {
70
3.29k
    auto* new_partitioner = new Crc32HashPartitioner<ChannelIds>(_partition_count);
71
3.29k
    partitioner.reset(new_partitioner);
72
3.29k
    return _clone_expr_ctxs(state, new_partitioner->_partition_expr_ctxs);
73
3.29k
}
_ZN5doris20Crc32HashPartitionerINS_17ShuffleChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS_15PartitionerBaseESt14default_deleteIS6_EE
Line
Count
Source
69
3.28k
                                               std::unique_ptr<PartitionerBase>& partitioner) {
70
3.28k
    auto* new_partitioner = new Crc32HashPartitioner<ChannelIds>(_partition_count);
71
3.28k
    partitioner.reset(new_partitioner);
72
3.28k
    return _clone_expr_ctxs(state, new_partitioner->_partition_expr_ctxs);
73
3.28k
}
_ZN5doris20Crc32HashPartitionerINS_24SpillPartitionChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS_15PartitionerBaseESt14default_deleteIS6_EE
Line
Count
Source
69
5
                                               std::unique_ptr<PartitionerBase>& partitioner) {
70
5
    auto* new_partitioner = new Crc32HashPartitioner<ChannelIds>(_partition_count);
71
5
    partitioner.reset(new_partitioner);
72
5
    return _clone_expr_ctxs(state, new_partitioner->_partition_expr_ctxs);
73
5
}
_ZN5doris20Crc32HashPartitionerINS_26SpillRePartitionChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS_15PartitionerBaseESt14default_deleteIS6_EE
Line
Count
Source
69
4
                                               std::unique_ptr<PartitionerBase>& partitioner) {
70
4
    auto* new_partitioner = new Crc32HashPartitioner<ChannelIds>(_partition_count);
71
4
    partitioner.reset(new_partitioner);
72
4
    return _clone_expr_ctxs(state, new_partitioner->_partition_expr_ctxs);
73
4
}
Unexecuted instantiation: _ZN5doris20Crc32HashPartitionerINS_15ShiftChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS_15PartitionerBaseESt14default_deleteIS6_EE
74
75
void Crc32CHashPartitioner::_do_hash(const ColumnPtr& column, HashValType* __restrict result,
76
72.7k
                                     int idx) const {
77
72.7k
    column->update_crc32c_batch(result, nullptr);
78
72.7k
}
79
80
Status Crc32CHashPartitioner::clone(RuntimeState* state,
81
83.5k
                                    std::unique_ptr<PartitionerBase>& partitioner) {
82
83.5k
    auto* new_partitioner = new Crc32CHashPartitioner(_partition_count);
83
83.5k
    partitioner.reset(new_partitioner);
84
83.5k
    return _clone_expr_ctxs(state, new_partitioner->_partition_expr_ctxs);
85
83.5k
}
86
87
template class Crc32HashPartitioner<ShuffleChannelIds>;
88
template class Crc32HashPartitioner<SpillPartitionChannelIds>;
89
template class Crc32HashPartitioner<SpillRePartitionChannelIds>;
90
91
} // namespace doris