be/src/exprs/function/dictionary_util.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 "core/block/columns_with_type_and_name.h" |
21 | | #include "util/simd/bits.h" |
22 | | |
23 | | namespace doris { |
24 | | /* |
25 | | If skip_null_key is false |
26 | | Check if there are null values in the columns of key_data, if so, return an error |
27 | | If there are no null values, convert the columns in key_data to non-nullable columns |
28 | | If skip_null_key is true |
29 | | Skip the rows where the key contains null |
30 | | Finally, convert the columns in key_data to non-nullable columns |
31 | | */ |
32 | | Status inline check_dict_input_data(ColumnsWithTypeAndName& key_data, |
33 | 6 | ColumnsWithTypeAndName& value_data, bool skip_null_key) { |
34 | 6 | if (!skip_null_key) { |
35 | 5 | for (auto& key : key_data) { |
36 | 5 | if (key.column->has_null()) { |
37 | 1 | return Status::InternalError("key column {} has null value", key.name); |
38 | 1 | } |
39 | 4 | key.column = remove_nullable(key.column); |
40 | 4 | } |
41 | 2 | return Status::OK(); |
42 | 3 | } |
43 | 3 | IColumn::Filter filter(key_data.front().column->size(), 1); |
44 | | |
45 | 6 | for (auto& key : key_data) { |
46 | 6 | if (key.column->is_nullable()) { |
47 | 4 | const auto& null_map = assert_cast<const ColumnNullable*>(key.column.get()) |
48 | 4 | ->get_null_map_data(); // Get the null_map in the key |
49 | 24 | for (size_t i = 0; i < key.column->size(); ++i) { |
50 | 20 | if (null_map[i] == 1) { |
51 | | // If the value in the null_map of the key is 0, filter it out |
52 | 6 | filter[i] = 0; |
53 | 6 | } |
54 | 20 | } |
55 | 4 | } |
56 | 6 | key.column = remove_nullable(key.column); |
57 | 6 | } |
58 | 3 | const size_t count = |
59 | 3 | filter.size() - simd::count_zero_num((int8_t*)filter.data(), filter.size()); |
60 | | // Similar to the filter_block_internal function in block.cpp |
61 | 12 | auto filter_column = [&](ColumnPtr& column) { |
62 | 12 | if (column->is_exclusive()) { |
63 | 12 | column->assume_mutable()->filter(filter); |
64 | 12 | } else { |
65 | 0 | column = column->filter(filter, count); |
66 | 0 | } |
67 | 12 | }; |
68 | | |
69 | 6 | for (auto& key : key_data) { |
70 | 6 | filter_column(key.column); |
71 | 6 | } |
72 | 6 | for (auto& value : value_data) { |
73 | 6 | filter_column(value.column); |
74 | 6 | } |
75 | 3 | return Status::OK(); |
76 | 6 | } |
77 | | |
78 | | } // namespace doris |