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