be/src/exec/scan/access_path_parser.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 "exec/scan/access_path_parser.h" |
19 | | |
20 | | #include <fmt/format.h> |
21 | | |
22 | | #include <algorithm> |
23 | | #include <charconv> |
24 | | #include <map> |
25 | | #include <string> |
26 | | #include <string_view> |
27 | | #include <utility> |
28 | | |
29 | | #include "common/cast_set.h" |
30 | | #include "common/consts.h" |
31 | | #include "core/assert_cast.h" |
32 | | #include "core/data_type/data_type.h" |
33 | | #include "core/data_type/data_type_array.h" |
34 | | #include "core/data_type/data_type_map.h" |
35 | | #include "core/data_type/data_type_nullable.h" |
36 | | #include "core/data_type/data_type_struct.h" |
37 | | #include "runtime/descriptors.h" |
38 | | #include "util/string_util.h" |
39 | | |
40 | | namespace doris { |
41 | | namespace { |
42 | | |
43 | 33 | bool is_scanner_materialized_virtual_column(const std::string& column_name) { |
44 | 33 | return column_name == BeConsts::ICEBERG_ROWID_COL; |
45 | 33 | } |
46 | | |
47 | 28 | bool parse_non_negative_int(std::string_view value, int32_t* result) { |
48 | 28 | DORIS_CHECK(result != nullptr); |
49 | 28 | int32_t parsed = -1; |
50 | 28 | const auto* begin = value.data(); |
51 | 28 | const auto* end = begin + value.size(); |
52 | 28 | const auto [ptr, ec] = std::from_chars(begin, end, parsed); |
53 | 28 | if (ec != std::errc() || ptr != end || parsed < 0) { |
54 | 25 | return false; |
55 | 25 | } |
56 | 3 | *result = parsed; |
57 | 3 | return true; |
58 | 28 | } |
59 | | |
60 | 2 | std::string access_path_to_string(const std::vector<std::string>& path) { |
61 | 2 | return fmt::format("{}", fmt::join(path, ".")); |
62 | 2 | } |
63 | | |
64 | | format::ColumnDefinition* find_or_add_child(format::ColumnDefinition* parent, int32_t id, |
65 | 37 | std::string name, DataTypePtr type) { |
66 | 37 | DORIS_CHECK(parent != nullptr); |
67 | 37 | for (auto& child : parent->children) { |
68 | 14 | if ((child.has_identifier_field_id() && child.get_identifier_field_id() == id) || |
69 | 14 | child.name == name) { |
70 | 0 | return &child; |
71 | 0 | } |
72 | 14 | } |
73 | 37 | parent->children.push_back({ |
74 | 37 | .identifier = Field::create_field<TYPE_INT>(id), |
75 | 37 | .name = std::move(name), |
76 | 37 | .type = std::move(type), |
77 | 37 | .children = {}, |
78 | 37 | .default_expr = nullptr, |
79 | 37 | .is_partition_key = false, |
80 | 37 | }); |
81 | 37 | return &parent->children.back(); |
82 | 37 | } |
83 | | |
84 | | void inherit_schema_metadata(format::ColumnDefinition* column, |
85 | 37 | const format::ColumnDefinition* schema_column) { |
86 | 37 | if (column == nullptr || schema_column == nullptr) { |
87 | 1 | return; |
88 | 1 | } |
89 | 36 | column->name_mapping = schema_column->name_mapping; |
90 | | // The presence bit is part of the mapping contract: an explicit empty mapping must remain |
91 | | // authoritative after access-path pruning instead of enabling current-name fallback. |
92 | 36 | column->has_name_mapping = schema_column->has_name_mapping; |
93 | | // Initial defaults describe the logical value of fields absent from older files. Nested |
94 | | // access-path pruning must retain them just like it retains rename metadata. |
95 | 36 | column->initial_default_value = schema_column->initial_default_value; |
96 | 36 | column->initial_default_value_is_base64 = schema_column->initial_default_value_is_base64; |
97 | 36 | } |
98 | | |
99 | | const format::ColumnDefinition* find_schema_child_by_path( |
100 | | const format::ColumnDefinition* schema_column, const std::string& child_path, |
101 | 26 | bool prefer_exact_name_match) { |
102 | 26 | if (schema_column == nullptr) { |
103 | 1 | return nullptr; |
104 | 1 | } |
105 | 25 | int32_t parsed_field_id = -1; |
106 | 25 | if (parse_non_negative_int(child_path, &parsed_field_id)) { |
107 | 1 | const auto child_it = std::ranges::find_if( |
108 | 2 | schema_column->children, [&](const format::ColumnDefinition& child) { |
109 | 2 | return child.has_identifier_field_id() && |
110 | 2 | child.get_identifier_field_id() == parsed_field_id; |
111 | 2 | }); |
112 | 1 | return child_it == schema_column->children.end() ? nullptr : &*child_it; |
113 | 1 | } |
114 | 24 | if (!prefer_exact_name_match) { |
115 | 1 | const auto child_it = std::ranges::find_if(schema_column->children, [&](const auto& child) { |
116 | 1 | if (to_lower(child.name) == to_lower(child_path)) { |
117 | 0 | return true; |
118 | 0 | } |
119 | 1 | return std::ranges::any_of(child.name_mapping, [&](const std::string& alias) { |
120 | 1 | return to_lower(alias) == to_lower(child_path); |
121 | 1 | }); |
122 | 1 | }); |
123 | 1 | return child_it == schema_column->children.end() ? nullptr : &*child_it; |
124 | 1 | } |
125 | | // Iceberg can reuse a historical name for a newly added sibling. Current names therefore |
126 | | // have precedence across the entire struct; an earlier alias must not steal that access path. |
127 | 45 | const auto exact_it = std::ranges::find_if(schema_column->children, [&](const auto& child) { |
128 | 45 | return to_lower(child.name) == to_lower(child_path); |
129 | 45 | }); |
130 | 23 | if (exact_it != schema_column->children.end()) { |
131 | 17 | return &*exact_it; |
132 | 17 | } |
133 | 11 | const auto alias_it = std::ranges::find_if(schema_column->children, [&](const auto& child) { |
134 | 11 | return std::ranges::any_of(child.name_mapping, [&](const std::string& alias) { |
135 | 6 | return to_lower(alias) == to_lower(child_path); |
136 | 6 | }); |
137 | 11 | }); |
138 | 6 | return alias_it == schema_column->children.end() ? nullptr : &*alias_it; |
139 | 23 | } |
140 | | |
141 | 40 | int32_t schema_field_id(const format::ColumnDefinition* schema_column) { |
142 | 40 | if (schema_column == nullptr || !schema_column->has_identifier_field_id()) { |
143 | 4 | return -1; |
144 | 4 | } |
145 | 36 | return schema_column->get_identifier_field_id(); |
146 | 40 | } |
147 | | |
148 | 24 | int32_t schema_field_id_or(const format::ColumnDefinition* schema_column, int32_t fallback) { |
149 | 24 | const auto field_id = schema_field_id(schema_column); |
150 | 24 | return field_id >= 0 ? field_id : fallback; |
151 | 24 | } |
152 | | |
153 | | std::string schema_field_name_or(const format::ColumnDefinition* schema_column, |
154 | 10 | std::string fallback) { |
155 | 10 | return schema_column == nullptr || schema_column->name.empty() ? std::move(fallback) |
156 | 10 | : schema_column->name; |
157 | 10 | } |
158 | | |
159 | | struct AccessPathNode { |
160 | | bool project_all = false; |
161 | | std::map<std::string, AccessPathNode> children; |
162 | | }; |
163 | | |
164 | 9 | void merge_access_path_node(AccessPathNode* dst, const AccessPathNode& src) { |
165 | 9 | DORIS_CHECK(dst != nullptr); |
166 | 9 | if (dst->project_all) { |
167 | 0 | return; |
168 | 0 | } |
169 | 9 | if (src.project_all) { |
170 | 5 | dst->project_all = true; |
171 | 5 | dst->children.clear(); |
172 | 5 | return; |
173 | 5 | } |
174 | 4 | for (const auto& [path, child] : src.children) { |
175 | 4 | merge_access_path_node(&dst->children[path], child); |
176 | 4 | } |
177 | 4 | } |
178 | | |
179 | | void insert_access_path(AccessPathNode* root, const std::vector<std::string>& path, |
180 | 60 | size_t path_idx) { |
181 | 60 | DORIS_CHECK(root != nullptr); |
182 | 60 | if (root->project_all) { |
183 | 0 | return; |
184 | 0 | } |
185 | 60 | if (path_idx >= path.size()) { |
186 | 28 | root->project_all = true; |
187 | 28 | root->children.clear(); |
188 | 28 | return; |
189 | 28 | } |
190 | 32 | insert_access_path(&root->children[path[path_idx]], path, path_idx + 1); |
191 | 32 | } |
192 | | |
193 | | Status build_nested_children_from_access_node(format::ColumnDefinition* column, |
194 | | const DataTypePtr& type, const AccessPathNode& node, |
195 | | const std::string& path, |
196 | | const format::ColumnDefinition* schema_column, |
197 | | bool prefer_exact_name_match); |
198 | | |
199 | | // Expand a full complex-column projection into table-schema children when the table format provides |
200 | | // an external/current schema. Without this, `SELECT complex_col` or `SELECT *` leaves |
201 | | // ColumnDefinition::children empty, so ColumnMapper treats the root complex column as a scalar |
202 | | // mapping and later tries to cast the old file shape to the current table shape directly. |
203 | | // |
204 | | // Examples: |
205 | | // - STRUCT country/city projected from an old file STRUCT country/population/location should |
206 | | // create children country and city, so city can be materialized as missing/default. |
207 | | // - ARRAY<STRUCT<item, quantity>> should create the array element wrapper and then the element |
208 | | // struct children item and quantity. |
209 | | // - MAP<STRING, STRUCT<full_name, age>> should create semantic children key/value directly, then |
210 | | // expand the value struct children full_name and age. Do not introduce a physical entries |
211 | | // wrapper here: ColumnMapper and TableReader treat MAP children as [key, value]. |
212 | | Status build_all_nested_children_from_schema(format::ColumnDefinition* column, |
213 | | const DataTypePtr& type, const std::string& path, |
214 | | const format::ColumnDefinition* schema_column, |
215 | 34 | bool prefer_exact_name_match) { |
216 | 34 | DORIS_CHECK(column != nullptr); |
217 | | |
218 | 34 | const auto nested_type = remove_nullable(type); |
219 | 34 | AccessPathNode project_all; |
220 | 34 | project_all.project_all = true; |
221 | 34 | switch (nested_type->get_primitive_type()) { |
222 | 4 | case TYPE_STRUCT: { |
223 | 4 | const auto& struct_type = assert_cast<const DataTypeStruct&>(*nested_type); |
224 | 14 | for (size_t field_idx = 0; field_idx < struct_type.get_elements().size(); ++field_idx) { |
225 | 10 | const auto field_name = struct_type.get_element_name(field_idx); |
226 | 10 | const auto* schema_child = |
227 | 10 | find_schema_child_by_path(schema_column, field_name, prefer_exact_name_match); |
228 | 10 | auto* child = find_or_add_child( |
229 | 10 | column, schema_field_id_or(schema_child, cast_set<int32_t>(field_idx)), |
230 | 10 | schema_field_name_or(schema_child, field_name), |
231 | 10 | struct_type.get_element(field_idx)); |
232 | 10 | inherit_schema_metadata(child, schema_child); |
233 | 10 | RETURN_IF_ERROR(build_nested_children_from_access_node( |
234 | 10 | child, child->type, project_all, path + "." + child->name, schema_child, |
235 | 10 | prefer_exact_name_match)); |
236 | 10 | } |
237 | 4 | return Status::OK(); |
238 | 4 | } |
239 | 1 | case TYPE_ARRAY: { |
240 | 1 | const auto& array_type = assert_cast<const DataTypeArray&>(*nested_type); |
241 | 1 | const auto* element_schema = schema_column != nullptr && !schema_column->children.empty() |
242 | 1 | ? &schema_column->children[0] |
243 | 1 | : nullptr; |
244 | 1 | auto* child = find_or_add_child(column, schema_field_id_or(element_schema, 0), "element", |
245 | 1 | array_type.get_nested_type()); |
246 | 1 | inherit_schema_metadata(child, element_schema); |
247 | 1 | return build_nested_children_from_access_node(child, child->type, project_all, path + ".*", |
248 | 1 | element_schema, prefer_exact_name_match); |
249 | 4 | } |
250 | 1 | case TYPE_MAP: { |
251 | 1 | const auto& map_type = assert_cast<const DataTypeMap&>(*nested_type); |
252 | 1 | const auto* key_schema = schema_column != nullptr && !schema_column->children.empty() |
253 | 1 | ? &schema_column->children[0] |
254 | 1 | : nullptr; |
255 | 1 | const auto* value_schema = schema_column != nullptr && schema_column->children.size() > 1 |
256 | 1 | ? &schema_column->children[1] |
257 | 1 | : nullptr; |
258 | 1 | auto* key_child = find_or_add_child(column, schema_field_id_or(key_schema, 0), "key", |
259 | 1 | map_type.get_key_type()); |
260 | 1 | inherit_schema_metadata(key_child, key_schema); |
261 | 1 | RETURN_IF_ERROR(build_nested_children_from_access_node( |
262 | 1 | key_child, key_child->type, project_all, path + ".KEYS", key_schema, |
263 | 1 | prefer_exact_name_match)); |
264 | 1 | auto* value_child = find_or_add_child(column, schema_field_id_or(value_schema, 1), "value", |
265 | 1 | map_type.get_value_type()); |
266 | 1 | inherit_schema_metadata(value_child, value_schema); |
267 | 1 | RETURN_IF_ERROR(build_nested_children_from_access_node( |
268 | 1 | value_child, value_child->type, project_all, path + ".VALUES", value_schema, |
269 | 1 | prefer_exact_name_match)); |
270 | 1 | return Status::OK(); |
271 | 1 | } |
272 | 28 | default: |
273 | 28 | return Status::OK(); |
274 | 34 | } |
275 | 34 | } |
276 | | |
277 | | Status build_struct_children_from_access_node(format::ColumnDefinition* column, |
278 | | const DataTypeStruct& struct_type, |
279 | | const AccessPathNode& node, const std::string& path, |
280 | | const format::ColumnDefinition* schema_column, |
281 | 19 | bool prefer_exact_name_match) { |
282 | 19 | DORIS_CHECK(column != nullptr); |
283 | 20 | for (const auto& [child_path, child_node] : node.children) { |
284 | | // Struct children are resolved by name or schema field id. We do not treat a numeric |
285 | | // child token as a struct ordinal, because `col.0` becomes ambiguous once the struct |
286 | | // evolves. Position-based access needs a separate design if it is required later. |
287 | 20 | if (child_path == "OFFSET" || child_path == "*" || child_path == "KEYS" || |
288 | 20 | child_path == "VALUES") { |
289 | 4 | return Status::NotSupported( |
290 | 4 | "AccessPathParser does not support access path {} for slot {}", |
291 | 4 | path + "." + child_path, column->name); |
292 | 4 | } |
293 | | |
294 | | // Prefer the table/schema ColumnDefinition because it carries field ids and aliases. |
295 | | // Fallback to the struct type name only for formats without external schema metadata. |
296 | 16 | const auto* schema_child = |
297 | 16 | find_schema_child_by_path(schema_column, child_path, prefer_exact_name_match); |
298 | 16 | int32_t field_id = schema_field_id(schema_child); |
299 | 16 | std::string field_name = schema_child == nullptr ? child_path : schema_child->name; |
300 | 16 | DataTypePtr field_type = schema_child == nullptr ? nullptr : schema_child->type; |
301 | 16 | if (field_id < 0 || field_type == nullptr) { |
302 | 11 | for (size_t field_idx = 0; field_idx < struct_type.get_elements().size(); ++field_idx) { |
303 | 8 | if (to_lower(struct_type.get_element_name(field_idx)) == to_lower(field_name)) { |
304 | 1 | field_id = cast_set<int32_t>(field_idx); |
305 | 1 | field_name = struct_type.get_element_name(field_idx); |
306 | 1 | field_type = struct_type.get_element(field_idx); |
307 | 1 | break; |
308 | 1 | } |
309 | 8 | } |
310 | 4 | } |
311 | | |
312 | 16 | if (field_id < 0 || field_type == nullptr) { |
313 | 3 | return Status::NotSupported( |
314 | 3 | "AccessPathParser does not support access path {} for slot {}", |
315 | 3 | path + "." + child_path, column->name); |
316 | 3 | } |
317 | | // TODO: For TVF Parquet files without field ids, this fallback uses the struct ordinal as |
318 | | // the table child identifier. BY_NAME mapping should instead keep a string identifier and |
319 | | // let TableColumnMapper resolve the file-local child id from the Parquet schema. |
320 | 13 | auto* child = find_or_add_child(column, field_id, field_name, field_type); |
321 | 13 | inherit_schema_metadata(child, schema_child); |
322 | 13 | RETURN_IF_ERROR(build_nested_children_from_access_node( |
323 | 13 | child, child->type, child_node, path + "." + child_path, schema_child, |
324 | 13 | prefer_exact_name_match)); |
325 | 13 | } |
326 | 12 | return Status::OK(); |
327 | 19 | } |
328 | | |
329 | | Status build_map_children_from_access_node(format::ColumnDefinition* column, |
330 | | const DataTypeMap& map_type, const AccessPathNode& node, |
331 | | const std::string& path, |
332 | | const format::ColumnDefinition* schema_column, |
333 | 6 | bool prefer_exact_name_match) { |
334 | 6 | DORIS_CHECK(column != nullptr); |
335 | 6 | AccessPathNode key_node; |
336 | 6 | AccessPathNode value_node; |
337 | 6 | bool need_key = false; |
338 | 6 | bool need_value = false; |
339 | | |
340 | 7 | for (const auto& [child_path, child_node] : node.children) { |
341 | 7 | if (child_path == "OFFSET") { |
342 | 1 | return Status::NotSupported( |
343 | 1 | "AccessPathParser does not support access path {} for slot {}", |
344 | 1 | path + "." + child_path, column->name); |
345 | 1 | } |
346 | 6 | if (child_path == "KEYS") { |
347 | 1 | need_key = true; |
348 | 1 | merge_access_path_node(&key_node, child_node); |
349 | 1 | continue; |
350 | 1 | } |
351 | 5 | if (child_path == "VALUES") { |
352 | 3 | need_key = true; |
353 | 3 | key_node.project_all = true; |
354 | 3 | key_node.children.clear(); |
355 | 3 | need_value = true; |
356 | 3 | merge_access_path_node(&value_node, child_node); |
357 | 3 | continue; |
358 | 3 | } |
359 | 2 | if (child_path == "*") { |
360 | 1 | need_key = true; |
361 | 1 | key_node.project_all = true; |
362 | 1 | key_node.children.clear(); |
363 | 1 | need_value = true; |
364 | 1 | merge_access_path_node(&value_node, child_node); |
365 | 1 | continue; |
366 | 1 | } |
367 | 1 | return Status::NotSupported("AccessPathParser does not support access path {} for slot {}", |
368 | 1 | path + "." + child_path, column->name); |
369 | 2 | } |
370 | 4 | if (need_key && !need_value) { |
371 | | // A key-only MAP projection is not independently materializable yet. FileScannerV2 can |
372 | | // describe a projection such as `m.KEYS`, but the downstream file block -> table block path |
373 | | // still builds a ColumnMap from key column + value column + offsets. If the value child is |
374 | | // omitted here, TableReader/ColumnMapper cannot reconstruct a valid table MAP column even |
375 | | // though the query only needs keys. |
376 | | // |
377 | | // Example: |
378 | | // SELECT map_keys(m) FROM t; |
379 | | // or |
380 | | // SELECT * FROM t WHERE array_contains(map_keys(m), 'k1'); |
381 | | // |
382 | | // The access path only asks for `m.KEYS`, but the scan still has to read `m.VALUES` as a |
383 | | // temporary full projection until map materialization supports constructing a table MAP |
384 | | // from keys only. |
385 | 1 | need_value = true; |
386 | 1 | value_node.project_all = true; |
387 | 1 | value_node.children.clear(); |
388 | 1 | } |
389 | | |
390 | 4 | if (!need_key && !need_value) { |
391 | 0 | return Status::OK(); |
392 | 0 | } |
393 | | |
394 | 4 | const auto* key_schema = schema_column != nullptr && !schema_column->children.empty() |
395 | 4 | ? &schema_column->children[0] |
396 | 4 | : nullptr; |
397 | 4 | const auto* value_schema = schema_column != nullptr && schema_column->children.size() > 1 |
398 | 4 | ? &schema_column->children[1] |
399 | 4 | : nullptr; |
400 | 4 | if (need_key) { |
401 | 4 | auto* key_child = find_or_add_child(column, schema_field_id_or(key_schema, 0), "key", |
402 | 4 | map_type.get_key_type()); |
403 | 4 | inherit_schema_metadata(key_child, key_schema); |
404 | 4 | RETURN_IF_ERROR(build_nested_children_from_access_node(key_child, key_child->type, key_node, |
405 | 4 | path + ".KEYS", key_schema, |
406 | 4 | prefer_exact_name_match)); |
407 | 4 | } |
408 | 4 | if (need_value) { |
409 | 4 | auto* value_child = find_or_add_child(column, schema_field_id_or(value_schema, 1), "value", |
410 | 4 | map_type.get_value_type()); |
411 | 4 | inherit_schema_metadata(value_child, value_schema); |
412 | 4 | RETURN_IF_ERROR(build_nested_children_from_access_node( |
413 | 4 | value_child, value_child->type, value_node, path + ".VALUES", value_schema, |
414 | 4 | prefer_exact_name_match)); |
415 | 4 | } |
416 | 3 | return Status::OK(); |
417 | 4 | } |
418 | | |
419 | | Status build_nested_children_from_access_node(format::ColumnDefinition* column, |
420 | | const DataTypePtr& type, const AccessPathNode& node, |
421 | | const std::string& path, |
422 | | const format::ColumnDefinition* schema_column, |
423 | 64 | bool prefer_exact_name_match) { |
424 | 64 | DORIS_CHECK(column != nullptr); |
425 | 64 | if (node.project_all || node.children.empty()) { |
426 | 34 | return build_all_nested_children_from_schema(column, type, path, schema_column, |
427 | 34 | prefer_exact_name_match); |
428 | 34 | } |
429 | | |
430 | 30 | const auto nested_type = remove_nullable(type); |
431 | 30 | switch (nested_type->get_primitive_type()) { |
432 | 19 | case TYPE_STRUCT: |
433 | 19 | return build_struct_children_from_access_node( |
434 | 19 | column, assert_cast<const DataTypeStruct&>(*nested_type), node, path, schema_column, |
435 | 19 | prefer_exact_name_match); |
436 | 5 | case TYPE_ARRAY: { |
437 | 5 | if (node.children.size() != 1 || !node.children.contains("*")) { |
438 | 2 | return Status::NotSupported( |
439 | 2 | "AccessPathParser does not support access path {} for slot {}", path, |
440 | 2 | column->name); |
441 | 2 | } |
442 | 3 | const auto& array_type = assert_cast<const DataTypeArray&>(*nested_type); |
443 | 3 | const auto* element_schema = schema_column != nullptr && !schema_column->children.empty() |
444 | 3 | ? &schema_column->children[0] |
445 | 3 | : nullptr; |
446 | 3 | auto* child = find_or_add_child(column, schema_field_id_or(element_schema, 0), "element", |
447 | 3 | array_type.get_nested_type()); |
448 | 3 | inherit_schema_metadata(child, element_schema); |
449 | 3 | return build_nested_children_from_access_node(child, child->type, node.children.at("*"), |
450 | 3 | path + ".*", element_schema, |
451 | 3 | prefer_exact_name_match); |
452 | 5 | } |
453 | 6 | case TYPE_MAP: |
454 | 6 | return build_map_children_from_access_node( |
455 | 6 | column, assert_cast<const DataTypeMap&>(*nested_type), node, path, schema_column, |
456 | 6 | prefer_exact_name_match); |
457 | 0 | default: |
458 | 0 | return Status::NotSupported("AccessPathParser does not support access path {} for slot {}", |
459 | 0 | path, column->name); |
460 | 30 | } |
461 | 30 | } |
462 | | |
463 | | } // namespace |
464 | | |
465 | | Status AccessPathParser::build_nested_children(format::ColumnDefinition* column, |
466 | | const std::vector<TColumnAccessPath>& access_paths, |
467 | | const format::ColumnDefinition* schema_column, |
468 | 33 | bool prefer_exact_name_match) { |
469 | 33 | DORIS_CHECK(column != nullptr); |
470 | 33 | if (is_scanner_materialized_virtual_column(column->name)) { |
471 | 1 | return Status::OK(); |
472 | 1 | } |
473 | 32 | if (!is_complex_type(remove_nullable(column->type)->get_primitive_type())) { |
474 | 1 | return Status::OK(); |
475 | 1 | } |
476 | | |
477 | 31 | AccessPathNode root; |
478 | | // Build tree for AccessPathNode. |
479 | | // For example, for access paths ["a.b", "a.c", "d"], the tree will be: |
480 | | // root |
481 | | // ├── a |
482 | | // │ ├── b |
483 | | // │ └── c |
484 | | // └── d |
485 | 32 | for (const auto& access_path : access_paths) { |
486 | | // TODO: Support META access paths if needed. Currently AccessPathParser only supports |
487 | | // DATA access paths. |
488 | 32 | if (access_path.type != TAccessPathType::DATA || !access_path.__isset.data_access_path) { |
489 | 2 | return Status::NotSupported( |
490 | 2 | "AccessPathParser only supports DATA access paths for slot {}", column->name); |
491 | 2 | } |
492 | 30 | const auto& path = access_path.data_access_path.path; |
493 | 30 | if (path.empty()) { |
494 | 0 | insert_access_path(&root, path, 0); |
495 | 0 | continue; |
496 | 0 | } |
497 | 30 | int32_t top_level_id = -1; |
498 | 30 | if (to_lower(path.front()) != to_lower(column->name) && |
499 | 30 | (!parse_non_negative_int(path.front(), &top_level_id) || |
500 | 3 | !column->has_identifier_field_id() || |
501 | 3 | top_level_id != column->get_identifier_field_id())) { |
502 | 2 | return Status::NotSupported("AccessPathParser access path {} does not match slot {}", |
503 | 2 | access_path_to_string(path), column->name); |
504 | 2 | } |
505 | 28 | insert_access_path(&root, path, 1); |
506 | 28 | } |
507 | | // Recursively build nested children for the column based on the AccessPathNode tree. |
508 | 27 | return build_nested_children_from_access_node(column, column->type, root, column->name, |
509 | 27 | schema_column, prefer_exact_name_match); |
510 | 31 | } |
511 | | |
512 | | Status AccessPathParser::build_nested_children(format::ColumnDefinition* column, |
513 | | const SlotDescriptor* slot_desc, |
514 | | const format::ColumnDefinition* schema_column, |
515 | 0 | bool prefer_exact_name_match) { |
516 | 0 | DORIS_CHECK(column != nullptr); |
517 | 0 | DORIS_CHECK(slot_desc != nullptr); |
518 | 0 | return build_nested_children(column, slot_desc->all_access_paths(), schema_column, |
519 | 0 | prefer_exact_name_match); |
520 | 0 | } |
521 | | |
522 | | } // namespace doris |