be/src/exprs/table_function/vexplode_bitmap.cpp
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 | | #include "exprs/table_function/vexplode_bitmap.h" |
19 | | |
20 | | #include <glog/logging.h> |
21 | | |
22 | | #include <memory> |
23 | | #include <ostream> |
24 | | |
25 | | #include "common/status.h" |
26 | | #include "core/block/block.h" |
27 | | #include "core/block/column_with_type_and_name.h" |
28 | | #include "core/column/column.h" |
29 | | #include "core/column/column_nullable.h" |
30 | | #include "core/string_ref.h" |
31 | | #include "core/value/bitmap_value.h" |
32 | | #include "exprs/table_function/table_function.h" |
33 | | #include "exprs/vexpr.h" |
34 | | #include "exprs/vexpr_context.h" |
35 | | |
36 | | namespace doris { |
37 | | #include "common/compile_check_begin.h" |
38 | | |
39 | 0 | VExplodeBitmapTableFunction::VExplodeBitmapTableFunction() { |
40 | 0 | _fn_name = "vexplode_bitmap"; |
41 | 0 | } |
42 | | |
43 | 0 | Status VExplodeBitmapTableFunction::process_init(Block* block, RuntimeState* state) { |
44 | 0 | CHECK(_expr_context->root()->children().size() == 1) |
45 | 0 | << "VExplodeNumbersTableFunction must be have 1 children but have " |
46 | 0 | << _expr_context->root()->children().size(); |
47 | |
|
48 | 0 | RETURN_IF_ERROR(_expr_context->root()->children()[0]->execute_column( |
49 | 0 | _expr_context.get(), block, nullptr, block->rows(), _value_column)); |
50 | | |
51 | 0 | return Status::OK(); |
52 | 0 | } |
53 | | |
54 | 0 | void VExplodeBitmapTableFunction::reset() { |
55 | 0 | _eos = false; |
56 | 0 | _cur_offset = 0; |
57 | 0 | if (!current_empty()) { |
58 | 0 | _cur_iter = std::make_unique<BitmapValueIterator>(*_cur_bitmap); |
59 | 0 | } |
60 | 0 | } |
61 | | |
62 | 0 | void VExplodeBitmapTableFunction::forward(int step) { |
63 | 0 | if (!current_empty()) { |
64 | 0 | for (int i = 0; i < step; i++) { |
65 | 0 | ++(*_cur_iter); |
66 | 0 | } |
67 | 0 | } |
68 | 0 | TableFunction::forward(step); |
69 | 0 | } |
70 | | |
71 | 0 | void VExplodeBitmapTableFunction::get_same_many_values(MutableColumnPtr& column, int length) { |
72 | 0 | if (current_empty()) { |
73 | 0 | column->insert_many_defaults(length); |
74 | 0 | } else { |
75 | 0 | if (_is_nullable) { |
76 | 0 | assert_cast<ColumnInt64*>( |
77 | 0 | assert_cast<ColumnNullable*>(column.get())->get_nested_column_ptr().get()) |
78 | 0 | ->insert_many_vals(**_cur_iter, length); |
79 | 0 | assert_cast<ColumnUInt8*>( |
80 | 0 | assert_cast<ColumnNullable*>(column.get())->get_null_map_column_ptr().get()) |
81 | 0 | ->insert_many_defaults(length); |
82 | 0 | } else { |
83 | 0 | assert_cast<ColumnInt64*>(column.get())->insert_many_vals(**_cur_iter, length); |
84 | 0 | } |
85 | 0 | } |
86 | 0 | } |
87 | | |
88 | 0 | void VExplodeBitmapTableFunction::process_row(size_t row_idx) { |
89 | 0 | TableFunction::process_row(row_idx); |
90 | | //FIXME: use ColumnComplex instead |
91 | 0 | StringRef value = _value_column->get_data_at(row_idx); |
92 | |
|
93 | 0 | if (value.data) { |
94 | 0 | _cur_bitmap = reinterpret_cast<const BitmapValue*>(value.data); |
95 | |
|
96 | 0 | _cur_size = _cur_bitmap->cardinality(); |
97 | 0 | if (!current_empty()) { |
98 | 0 | _cur_iter = std::make_unique<BitmapValueIterator>(*_cur_bitmap); |
99 | 0 | } |
100 | 0 | } |
101 | 0 | } |
102 | | |
103 | 0 | void VExplodeBitmapTableFunction::process_close() { |
104 | 0 | _value_column = nullptr; |
105 | 0 | } |
106 | | |
107 | 0 | int VExplodeBitmapTableFunction::get_value(MutableColumnPtr& column, int max_step) { |
108 | 0 | max_step = std::min(max_step, (int)(_cur_size - _cur_offset)); |
109 | | // should dispose the empty status, forward one step |
110 | 0 | if (current_empty()) { |
111 | 0 | column->insert_default(); |
112 | 0 | max_step = 1; |
113 | 0 | } else { |
114 | 0 | ColumnInt64* target = nullptr; |
115 | 0 | if (_is_nullable) { |
116 | 0 | target = assert_cast<ColumnInt64*>( |
117 | 0 | assert_cast<ColumnNullable*>(column.get())->get_nested_column_ptr().get()); |
118 | 0 | assert_cast<ColumnUInt8*>( |
119 | 0 | assert_cast<ColumnNullable*>(column.get())->get_null_map_column_ptr().get()) |
120 | 0 | ->insert_many_defaults(max_step); |
121 | 0 | } else { |
122 | 0 | target = assert_cast<ColumnInt64*>(column.get()); |
123 | 0 | } |
124 | 0 | auto origin_size = target->size(); |
125 | 0 | target->resize(origin_size + max_step); |
126 | 0 | auto* target_data = target->get_data().data(); |
127 | 0 | for (int i = 0; i < max_step; ++i) { |
128 | 0 | target_data[i + origin_size] = **_cur_iter; |
129 | 0 | ++(*_cur_iter); |
130 | 0 | } |
131 | 0 | } |
132 | 0 | TableFunction::forward(max_step); |
133 | 0 | return max_step; |
134 | 0 | } |
135 | | #include "common/compile_check_end.h" |
136 | | } // namespace doris |