be/src/exec/sink/vtablet_block_convertor.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 | | #include <stddef.h> |
20 | | #include <stdint.h> |
21 | | |
22 | | // IWYU pragma: no_include <bits/chrono.h> |
23 | | |
24 | | #include <chrono> // IWYU pragma: keep |
25 | | #include <map> |
26 | | |
27 | | #include "common/status.h" |
28 | | #include "core/block/block.h" |
29 | | #include "core/column/column.h" |
30 | | #include "core/data_type/data_type_factory.hpp" |
31 | | #include "core/value/decimalv2_value.h" |
32 | | #include "exec/sink/autoinc_buffer.h" |
33 | | #include "exprs/vexpr_fwd.h" |
34 | | #include "runtime/descriptors.h" |
35 | | #include "util/bitmap.h" |
36 | | |
37 | | namespace doris { |
38 | | #include "common/compile_check_begin.h" |
39 | | |
40 | | class OlapTableBlockConvertor { |
41 | | public: |
42 | | OlapTableBlockConvertor(TupleDescriptor* output_tuple_desc) |
43 | 8 | : _output_tuple_desc(output_tuple_desc) {} |
44 | | |
45 | | Status validate_and_convert_block(RuntimeState* state, Block* input_block, |
46 | | std::shared_ptr<Block>& block, |
47 | | VExprContextSPtrs output_vexpr_ctxs, size_t rows, |
48 | | bool& has_filtered_rows); |
49 | | |
50 | 0 | const char* filter_map() const { return _filter_map.data(); } |
51 | | |
52 | 0 | int64_t validate_data_ns() const { return _validate_data_ns; } |
53 | | |
54 | 0 | int64_t num_filtered_rows() const { return _num_filtered_rows; } |
55 | | |
56 | | void init_autoinc_info(int64_t db_id, int64_t table_id, int batch_size, |
57 | | bool is_partial_update_and_auto_inc = false, |
58 | | int32_t auto_increment_column_unique_id = -1); |
59 | | |
60 | 0 | AutoIncIDAllocator& auto_inc_id_allocator() { return _auto_inc_id_allocator; } |
61 | | |
62 | | private: |
63 | | template <bool is_min> |
64 | | DecimalV2Value _get_decimalv2_min_or_max(const DataTypePtr& type); |
65 | | |
66 | | template <typename DecimalType, bool IsMin> |
67 | | DecimalType _get_decimalv3_min_or_max(const DataTypePtr& type); |
68 | | |
69 | | Status _validate_column(RuntimeState* state, Block* block, const DataTypePtr& type, |
70 | | ColumnPtr column, size_t slot_index, fmt::memory_buffer& error_prefix, |
71 | 9 | const size_t row_count, IColumn::Permutation* rows = nullptr) { |
72 | 9 | RETURN_IF_CATCH_EXCEPTION({ |
73 | 9 | return _internal_validate_column(state, block, type, column, slot_index, error_prefix, |
74 | 9 | row_count, rows); |
75 | 9 | }); |
76 | 9 | } |
77 | | |
78 | | Status _internal_validate_column(RuntimeState* state, Block* block, const DataTypePtr& type, |
79 | | ColumnPtr column, size_t slot_index, |
80 | | fmt::memory_buffer& error_prefix, const size_t row_count, |
81 | | IColumn::Permutation* rows = nullptr); |
82 | | |
83 | | // make input data valid for OLAP table |
84 | | // return number of invalid/filtered rows. |
85 | | // invalid row number is set in Bitmap |
86 | | Status _validate_data(RuntimeState* state, Block* block, const size_t rows, int& filtered_rows); |
87 | | |
88 | | // some output column of output expr may have different nullable property with dest slot desc |
89 | | // so here need to do the convert operation |
90 | | void _convert_to_dest_desc_block(Block* block); |
91 | | |
92 | | Status _fill_auto_inc_cols(Block* block, size_t rows); |
93 | | |
94 | | Status _partial_update_fill_auto_inc_cols(Block* block, size_t rows); |
95 | | |
96 | | TupleDescriptor* _output_tuple_desc = nullptr; |
97 | | |
98 | | std::map<std::pair<int, int>, DecimalV2Value> _max_decimalv2_val; |
99 | | std::map<std::pair<int, int>, DecimalV2Value> _min_decimalv2_val; |
100 | | |
101 | | std::map<int, int32_t> _max_decimal32_val; |
102 | | std::map<int, int32_t> _min_decimal32_val; |
103 | | std::map<int, int64_t> _max_decimal64_val; |
104 | | std::map<int, int64_t> _min_decimal64_val; |
105 | | std::map<int, int128_t> _max_decimal128_val; |
106 | | std::map<int, int128_t> _min_decimal128_val; |
107 | | std::map<int, wide::Int256> _max_decimal256_val; |
108 | | std::map<int, wide::Int256> _min_decimal256_val; |
109 | | |
110 | | std::vector<char> _filter_map; |
111 | | |
112 | | int64_t _validate_data_ns = 0; |
113 | | int64_t _num_filtered_rows = 0; |
114 | | |
115 | | size_t _batch_size; |
116 | | std::optional<size_t> _auto_inc_col_idx; |
117 | | std::shared_ptr<AutoIncIDBuffer> _auto_inc_id_buffer = nullptr; |
118 | | AutoIncIDAllocator _auto_inc_id_allocator; |
119 | | bool _is_partial_update_and_auto_inc = false; |
120 | | }; |
121 | | |
122 | | } // namespace doris |
123 | | #include "common/compile_check_end.h" |