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 | | |
25 | 27.7M | bool IndexColumnWriter::check_support_inverted_index(const TabletColumn& column) { |
26 | | // bellow types are not supported in inverted index for extracted columns |
27 | 27.7M | static std::set<FieldType> invalid_types = {FieldType::OLAP_FIELD_TYPE_JSONB}; |
28 | 27.7M | if (invalid_types.contains(column.type())) { |
29 | 38.5k | return false; |
30 | 38.5k | } |
31 | 27.6M | if (column.is_variant_type()) { |
32 | 19.7k | return false; |
33 | 19.7k | } |
34 | 27.6M | if (column.is_array_type()) { |
35 | | // only support one level array |
36 | 113k | const auto& subcolumn = column.get_sub_column(0); |
37 | 113k | return !subcolumn.is_array_type() && check_support_inverted_index(subcolumn); |
38 | 113k | } |
39 | 27.5M | return true; |
40 | 27.6M | } |
41 | | |
42 | 26.7M | bool IndexColumnWriter::check_support_ann_index(const TabletColumn& column) { |
43 | | // only array are supported in ann index |
44 | 26.7M | return column.is_array_type(); |
45 | 26.7M | } |
46 | | |
47 | | // create index writer |
48 | | Status IndexColumnWriter::create(const StorageField* field, std::unique_ptr<IndexColumnWriter>* res, |
49 | | IndexFileWriter* index_file_writer, |
50 | 40.3k | const TabletIndex* index_meta) { |
51 | 40.3k | FieldType type = field->type(); |
52 | 40.3k | std::string field_name; |
53 | 40.3k | auto storage_format = index_file_writer->get_storage_format(); |
54 | 40.3k | if (storage_format == InvertedIndexStorageFormatPB::V1) { |
55 | 583 | field_name = field->name(); |
56 | 39.7k | } else { |
57 | 39.7k | if (field->is_extracted_column()) { |
58 | | // variant sub col |
59 | | // field_name format: parent_unique_id.sub_col_name |
60 | 7.58k | field_name = std::to_string(field->parent_unique_id()) + "." + field->name(); |
61 | 32.1k | } else { |
62 | 32.1k | field_name = std::to_string(field->unique_id()); |
63 | 32.1k | } |
64 | 39.7k | } |
65 | | |
66 | 40.3k | if (index_meta->is_inverted_index()) { |
67 | 40.3k | bool single_field = true; |
68 | 40.3k | if (type == FieldType::OLAP_FIELD_TYPE_ARRAY) { |
69 | 1.78k | const auto& column = field->get_desc(); |
70 | 1.78k | bool has_item_subcolumn = column.get_subtype_count() > 0; |
71 | 1.78k | DBUG_EXECUTE_IF("InvertedIndexColumnWriter::create_array_typeinfo_is_nullptr", |
72 | 1.78k | { has_item_subcolumn = false; }) |
73 | 1.78k | if (has_item_subcolumn) { |
74 | 1.78k | type = column.get_sub_column(0).type(); |
75 | 1.78k | single_field = false; |
76 | 1.78k | } else { |
77 | 0 | return Status::NotSupported("unsupported array type for inverted index: " + |
78 | 0 | std::to_string(int(type))); |
79 | 0 | } |
80 | 1.78k | } |
81 | | |
82 | 40.3k | DBUG_EXECUTE_IF("InvertedIndexColumnWriter::create_unsupported_type_for_inverted_index", |
83 | 40.3k | { type = FieldType::OLAP_FIELD_TYPE_JSONB; }) |
84 | 40.3k | switch (type) { |
85 | 0 | #define M(TYPE) \ |
86 | 40.3k | case TYPE: \ |
87 | 40.3k | *res = std::make_unique<InvertedIndexColumnWriter<TYPE>>(field_name, index_file_writer, \ |
88 | 40.3k | index_meta, single_field); \ |
89 | 40.3k | break; |
90 | 300 | M(FieldType::OLAP_FIELD_TYPE_TINYINT) |
91 | 271 | M(FieldType::OLAP_FIELD_TYPE_SMALLINT) |
92 | 6.31k | M(FieldType::OLAP_FIELD_TYPE_INT) |
93 | 0 | M(FieldType::OLAP_FIELD_TYPE_UNSIGNED_INT) |
94 | 4.24k | M(FieldType::OLAP_FIELD_TYPE_BIGINT) |
95 | 431 | M(FieldType::OLAP_FIELD_TYPE_LARGEINT) |
96 | 634 | M(FieldType::OLAP_FIELD_TYPE_CHAR) |
97 | 6.03k | M(FieldType::OLAP_FIELD_TYPE_VARCHAR) |
98 | 9.88k | M(FieldType::OLAP_FIELD_TYPE_STRING) |
99 | 28 | M(FieldType::OLAP_FIELD_TYPE_DATE) |
100 | 28 | M(FieldType::OLAP_FIELD_TYPE_DATETIME) |
101 | 1 | M(FieldType::OLAP_FIELD_TYPE_DECIMAL) |
102 | 4.26k | M(FieldType::OLAP_FIELD_TYPE_DATEV2) |
103 | 2.29k | M(FieldType::OLAP_FIELD_TYPE_DATETIMEV2) |
104 | 4 | M(FieldType::OLAP_FIELD_TYPE_TIMESTAMPTZ) |
105 | 1.30k | M(FieldType::OLAP_FIELD_TYPE_DECIMAL32) |
106 | 578 | M(FieldType::OLAP_FIELD_TYPE_DECIMAL64) |
107 | 424 | M(FieldType::OLAP_FIELD_TYPE_DECIMAL128I) |
108 | 149 | M(FieldType::OLAP_FIELD_TYPE_DECIMAL256) |
109 | 2.94k | M(FieldType::OLAP_FIELD_TYPE_BOOL) |
110 | 102 | M(FieldType::OLAP_FIELD_TYPE_IPV4) |
111 | 115 | M(FieldType::OLAP_FIELD_TYPE_IPV6) |
112 | 1 | M(FieldType::OLAP_FIELD_TYPE_FLOAT) |
113 | 27 | M(FieldType::OLAP_FIELD_TYPE_DOUBLE) |
114 | 0 | #undef M |
115 | 1 | default: |
116 | 1 | return Status::NotSupported("unsupported type for inverted index: " + |
117 | 1 | std::to_string(int(type))); |
118 | 40.3k | } |
119 | 40.3k | if (*res != nullptr) { |
120 | 40.3k | auto st = (*res)->init(); |
121 | 40.3k | if (!st.ok()) { |
122 | 0 | (*res)->close_on_error(); |
123 | 0 | return st; |
124 | 0 | } |
125 | 40.3k | } |
126 | 40.3k | } else if (index_meta->is_ann_index()) { |
127 | 2 | DCHECK(type == FieldType::OLAP_FIELD_TYPE_ARRAY); |
128 | 2 | *res = std ::make_unique<AnnIndexColumnWriter>(index_file_writer, index_meta); |
129 | 2 | if (*res != nullptr) { |
130 | 2 | auto st = (*res)->init(); |
131 | 2 | if (!st.ok()) { |
132 | 0 | (*res)->close_on_error(); |
133 | 0 | return st; |
134 | 0 | } |
135 | 2 | } |
136 | 2 | } |
137 | | |
138 | 40.3k | return Status::OK(); |
139 | 40.3k | } |
140 | | |
141 | | } // namespace doris::segment_v2 |