-
Notifications
You must be signed in to change notification settings - Fork 419
Expand file tree
/
Copy pathColumnarReadSourceOp.h
More file actions
107 lines (83 loc) · 3.5 KB
/
Copy pathColumnarReadSourceOp.h
File metadata and controls
107 lines (83 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2023 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <Common/config.h> // for ENABLE_NEXT_GEN_COLUMNAR
#if ENABLE_NEXT_GEN_COLUMNAR
#include <Common/Logger.h>
#include <Common/Stopwatch.h>
#include <DataStreams/AddExtraTableIDColumnTransformAction.h>
#include <Operators/Operator.h>
#include <Storages/StorageDisaggregatedColumnar.h>
#include <optional>
namespace DB
{
/// Explicit state machine for ColumnarReadSourceOp.
/// It owns reader works and emits deserialized blocks to a downstream SharedQueueSinkOp.
enum class ColumnarReadSourceState : uint8_t
{
NEED_READER, // No current reader work; awaitImpl will acquire one.
WAIT_READER, // Compatibility state for a reader work that is Creating; pipeline still returns IO_IN.
READING, // Reader is ready and input stream created; ready to read a block.
READY_BLOCK, // t_block has a cached block for downstream.
DONE, // All reader works consumed.
};
class ColumnarReadSourceOp : public SourceOp
{
static constexpr auto NAME = "RNProxy";
public:
struct Options
{
PipelineExecutorContext & exec_context;
RNColumnarReadTaskPtr task;
};
explicit ColumnarReadSourceOp(const Options & options)
: SourceOp(options.exec_context, options.task->getLog()->identifier())
, context(options.task->getContext())
, log(options.task->getLog())
, task(options.task)
{
setHeader(AddExtraTableIDColumnTransformAction::buildHeader(
options.task->getColumnsToRead(),
options.task->getExtraTableIDIndex()));
}
static SourceOpPtr create(const Options & options) { return std::make_unique<ColumnarReadSourceOp>(options); }
String getName() const override { return NAME; }
IOProfileInfoPtr getIOProfileInfo() const override { return IOProfileInfo::createForLocal(profile_info_ptr); }
protected:
void operateSuffixImpl() override;
void operatePrefixImpl() override;
OperatorStatus readImpl(Block & block) override;
OperatorStatus awaitImpl() override;
OperatorStatus executeIOImpl() override;
private:
/// Create an input stream from an already-materialized reader, then transition to READING.
void consumeReadyReader(ColumnarReaderPtr reader);
const Context & context;
const LoggerPtr log;
RNColumnarReadTaskPtr task;
UInt64 total_bytes = 0;
size_t total_rows = 0;
size_t total_streams = 0;
BlockInputStreamPtr current_input_stream;
// IO work caches one block here so the next CPU-side readImpl can push it into SharedQueueSinkOp.
std::optional<Block> t_block = std::nullopt;
// The reader work currently being consumed by this producer source.
RNColumnarReaderWorkPtr current_reader_work;
ColumnarReadSourceState state = ColumnarReadSourceState::NEED_READER;
Stopwatch total_cost_watch{CLOCK_MONOTONIC_COARSE};
// Count the time consumed by reading blocks in the stream of reader works.
double duration_read_sec = 0;
};
} // namespace DB
#endif