be/src/exec/operator/mock_operator.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 <list> |
21 | | |
22 | | #include "core/block/block.h" |
23 | | #include "exec/operator/operator.h" |
24 | | |
25 | | namespace doris { |
26 | | |
27 | | #ifdef BE_TEST |
28 | | class MockLocalState final : public doris::PipelineXLocalState<FakeSharedState> { |
29 | | public: |
30 | | using Base = doris::PipelineXLocalState<FakeSharedState>; |
31 | | ENABLE_FACTORY_CREATOR(MockLocalState); |
32 | | |
33 | 3 | MockLocalState(RuntimeState* state, OperatorXBase* parent) : Base(state, parent) {} |
34 | 3 | ~MockLocalState() override = default; |
35 | | |
36 | | private: |
37 | | friend class MockOperatorX; |
38 | | }; |
39 | | |
40 | | class MockOperatorX final : public OperatorX<MockLocalState> { |
41 | | public: |
42 | | ENABLE_FACTORY_CREATOR(MockOperatorX); |
43 | 16 | MockOperatorX() = default; |
44 | | |
45 | 6 | Status get_block(RuntimeState* state, Block* block, bool* eos) override { |
46 | 6 | if (_outout_blocks.empty()) { |
47 | 0 | *eos = true; |
48 | 0 | return Status::OK(); |
49 | 0 | } |
50 | | |
51 | 6 | *eos = false; |
52 | 6 | block->swap(_outout_blocks.front()); |
53 | 6 | _outout_blocks.pop_front(); |
54 | 6 | if (_outout_blocks.empty()) { |
55 | 5 | *eos = true; |
56 | 5 | } |
57 | 6 | return Status::OK(); |
58 | 6 | } |
59 | | |
60 | 7 | [[nodiscard]] bool is_source() const override { return true; } |
61 | | friend class MockLocalState; |
62 | | std::list<Block> _outout_blocks; |
63 | | }; |
64 | | |
65 | | #endif |
66 | | |
67 | | } // namespace doris |