be/src/exec/sink/writer/vtvf_table_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 <gen_cpp/DataSinks_types.h> |
21 | | |
22 | | #include <memory> |
23 | | #include <string> |
24 | | |
25 | | #include "common/status.h" |
26 | | #include "exec/sink/writer/async_result_writer.h" |
27 | | #include "exprs/vexpr_fwd.h" |
28 | | #include "format/transformer/vfile_format_transformer.h" |
29 | | #include "format/transformer/vfile_format_transformer_factory.h" |
30 | | #include "io/fs/file_writer.h" |
31 | | #include "runtime/runtime_profile.h" |
32 | | |
33 | | namespace doris { |
34 | | class RuntimeState; |
35 | | class RuntimeProfile; |
36 | | |
37 | | class Block; |
38 | | |
39 | | /** |
40 | | * VTVFTableWriter writes query result blocks to files (local/s3/hdfs) |
41 | | * via the TVF sink path: INSERT INTO tvf_name(properties) SELECT ... |
42 | | * |
43 | | * It inherits from AsyncResultWriter to perform IO in a separate thread pool, |
44 | | * avoiding blocking the pipeline execution engine. |
45 | | */ |
46 | | class VTVFTableWriter final : public AsyncResultWriter { |
47 | | public: |
48 | | VTVFTableWriter(const TDataSink& t_sink, const VExprContextSPtrs& output_exprs, |
49 | | std::shared_ptr<Dependency> dep, std::shared_ptr<Dependency> fin_dep); |
50 | | |
51 | 0 | ~VTVFTableWriter() override = default; |
52 | | |
53 | | Status open(RuntimeState* state, RuntimeProfile* profile) override; |
54 | | |
55 | | Status write(RuntimeState* state, Block& block) override; |
56 | | |
57 | | Status close(Status status) override; |
58 | | |
59 | | private: |
60 | | Status _create_file_writer(const std::string& file_name); |
61 | | Status _create_next_file_writer(); |
62 | | Status _close_file_writer(bool done); |
63 | | Status _create_new_file_if_exceed_size(); |
64 | | Status _get_next_file_name(std::string* file_name); |
65 | | |
66 | | TTVFTableSink _tvf_sink; |
67 | | RuntimeState* _state = nullptr; |
68 | | |
69 | | std::unique_ptr<doris::io::FileWriter> _file_writer_impl; |
70 | | std::unique_ptr<VFileFormatTransformer> _vfile_writer; |
71 | | |
72 | | int64_t _current_written_bytes = 0; |
73 | | int64_t _max_file_size_bytes = 0; |
74 | | int _file_idx = 0; |
75 | | std::string _file_path; |
76 | | |
77 | | // profile counters |
78 | | RuntimeProfile::Counter* _written_rows_counter = nullptr; |
79 | | RuntimeProfile::Counter* _written_data_bytes = nullptr; |
80 | | RuntimeProfile::Counter* _file_write_timer = nullptr; |
81 | | RuntimeProfile::Counter* _writer_close_timer = nullptr; |
82 | | }; |
83 | | |
84 | | } // namespace doris |