be/src/exec/sink/writer/vhive_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 "core/column/column.h" |
23 | | #include "core/data_type/data_type.h" |
24 | | #include "exec/sink/writer/async_result_writer.h" |
25 | | #include "exprs/vexpr_fwd.h" |
26 | | #include "runtime/runtime_profile.h" |
27 | | |
28 | | namespace doris { |
29 | | |
30 | | class ObjectPool; |
31 | | class RuntimeState; |
32 | | class RuntimeProfile; |
33 | | |
34 | | class Block; |
35 | | class VHivePartitionWriter; |
36 | | struct ColumnWithTypeAndName; |
37 | | |
38 | | class VHiveTableWriter final : public AsyncResultWriter { |
39 | | public: |
40 | | VHiveTableWriter(const TDataSink& t_sink, const VExprContextSPtrs& output_exprs, |
41 | | std::shared_ptr<Dependency> dep, std::shared_ptr<Dependency> fin_dep); |
42 | | |
43 | 0 | ~VHiveTableWriter() override = default; |
44 | | |
45 | | Status init_properties(ObjectPool* pool); |
46 | | |
47 | | Status open(RuntimeState* state, RuntimeProfile* profile) override; |
48 | | |
49 | | Status write(RuntimeState* state, Block& block) override; |
50 | | |
51 | | Status close(Status) override; |
52 | | |
53 | | private: |
54 | | std::shared_ptr<VHivePartitionWriter> _create_partition_writer( |
55 | | Block& block, int position, const std::string* file_name = nullptr, |
56 | | int file_name_index = 0); |
57 | | |
58 | | std::vector<std::string> _create_partition_values(Block& block, int position); |
59 | | |
60 | | std::string _to_partition_value(const DataTypePtr& type_desc, |
61 | | const ColumnWithTypeAndName& partition_column, int position); |
62 | | |
63 | | std::string _compute_file_name(); |
64 | | |
65 | | Status _filter_block(doris::Block& block, const IColumn::Filter* filter, |
66 | | doris::Block* output_block); |
67 | | |
68 | | // Currently it is a copy, maybe it is better to use move semantics to eliminate it. |
69 | | TDataSink _t_sink; |
70 | | RuntimeState* _state = nullptr; |
71 | | std::vector<int> _partition_columns_input_index; |
72 | | std::set<size_t> _non_write_columns_indices; |
73 | | std::unordered_map<std::string, std::shared_ptr<VHivePartitionWriter>> _partitions_to_writers; |
74 | | |
75 | | VExprContextSPtrs _write_output_vexpr_ctxs; |
76 | | |
77 | | size_t _row_count = 0; |
78 | | |
79 | | // profile counters |
80 | | int64_t _send_data_ns = 0; |
81 | | int64_t _partition_writers_dispatch_ns = 0; |
82 | | int64_t _partition_writers_write_ns = 0; |
83 | | int64_t _close_ns = 0; |
84 | | int64_t _write_file_count = 0; |
85 | | |
86 | | RuntimeProfile::Counter* _written_rows_counter = nullptr; |
87 | | RuntimeProfile::Counter* _send_data_timer = nullptr; |
88 | | RuntimeProfile::Counter* _partition_writers_dispatch_timer = nullptr; |
89 | | RuntimeProfile::Counter* _partition_writers_write_timer = nullptr; |
90 | | RuntimeProfile::Counter* _partition_writers_count = nullptr; |
91 | | RuntimeProfile::Counter* _open_timer = nullptr; |
92 | | RuntimeProfile::Counter* _close_timer = nullptr; |
93 | | RuntimeProfile::Counter* _write_file_counter = nullptr; |
94 | | }; |
95 | | } // namespace doris |