sunchao commented on code in PR #5407: URL: https://github.com/apache/datafusion-comet/pull/5407#discussion_r3870702825
########## native/core/src/parquet/cast_column/variant.rs: ########## @@ -0,0 +1,1414 @@ +// 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. +use arrow::{ + array::{ + make_array, Array, ArrayRef, AsArray, BinaryArray, BinaryBuilder, ListLikeArray, + StructArray, + }, + buffer::NullBuffer, + compute::{cast, cast_with_options}, + datatypes::{DataType, FieldRef, TimeUnit}, + error::ArrowError, +}; +use datafusion::common::{ + format::DEFAULT_CAST_OPTIONS, DataFusionError, Result as DataFusionResult, +}; +use parquet::variant::{ + unshred_variant, BorrowedShreddingState, ListBuilder, MetadataBuilder, ObjectBuilder, + ParentState, ReadOnlyMetadataBuilder, ValueBuilder, Variant, VariantArray, VariantBuilder, + VariantDecimal4, VariantDecimal8, VariantMetadata, WritableMetadataBuilder, +}; +use std::{ + collections::HashSet, + panic::{catch_unwind, AssertUnwindSafe}, + sync::Arc, +}; + +pub(super) fn normalize_variant_array( + array: &ArrayRef, + target_field: &FieldRef, +) -> DataFusionResult<ArrayRef> { + let DataType::Struct(fields) = target_field.data_type() else { + return Err(DataFusionError::Execution( + "Variant extension field must use Struct storage".to_string(), + )); + }; + if fields.len() != 2 + || fields[0].name() != "value" + || fields[1].name() != "metadata" + || fields + .iter() + .any(|field| field.data_type() != &DataType::Binary) + { + return Err(DataFusionError::Execution( + "Variant output must contain Binary children [value, metadata]".to_string(), + )); + } + + let array = normalize_variant_storage(array)?; Review Comment: [P2] Preserve ENUM's String meaning in shredded Variant leaves This path takes Arrow's Binary mapping for a Parquet ENUM child as the final Variant type, but Spark interprets ENUM as String. With `allowReadingShredded=true` and pushdown disabled, an ordinary `v` group containing `typed_value BINARY (ENUM)` and UTF-8 `red` returns `schema_of_variant(v) = STRING` and Variant `"red"` under both Spark 4.0.4 readers. At this head, an asserted `CometNativeScanExec` instead returns `BINARY` and Variant `"cmVk"`. The fixture has no `ARROW:schema`; STRING-annotated and unannotated-BINARY controls agree with Spark. Please preserve the physical ENUM annotation's String interpretation before unshredding, or retain fallback for these inputs. -- 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]
