yihua commented on code in PR #1086:
URL: https://github.com/apache/hudi-rs/pull/1086#discussion_r4808086979
##########
crates/core/src/avro_to_arrow/schema.rs:
##########
@@ -32,166 +33,181 @@ const HUDI_VARIANT_LOGICAL_TYPE: &str = "variant";
/// Converts an avro schema to an arrow schema
pub fn to_arrow_schema(avro_schema: &apache_avro::Schema) -> Result<Schema> {
+ let resolved = ResolvedSchema::try_from(avro_schema)?;
+ let mut converter = SchemaConverter {
+ names: resolved.get_names(),
+ resolving: HashSet::new(),
+ };
let mut schema_fields = vec![];
match avro_schema {
AvroSchema::Record(RecordSchema { fields, .. }) => {
for field in fields {
- schema_fields.push(schema_to_field_with_props(
+ schema_fields.push(converter.field(
&field.schema,
Some(&field.name),
field.is_nullable(),
Some(external_props(&field.schema)),
)?)
}
}
- schema => schema_fields.push(schema_to_field(schema, Some(""),
false)?),
+ schema => schema_fields.push(converter.field(schema, Some(""), false,
None)?),
}
let schema = Schema::new(schema_fields);
Ok(schema)
}
-fn schema_to_field(
- schema: &apache_avro::Schema,
- name: Option<&str>,
- nullable: bool,
-) -> Result<Field> {
- schema_to_field_with_props(schema, name, nullable, Default::default())
-}
-
/// Arrow's conventional name for a map's entry struct, and what the parquet
/// reader produces — the two schemas have to agree by name to reconcile.
pub(crate) const MAP_ENTRIES_FIELD: &str = "key_value";
-fn schema_to_field_with_props(
- schema: &AvroSchema,
- name: Option<&str>,
- nullable: bool,
- props: Option<HashMap<String, String>>,
-) -> Result<Field> {
- let mut nullable = nullable;
- let field_type: DataType = match schema {
- AvroSchema::Ref { .. } => todo!("Add support for AvroSchema::Ref"),
- AvroSchema::Null => DataType::Null,
- AvroSchema::Boolean => DataType::Boolean,
- AvroSchema::Int => DataType::Int32,
- AvroSchema::Long => DataType::Int64,
- AvroSchema::Float => DataType::Float32,
- AvroSchema::Double => DataType::Float64,
- AvroSchema::Bytes => DataType::Binary,
- AvroSchema::String => DataType::Utf8,
- AvroSchema::Array(item_schema) =>
DataType::List(Arc::new(schema_to_field_with_props(
- &item_schema.items,
- Some("element"),
- false,
- None,
- )?)),
- AvroSchema::Map(value_schema) => {
- // An Arrow dictionary key must be an integer, so the
`Dictionary(Utf8, V)`
- // this used to produce was not a valid type and could not
reconcile
- // against the `Map` a parquet base file carries. Avro map keys are
- // always strings, and the entry struct is never null.
- let value_field =
- schema_to_field_with_props(&value_schema.types, Some("value"),
true, None)?;
- let entries = Field::new(
- MAP_ENTRIES_FIELD,
- DataType::Struct(
- vec![Field::new("key", DataType::Utf8, false),
value_field].into(),
- ),
+struct SchemaConverter<'a> {
+ names: &'a NamesRef<'a>,
+ resolving: HashSet<Name>,
+}
+
+impl SchemaConverter<'_> {
+ fn field(
+ &mut self,
+ schema: &AvroSchema,
+ name: Option<&str>,
+ nullable: bool,
+ props: Option<HashMap<String, String>>,
+ ) -> Result<Field> {
+ let mut nullable = nullable;
+ let field_type: DataType = match schema {
+ AvroSchema::Ref { name: reference } => {
Review Comment:
Addressed in #1102, stacked on this PR, which rewrites those references
before parsing.
##########
crates/core/src/schema/batch_evolution.rs:
##########
@@ -353,6 +353,15 @@ pub(crate) fn is_promotion(from: &DataType, to: &DataType)
-> bool {
}
pub(crate) fn evolve_array(src: &ArrayRef, target_field: &FieldRef) ->
Result<ArrayRef> {
+ // Generic Struct projection would silently drop the shredded payload.
+ if target_field.has_valid_extension_type::<parquet::variant::VariantType>()
Review Comment:
Addressed in #1102, which rebuilds shredded values with `unshred_variant`
before projection.
##########
crates/datafusion/tests/variant_read_tests.rs:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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 datafusion::prelude::SessionContext;
+use hudi_datafusion::HudiDataSource;
+use hudi_test::variant::{variant_rows, variant_table_path};
+use serde_json::json;
+use std::sync::Arc;
+
+#[tokio::test]
+async fn test_variant_table_scan_preserves_values_and_extensions() {
+ for name in ["variant_cow", "variant_mor_avro", "variant_mor_spark"] {
+ let root = variant_table_path(name);
+ let provider =
HudiDataSource::new(root.to_str().unwrap()).await.unwrap();
+ let context = SessionContext::new();
+ context
+ .register_table("variants", Arc::new(provider))
+ .unwrap();
+ let batches = context
+ .sql("SELECT id, v FROM variants WHERE id = 1")
Review Comment:
Done in 531fbe9a; the test now asserts the plan uses `HudiScanExec`.
##########
docs/reader-spec.md:
##########
@@ -348,3 +348,17 @@ For I/O cost estimation (on-disk base + log file sizes),
use `FileSlice::total_s
`Table` / `HudiTable` stores table configs (`HudiTableConfig`) and those read
configs whose scope is `TableOrRead`; a per-read value overrides them.
`ReadOnly` read configs — `hoodie.read.query.type` and the as-of/start/end
timestamps — are filtered out during construction and flow exclusively through
`ReadOptions` / `HudiReadOptions` per-call, so `hudi_options()` on the table
never reflects them.
Out of scope for this version: writer APIs, internal architecture (timeline
parsing, log-record merging, metadata table layout), the full configuration key
glossary (`HudiReadConfig` / `HudiTableConfig` members), and the DataFusion and
C++ bindings — separate spec follow-ups.
+
+## Variant columns
+
+Variant columns use Arrow Struct storage with the `arrow.parquet.variant`
+extension metadata. Unshredded Hudi Variant values are preserved through COW
and
+MOR reads, projections and the Arrow bindings. Consumers can use
+`parquet::variant::VariantArray::try_new` to decode values by child name; Hudi
+producers may order `value` and `metadata` differently. SQL null and an encoded
+Variant null remain distinct.
+
+Variant scans use the Hudi file-group reader in DataFusion. Shredded values are
+currently rejected before schema projection can discard `typed_value`. Variant
+comparisons are not advertised as pushdown predicates; queries on ordinary
Review Comment:
Addressed in #1101, which refuses Variant filters in
`SchemableFilter::try_from` with `Unsupported`.
##########
crates/datafusion/src/lib.rs:
##########
@@ -584,6 +585,14 @@ impl HudiDataSource {
read_options: &ReadOptions,
file_slices: &[FileSlice],
) -> Result<bool> {
+ if self
Review Comment:
Done in 531fbe9a; dropped the check from `use_parquet_source` and pointed
its routing doc at the function that decides it.
--
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]