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 | | class ExchangeSinkLocalState; |
34 | | |
35 | | class ExchangeWriterBase { |
36 | | public: |
37 | | using HashValType = PartitionerBase::HashValType; |
38 | | ExchangeWriterBase(ExchangeSinkLocalState& local_state); |
39 | | |
40 | | virtual Status write(RuntimeState* state, Block* block, bool eos) = 0; |
41 | | |
42 | 645k | virtual ~ExchangeWriterBase() = default; |
43 | | |
44 | | protected: |
45 | | template <typename ChannelPtrType> |
46 | | Status _handle_eof_channel(RuntimeState* state, ChannelPtrType channel, Status st) const; |
47 | | Status _add_rows_impl(RuntimeState* state, std::vector<std::shared_ptr<Channel>>& channels, |
48 | | size_t channel_count, Block* block, bool eos); |
49 | | |
50 | | // myself as a visitor of local state |
51 | | ExchangeSinkLocalState& _local_state; |
52 | | PartitionerBase* _partitioner; |
53 | | |
54 | | // _origin_row_idx[i]: row id in original block for the i-th's data we send. |
55 | | PaddedPODArray<uint32_t> _origin_row_idx; |
56 | | // _channel_rows_histogram[i]: number of rows for channel i in current batch |
57 | | PaddedPODArray<uint32_t> _channel_rows_histogram; |
58 | | // _channel_start_offsets[i]: the start offset of channel i in _row_idx |
59 | | // its value equals to prefix sum of _channel_rows_histogram |
60 | | // after calculation, it will be end offset for channel i. |
61 | | PaddedPODArray<uint32_t> _channel_pos_offsets; |
62 | | }; |
63 | | |
64 | | class ExchangeTrivialWriter final : public ExchangeWriterBase { |
65 | | public: |
66 | 643k | ExchangeTrivialWriter(ExchangeSinkLocalState& local_state) : ExchangeWriterBase(local_state) {} |
67 | | |
68 | | Status write(RuntimeState* state, Block* block, bool eos) override; |
69 | | |
70 | | private: |
71 | | Status _channel_add_rows(RuntimeState* state, std::vector<std::shared_ptr<Channel>>& channels, |
72 | | size_t channel_count, const std::vector<HashValType>& channel_ids, |
73 | | size_t rows, Block* block, bool eos); |
74 | | }; |
75 | | |
76 | | // maybe auto partition |
77 | | class ExchangeOlapWriter final : public ExchangeWriterBase { |
78 | | public: |
79 | 435 | ExchangeOlapWriter(ExchangeSinkLocalState& local_state) : ExchangeWriterBase(local_state) {} |
80 | | |
81 | | Status write(RuntimeState* state, Block* block, bool eos) override; |
82 | | |
83 | | private: |
84 | | Status _write_impl(RuntimeState* state, Block* block, bool eos = false); |
85 | | Status _channel_add_rows(RuntimeState* state, std::vector<std::shared_ptr<Channel>>& channels, |
86 | | size_t channel_count, const std::vector<HashValType>& channel_ids, |
87 | | size_t rows, Block* block, bool eos, HashValType invalid_val); |
88 | | }; |
89 | | } // namespace doris |