Coverage Report

Created: 2025-05-20 19:11

/root/doris/be/src/vec/runtime/partitioner.cpp
Line
Count
Source (jump to first uncovered line)
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 "partitioner.h"
19
20
#include "pipeline/pipeline_x/local_exchange/local_exchange_sink_operator.h"
21
#include "runtime/thread_context.h"
22
#include "vec/columns/column_const.h"
23
#include "vec/sink/vdata_stream_sender.h"
24
25
namespace doris::vectorized {
26
27
template <typename HashValueType, typename ChannelIds>
28
Status Partitioner<HashValueType, ChannelIds>::do_partitioning(RuntimeState* state, Block* block,
29
0
                                                               MemTracker* mem_tracker) const {
30
0
    int rows = block->rows();
31
32
0
    if (rows > 0) {
33
0
        auto column_to_keep = block->columns();
34
35
0
        int result_size = _partition_expr_ctxs.size();
36
0
        std::vector<int> result(result_size);
37
38
0
        _hash_vals.resize(rows);
39
0
        std::fill(_hash_vals.begin(), _hash_vals.end(), 0);
40
0
        auto* __restrict hashes = _hash_vals.data();
41
0
        {
42
0
            SCOPED_CONSUME_MEM_TRACKER(mem_tracker);
43
0
            RETURN_IF_ERROR(_get_partition_column_result(block, result));
44
0
        }
45
0
        for (int j = 0; j < result_size; ++j) {
46
0
            const auto& [col, is_const] = unpack_if_const(block->get_by_position(result[j]).column);
47
0
            if (is_const) {
48
0
                continue;
49
0
            }
50
0
            _do_hash(col, hashes, j);
51
0
        }
52
53
0
        for (int i = 0; i < rows; i++) {
54
0
            hashes[i] = ChannelIds()(hashes[i], _partition_count);
55
0
        }
56
57
0
        {
58
0
            SCOPED_CONSUME_MEM_TRACKER(mem_tracker);
59
0
            Block::erase_useless_column(block, column_to_keep);
60
0
        }
61
0
    }
62
0
    return Status::OK();
63
0
}
Unexecuted instantiation: _ZNK5doris10vectorized11PartitionerImNS_8pipeline23LocalExchangeChannelIdsEE15do_partitioningEPNS_12RuntimeStateEPNS0_5BlockEPNS_10MemTrackerE
Unexecuted instantiation: _ZNK5doris10vectorized11PartitionerImNS0_17ShuffleChannelIdsEE15do_partitioningEPNS_12RuntimeStateEPNS0_5BlockEPNS_10MemTrackerE
Unexecuted instantiation: _ZNK5doris10vectorized11PartitionerIjNS0_17ShuffleChannelIdsEE15do_partitioningEPNS_12RuntimeStateEPNS0_5BlockEPNS_10MemTrackerE
Unexecuted instantiation: _ZNK5doris10vectorized11PartitionerIjNS0_24SpillPartitionChannelIdsEE15do_partitioningEPNS_12RuntimeStateEPNS0_5BlockEPNS_10MemTrackerE
64
65
template <typename ChannelIds>
66
void Crc32HashPartitioner<ChannelIds>::_do_hash(const ColumnPtr& column,
67
0
                                                uint32_t* __restrict result, int idx) const {
68
0
    column->update_crcs_with_value(result, Base::_partition_expr_ctxs[idx]->root()->type().type,
69
0
                                   column->size());
70
0
}
Unexecuted instantiation: _ZNK5doris10vectorized20Crc32HashPartitionerINS0_17ShuffleChannelIdsEE8_do_hashERKN3COWINS0_7IColumnEE13immutable_ptrIS5_EEPji
Unexecuted instantiation: _ZNK5doris10vectorized20Crc32HashPartitionerINS0_24SpillPartitionChannelIdsEE8_do_hashERKN3COWINS0_7IColumnEE13immutable_ptrIS5_EEPji
71
72
template <typename ChannelIds>
73
void XXHashPartitioner<ChannelIds>::_do_hash(const ColumnPtr& column, uint64_t* __restrict result,
74
0
                                             int /*idx*/) const {
75
0
    column->update_hashes_with_value(result);
76
0
}
Unexecuted instantiation: _ZNK5doris10vectorized17XXHashPartitionerINS_8pipeline23LocalExchangeChannelIdsEE8_do_hashERKN3COWINS0_7IColumnEE13immutable_ptrIS6_EEPmi
Unexecuted instantiation: _ZNK5doris10vectorized17XXHashPartitionerINS0_17ShuffleChannelIdsEE8_do_hashERKN3COWINS0_7IColumnEE13immutable_ptrIS5_EEPmi
77
78
template <typename ChannelIds>
79
Status XXHashPartitioner<ChannelIds>::clone(RuntimeState* state,
80
0
                                            std::unique_ptr<PartitionerBase>& partitioner) {
81
0
    auto* new_partitioner = new XXHashPartitioner(Base::_partition_count);
82
0
    partitioner.reset(new_partitioner);
83
0
    new_partitioner->_partition_expr_ctxs.resize(Base::_partition_expr_ctxs.size());
84
0
    for (size_t i = 0; i < Base::_partition_expr_ctxs.size(); i++) {
85
0
        RETURN_IF_ERROR(Base::_partition_expr_ctxs[i]->clone(
86
0
                state, new_partitioner->_partition_expr_ctxs[i]));
87
0
    }
88
0
    return Status::OK();
89
0
}
Unexecuted instantiation: _ZN5doris10vectorized17XXHashPartitionerINS_8pipeline23LocalExchangeChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS0_15PartitionerBaseESt14default_deleteIS8_EE
Unexecuted instantiation: _ZN5doris10vectorized17XXHashPartitionerINS0_17ShuffleChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS0_15PartitionerBaseESt14default_deleteIS7_EE
90
91
template <typename ChannelIds>
92
Status Crc32HashPartitioner<ChannelIds>::clone(RuntimeState* state,
93
0
                                               std::unique_ptr<PartitionerBase>& partitioner) {
94
0
    auto* new_partitioner = new Crc32HashPartitioner(Base::_partition_count);
95
0
    partitioner.reset(new_partitioner);
96
0
    new_partitioner->_partition_expr_ctxs.resize(Base::_partition_expr_ctxs.size());
97
0
    for (size_t i = 0; i < Base::_partition_expr_ctxs.size(); i++) {
98
0
        RETURN_IF_ERROR(Base::_partition_expr_ctxs[i]->clone(
99
0
                state, new_partitioner->_partition_expr_ctxs[i]));
100
0
    }
101
0
    return Status::OK();
102
0
}
Unexecuted instantiation: _ZN5doris10vectorized20Crc32HashPartitionerINS0_17ShuffleChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS0_15PartitionerBaseESt14default_deleteIS7_EE
Unexecuted instantiation: _ZN5doris10vectorized20Crc32HashPartitionerINS0_24SpillPartitionChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS0_15PartitionerBaseESt14default_deleteIS7_EE
103
104
template class Partitioner<size_t, pipeline::LocalExchangeChannelIds>;
105
template class XXHashPartitioner<pipeline::LocalExchangeChannelIds>;
106
template class Partitioner<size_t, ShuffleChannelIds>;
107
template class XXHashPartitioner<ShuffleChannelIds>;
108
template class Partitioner<uint32_t, ShuffleChannelIds>;
109
template class Crc32HashPartitioner<ShuffleChannelIds>;
110
template class Crc32HashPartitioner<SpillPartitionChannelIds>;
111
112
} // namespace doris::vectorized