Coverage Report

Created: 2024-11-20 12:30

/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
            _do_hash(unpack_if_const(block->get_by_position(result[j]).column).first, hashes, j);
47
0
        }
48
49
0
        for (int i = 0; i < rows; i++) {
50
0
            hashes[i] = ChannelIds()(hashes[i], _partition_count);
51
0
        }
52
53
0
        {
54
0
            SCOPED_CONSUME_MEM_TRACKER(mem_tracker);
55
0
            Block::erase_useless_column(block, column_to_keep);
56
0
        }
57
0
    }
58
0
    return Status::OK();
59
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
60
61
template <typename ChannelIds>
62
void Crc32HashPartitioner<ChannelIds>::_do_hash(const ColumnPtr& column,
63
0
                                                uint32_t* __restrict result, int idx) const {
64
0
    column->update_crcs_with_value(result, Base::_partition_expr_ctxs[idx]->root()->type().type,
65
0
                                   column->size());
66
0
}
Unexecuted instantiation: _ZNK5doris10vectorized20Crc32HashPartitionerINS0_17ShuffleChannelIdsEE8_do_hashERKN3COWINS0_7IColumnEE13immutable_ptrIS5_EEPji
Unexecuted instantiation: _ZNK5doris10vectorized20Crc32HashPartitionerINS0_24SpillPartitionChannelIdsEE8_do_hashERKN3COWINS0_7IColumnEE13immutable_ptrIS5_EEPji
67
68
template <typename ChannelIds>
69
void XXHashPartitioner<ChannelIds>::_do_hash(const ColumnPtr& column, uint64_t* __restrict result,
70
0
                                             int /*idx*/) const {
71
0
    column->update_hashes_with_value(result);
72
0
}
Unexecuted instantiation: _ZNK5doris10vectorized17XXHashPartitionerINS_8pipeline23LocalExchangeChannelIdsEE8_do_hashERKN3COWINS0_7IColumnEE13immutable_ptrIS6_EEPmi
Unexecuted instantiation: _ZNK5doris10vectorized17XXHashPartitionerINS0_17ShuffleChannelIdsEE8_do_hashERKN3COWINS0_7IColumnEE13immutable_ptrIS5_EEPmi
73
74
template <typename ChannelIds>
75
Status XXHashPartitioner<ChannelIds>::clone(RuntimeState* state,
76
0
                                            std::unique_ptr<PartitionerBase>& partitioner) {
77
0
    auto* new_partitioner = new XXHashPartitioner(Base::_partition_count);
78
0
    partitioner.reset(new_partitioner);
79
0
    new_partitioner->_partition_expr_ctxs.resize(Base::_partition_expr_ctxs.size());
80
0
    for (size_t i = 0; i < Base::_partition_expr_ctxs.size(); i++) {
81
0
        RETURN_IF_ERROR(Base::_partition_expr_ctxs[i]->clone(
82
0
                state, new_partitioner->_partition_expr_ctxs[i]));
83
0
    }
84
0
    return Status::OK();
85
0
}
Unexecuted instantiation: _ZN5doris10vectorized17XXHashPartitionerINS_8pipeline23LocalExchangeChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS0_15PartitionerBaseESt14default_deleteIS8_EE
Unexecuted instantiation: _ZN5doris10vectorized17XXHashPartitionerINS0_17ShuffleChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS0_15PartitionerBaseESt14default_deleteIS7_EE
86
87
template <typename ChannelIds>
88
Status Crc32HashPartitioner<ChannelIds>::clone(RuntimeState* state,
89
0
                                               std::unique_ptr<PartitionerBase>& partitioner) {
90
0
    auto* new_partitioner = new Crc32HashPartitioner(Base::_partition_count);
91
0
    partitioner.reset(new_partitioner);
92
0
    new_partitioner->_partition_expr_ctxs.resize(Base::_partition_expr_ctxs.size());
93
0
    for (size_t i = 0; i < Base::_partition_expr_ctxs.size(); i++) {
94
0
        RETURN_IF_ERROR(Base::_partition_expr_ctxs[i]->clone(
95
0
                state, new_partitioner->_partition_expr_ctxs[i]));
96
0
    }
97
0
    return Status::OK();
98
0
}
Unexecuted instantiation: _ZN5doris10vectorized20Crc32HashPartitionerINS0_17ShuffleChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS0_15PartitionerBaseESt14default_deleteIS7_EE
Unexecuted instantiation: _ZN5doris10vectorized20Crc32HashPartitionerINS0_24SpillPartitionChannelIdsEE5cloneEPNS_12RuntimeStateERSt10unique_ptrINS0_15PartitionerBaseESt14default_deleteIS7_EE
99
100
template class Partitioner<size_t, pipeline::LocalExchangeChannelIds>;
101
template class XXHashPartitioner<pipeline::LocalExchangeChannelIds>;
102
template class Partitioner<size_t, ShuffleChannelIds>;
103
template class XXHashPartitioner<ShuffleChannelIds>;
104
template class Partitioner<uint32_t, ShuffleChannelIds>;
105
template class Crc32HashPartitioner<ShuffleChannelIds>;
106
template class Crc32HashPartitioner<SpillPartitionChannelIds>;
107
108
} // namespace doris::vectorized