be/src/storage/index/index_writer.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 "common/exception.h" |
19 | | #include "storage/field.h" |
20 | | #include "storage/index/ann/ann_index_writer.h" |
21 | | #include "storage/index/inverted/inverted_index_writer.h" |
22 | | |
23 | | namespace doris::segment_v2 { |
24 | | #include "common/compile_check_begin.h" |
25 | | |
26 | 28.1M | bool IndexColumnWriter::check_support_inverted_index(const TabletColumn& column) { |
27 | | // bellow types are not supported in inverted index for extracted columns |
28 | 28.1M | static std::set<FieldType> invalid_types = {FieldType::OLAP_FIELD_TYPE_JSONB}; |
29 | 28.1M | if (invalid_types.contains(column.type())) { |
30 | 33.5k | return false; |
31 | 33.5k | } |
32 | 28.1M | if (column.is_variant_type()) { |
33 | 19.8k | return false; |
34 | 19.8k | } |
35 | 28.0M | if (column.is_array_type()) { |
36 | | // only support one level array |
37 | 123k | const auto& subcolumn = column.get_sub_column(0); |
38 | 123k | return !subcolumn.is_array_type() && check_support_inverted_index(subcolumn); |
39 | 123k | } |
40 | 27.9M | return true; |
41 | 28.0M | } |
42 | | |
43 | 27.0M | bool IndexColumnWriter::check_support_ann_index(const TabletColumn& column) { |
44 | | // only array are supported in ann index |
45 | 27.0M | return column.is_array_type(); |
46 | 27.0M | } |
47 | | |
48 | | // create index writer |
49 | | Status IndexColumnWriter::create(const StorageField* field, std::unique_ptr<IndexColumnWriter>* res, |
50 | | IndexFileWriter* index_file_writer, |
51 | 38.4k | const TabletIndex* index_meta) { |
52 | 38.4k | const auto* typeinfo = field->type_info(); |
53 | 38.4k | FieldType type = typeinfo->type(); |
54 | 38.4k | std::string field_name; |
55 | 38.4k | auto storage_format = index_file_writer->get_storage_format(); |
56 | 38.4k | if (storage_format == InvertedIndexStorageFormatPB::V1) { |
57 | 571 | field_name = field->name(); |
58 | 37.9k | } else { |
59 | 37.9k | if (field->is_extracted_column()) { |
60 | | // variant sub col |
61 | | // field_name format: parent_unique_id.sub_col_name |
62 | 4.99k | field_name = std::to_string(field->parent_unique_id()) + "." + field->name(); |
63 | 32.9k | } else { |
64 | 32.9k | field_name = std::to_string(field->unique_id()); |
65 | 32.9k | } |
66 | 37.9k | } |
67 | | |
68 | 38.4k | if (index_meta->is_inverted_index()) { |
69 | 38.4k | bool single_field = true; |
70 | 38.4k | if (type == FieldType::OLAP_FIELD_TYPE_ARRAY) { |
71 | 2.52k | const auto* array_typeinfo = dynamic_cast<const ArrayTypeInfo*>(typeinfo); |
72 | 2.52k | DBUG_EXECUTE_IF("InvertedIndexColumnWriter::create_array_typeinfo_is_nullptr", |
73 | 2.52k | { array_typeinfo = nullptr; }) |
74 | 2.52k | if (array_typeinfo != nullptr) { |
75 | 2.52k | typeinfo = array_typeinfo->item_type_info(); |
76 | 2.52k | type = typeinfo->type(); |
77 | 2.52k | single_field = false; |
78 | 2.52k | } else { |
79 | 0 | return Status::NotSupported("unsupported array type for inverted index: " + |
80 | 0 | std::to_string(int(type))); |
81 | 0 | } |
82 | 2.52k | } |
83 | | |
84 | 38.4k | DBUG_EXECUTE_IF("InvertedIndexColumnWriter::create_unsupported_type_for_inverted_index", |
85 | 38.4k | { type = FieldType::OLAP_FIELD_TYPE_JSONB; }) |
86 | 38.4k | switch (type) { |
87 | 0 | #define M(TYPE) \ |
88 | 38.4k | case TYPE: \ |
89 | 38.4k | *res = std::make_unique<InvertedIndexColumnWriter<TYPE>>(field_name, index_file_writer, \ |
90 | 38.4k | index_meta, single_field); \ |
91 | 38.4k | break; |
92 | 349 | M(FieldType::OLAP_FIELD_TYPE_TINYINT) |
93 | 320 | M(FieldType::OLAP_FIELD_TYPE_SMALLINT) |
94 | 6.26k | M(FieldType::OLAP_FIELD_TYPE_INT) |
95 | 0 | M(FieldType::OLAP_FIELD_TYPE_UNSIGNED_INT) |
96 | 3.62k | M(FieldType::OLAP_FIELD_TYPE_BIGINT) |
97 | 470 | M(FieldType::OLAP_FIELD_TYPE_LARGEINT) |
98 | 668 | M(FieldType::OLAP_FIELD_TYPE_CHAR) |
99 | 6.07k | M(FieldType::OLAP_FIELD_TYPE_VARCHAR) |
100 | 8.04k | M(FieldType::OLAP_FIELD_TYPE_STRING) |
101 | 27 | M(FieldType::OLAP_FIELD_TYPE_DATE) |
102 | 27 | M(FieldType::OLAP_FIELD_TYPE_DATETIME) |
103 | 0 | M(FieldType::OLAP_FIELD_TYPE_DECIMAL) |
104 | 4.32k | M(FieldType::OLAP_FIELD_TYPE_DATEV2) |
105 | 2.43k | M(FieldType::OLAP_FIELD_TYPE_DATETIMEV2) |
106 | 3 | M(FieldType::OLAP_FIELD_TYPE_TIMESTAMPTZ) |
107 | 1.38k | M(FieldType::OLAP_FIELD_TYPE_DECIMAL32) |
108 | 656 | M(FieldType::OLAP_FIELD_TYPE_DECIMAL64) |
109 | 469 | M(FieldType::OLAP_FIELD_TYPE_DECIMAL128I) |
110 | 148 | M(FieldType::OLAP_FIELD_TYPE_DECIMAL256) |
111 | 2.94k | M(FieldType::OLAP_FIELD_TYPE_BOOL) |
112 | 101 | M(FieldType::OLAP_FIELD_TYPE_IPV4) |
113 | 115 | M(FieldType::OLAP_FIELD_TYPE_IPV6) |
114 | 0 | M(FieldType::OLAP_FIELD_TYPE_FLOAT) |
115 | 26 | M(FieldType::OLAP_FIELD_TYPE_DOUBLE) |
116 | 0 | #undef M |
117 | 1 | default: |
118 | 1 | return Status::NotSupported("unsupported type for inverted index: " + |
119 | 1 | std::to_string(int(type))); |
120 | 38.4k | } |
121 | 38.4k | if (*res != nullptr) { |
122 | 38.4k | auto st = (*res)->init(); |
123 | 38.4k | if (!st.ok()) { |
124 | 0 | (*res)->close_on_error(); |
125 | 0 | return st; |
126 | 0 | } |
127 | 38.4k | } |
128 | 38.4k | } else if (index_meta->is_ann_index()) { |
129 | 2 | DCHECK(type == FieldType::OLAP_FIELD_TYPE_ARRAY); |
130 | 2 | *res = std ::make_unique<AnnIndexColumnWriter>(index_file_writer, index_meta); |
131 | 2 | if (*res != nullptr) { |
132 | 2 | auto st = (*res)->init(); |
133 | 2 | if (!st.ok()) { |
134 | 0 | (*res)->close_on_error(); |
135 | 0 | return st; |
136 | 0 | } |
137 | 2 | } |
138 | 2 | } |
139 | | |
140 | 38.4k | return Status::OK(); |
141 | 38.4k | } |
142 | | |
143 | | #include "common/compile_check_end.h" |
144 | | } // namespace doris::segment_v2 |