github-actions[bot] commented on code in PR #63192: URL: https://github.com/apache/doris/pull/63192#discussion_r3253312414
########## be/src/format/parquet/parquet_nested_column_utils.cpp: ########## @@ -0,0 +1,529 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "format/parquet/parquet_nested_column_utils.h" + +#include <algorithm> +#include <cctype> +#include <string_view> +#include <unordered_map> +#include <utility> + +#include "core/data_type/data_type_nullable.h" +#include "format/parquet/schema_desc.h" + +namespace doris { +namespace { + +enum class NestedPathMode { + NAME, + FIELD_ID, +}; + +void add_column_id_range(const FieldSchema& field_schema, std::set<uint64_t>& column_ids) { + const uint64_t start_id = field_schema.get_column_id(); + const uint64_t max_column_id = field_schema.get_max_column_id(); + for (uint64_t id = start_id; id <= max_column_id; ++id) { + column_ids.insert(id); + } +} + +const FieldSchema* find_child_by_structural_name(const FieldSchema& field_schema, + std::string_view name) { + std::string lower_name(name); + std::transform(lower_name.begin(), lower_name.end(), lower_name.begin(), + [](unsigned char c) { return static_cast<char>(std::tolower(c)); }); + for (const auto& child : field_schema.children) { + if (child.name == name || child.lower_case_name == lower_name) { + return &child; + } + } + return nullptr; +} + +const FieldSchema* find_child_by_exact_name(const FieldSchema& field_schema, + std::string_view name) { + for (const auto& child : field_schema.children) { + if (child.name == name) { + return &child; + } + } + return nullptr; +} + +const FieldSchema* find_variant_typed_child_by_key(const FieldSchema& field_schema, + std::string_view key, NestedPathMode mode) { + if (const auto* child = find_child_by_exact_name(field_schema, key)) { + return child; + } + if (mode == NestedPathMode::NAME) { + return nullptr; + } + for (const auto& child : field_schema.children) { + if (child.field_id >= 0 && key == std::to_string(child.field_id)) { + return &child; + } + } + return nullptr; +} + +void add_variant_metadata(const FieldSchema& variant_field, std::set<uint64_t>& column_ids) { + if (const auto* metadata = find_child_by_structural_name(variant_field, "metadata")) { + add_column_id_range(*metadata, column_ids); + } +} + +void add_variant_value(const FieldSchema& variant_field, std::set<uint64_t>& column_ids) { + add_variant_metadata(variant_field, column_ids); + if (const auto* value = find_child_by_structural_name(variant_field, "value")) { + add_column_id_range(*value, column_ids); + } +} + +struct VariantColumnIdExtractionResult { + bool has_child_columns = false; + bool needs_metadata = false; +}; + +using VariantPathMap = std::unordered_map<std::string, std::vector<std::vector<std::string>>>; + +bool is_shredded_variant_field(const FieldSchema& field_schema) { Review Comment: This also classifies an ordinary typed-only user object whose only child key is named `typed_value` as a shredded wrapper. For example, a valid typed layout for `{'obj': {'typed_value': {'x': 1}}}` has `v.typed_value.obj.typed_value.x`; querying `v['obj']['typed_value']['x']` recurses into `obj`, this predicate treats `obj` itself as a wrapper, and `extract_shredded_variant_field_ids()` consumes the user `typed_value` as wrapper metadata instead of selecting `obj.typed_value.x`. With no residual `value` child in a typed-only file, the helper reports no selected typed leaf and the scan falls back to the wrong top-level residual path/missing data. Please avoid treating a lone complex child named `typed_value` as a wrapper unless the caller can prove it is an unannotated shredded-field layout, and add coverage for a user object field named `typed_value`. ########## be/src/format/parquet/vparquet_reader.cpp: ########## @@ -432,11 +440,111 @@ Status ParquetReader::on_before_init_reader(ReaderInitContext* ctx) { RETURN_IF_ERROR(get_file_metadata_schema(&field_desc)); RETURN_IF_ERROR(TableSchemaChangeHelper::BuildTableInfoUtil::by_parquet_name( ctx->tuple_descriptor, *field_desc, ctx->table_info_node)); + auto column_id_result = _create_column_ids_by_name(field_desc, ctx->tuple_descriptor); + ctx->column_ids = std::move(column_id_result.column_ids); + ctx->filter_column_ids = std::move(column_id_result.filter_column_ids); } return Status::OK(); } Review Comment: This mutates the `FieldDescriptor` returned from `FileMetaData::schema()`, but `_open_file()` can source `_file_metadata` from `_meta_cache`, so multiple readers/fragments scanning the same cached footer can call `assign_ids()` concurrently on the same schema object. `assign_ids()` writes `column_id`/`max_column_id` through the whole tree, so even though the values are deterministic this is still an unsynchronized write/write (and write/read, e.g. `_selected_leaf_column_paths()` / range generation) data race on cached metadata. Please assign these IDs before inserting the footer into the cache, guard the mutation, or use a per-reader copied schema instead of `const_cast`ing the shared cached schema. ########## fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergUtils.java: ########## @@ -618,6 +620,8 @@ public static Type icebergTypeToDorisType(org.apache.iceberg.types.Type type, bo enableMappingVarbinary, enableMappingTimestampTz); } switch (type.typeId()) { + case VARIANT: Review Comment: Exposing VARIANT recursively inside Iceberg complex types needs matching Nereids pruning support. With a schema such as `struct<s: struct<v: variant>>` and `SELECT s.v['k'] FROM tbl`, access collection produces a nested path like `[s, v, k]` for the struct slot, but `NestedColumnPruning.DataTypeAccessTree.setAccessByPath()` has no `VariantType` case below a struct/map/array node. It throws `unsupported data type`, `rewriteRoot()` catches it, and the whole pruning/access-path rewrite is skipped, so nested Iceberg VARIANT subfield reads cannot use the shredded-column pruning this PR adds. Please either handle `VariantType` as an access-path leaf inside complex parents or do not expose nested Iceberg VARIANT until the pruning tree can represent it, with a regression for `struct<variant>` subfield access. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
