Coverage Report

Created: 2026-03-12 14:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exec/exchange/exchange_writer.h
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
#pragma once
19
20
#include <cstdint>
21
22
#include "exec/exchange/vdata_stream_sender.h"
23
#include "exec/partitioner/partitioner.h"
24
25
namespace doris {
26
class RuntimeState;
27
class Status;
28
class Block;
29
class Channel;
30
class PartitionerBase;
31
class TabletSinkHashPartitioner;
32
33
#include "common/compile_check_begin.h"
34
class ExchangeSinkLocalState;
35
36
class ExchangeWriterBase {
37
public:
38
    using HashValType = PartitionerBase::HashValType;
39
    ExchangeWriterBase(ExchangeSinkLocalState& local_state);
40
41
    virtual Status write(RuntimeState* state, Block* block, bool eos) = 0;
42
43
149k
    virtual ~ExchangeWriterBase() = default;
44
45
protected:
46
    template <typename ChannelPtrType>
47
    Status _handle_eof_channel(RuntimeState* state, ChannelPtrType channel, Status st) const;
48
    Status _add_rows_impl(RuntimeState* state, std::vector<std::shared_ptr<Channel>>& channels,
49
                          size_t channel_count, Block* block, bool eos);
50
51
    // myself as a visitor of local state
52
    ExchangeSinkLocalState& _local_state;
53
    PartitionerBase* _partitioner;
54
55
    // _origin_row_idx[i]: row id in original block for the i-th's data we send.
56
    PaddedPODArray<uint32_t> _origin_row_idx;
57
    // _channel_rows_histogram[i]: number of rows for channel i in current batch
58
    PaddedPODArray<uint32_t> _channel_rows_histogram;
59
    // _channel_start_offsets[i]: the start offset of channel i in _row_idx
60
    // its value equals to prefix sum of _channel_rows_histogram
61
    // after calculation, it will be end offset for channel i.
62
    PaddedPODArray<uint32_t> _channel_pos_offsets;
63
};
64
65
class ExchangeTrivialWriter final : public ExchangeWriterBase {
66
public:
67
148k
    ExchangeTrivialWriter(ExchangeSinkLocalState& local_state) : ExchangeWriterBase(local_state) {}
68
69
    Status write(RuntimeState* state, Block* block, bool eos) override;
70
71
private:
72
    Status _channel_add_rows(RuntimeState* state, std::vector<std::shared_ptr<Channel>>& channels,
73
                             size_t channel_count, const std::vector<HashValType>& channel_ids,
74
                             size_t rows, Block* block, bool eos);
75
};
76
77
// maybe auto partition
78
class ExchangeOlapWriter final : public ExchangeWriterBase {
79
public:
80
307
    ExchangeOlapWriter(ExchangeSinkLocalState& local_state) : ExchangeWriterBase(local_state) {}
81
82
    Status write(RuntimeState* state, Block* block, bool eos) override;
83
84
private:
85
    Status _write_impl(RuntimeState* state, Block* block, bool eos = false);
86
    Status _channel_add_rows(RuntimeState* state, std::vector<std::shared_ptr<Channel>>& channels,
87
                             size_t channel_count, const std::vector<HashValType>& channel_ids,
88
                             size_t rows, Block* block, bool eos, HashValType invalid_val);
89
};
90
#include "common/compile_check_end.h"
91
} // namespace doris