mbutrovich commented on code in PR #3354:
URL: https://github.com/apache/iceberg-rust/pull/3354#discussion_r4209484958


##########
crates/iceberg/src/avro/deserializer.rs:
##########
@@ -0,0 +1,457 @@
+// 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.
+
+//! Deserialization straight from an Avro writer schema, with the parts of Avro
+//! schema resolution that apache-avro's schema-aware deserializer leaves out.
+//!
+//! `Reader::into_deser_iter` decodes into serde types without building
+//! `apache_avro::types::Value`s, but it requires the reader schema to equal 
the
+//! writer schema and applies no resolution rules. [`ResolvingDeserializer`]
+//! wraps it and routes every value through `deserialize_any`, which follows 
the
+//! writer schema. As a result:
+//!
+//! - Avro record names don't have to match serde type names.
+//! - A writer value that isn't a union reads into an `Option`.
+//! - A writer union reads into a type that isn't an `Option`. A null value
+//!   returns an error.
+//! - serde's numeric visitors convert between numeric types, so an `int` reads
+//!   into an `i64` and a `float` into an `f64`. An integer that doesn't fit 
the
+//!   target, such as a `long` above `i32::MAX` read into an `i32`, returns an
+//!   error. Conversions into `f32` or `f64` use `as` and can lose precision.

Review Comment:
   > a type mismatch the old path rejected up front now only surfaces as a 
serde error when a value is actually hit, so a mismatched column whose values 
are all null reads clean.
   
   If I'm reading 0.21 right, the old path didn't check types up front either. 
[`Reader::with_schema`](https://github.com/apache/avro-rs/blob/04707999f75278fdea927ee8d2a59de41d8f22a7/avro/src/reader.rs#L356-L367)
 only compares the writer and reader schemas for equality, and the reader 
[resolves each value as it reads 
it](https://github.com/apache/avro-rs/blob/04707999f75278fdea927ee8d2a59de41d8f22a7/avro/src/reader.rs#L203).
 A null resolves to the null branch of the reader's union 
([`types.rs#L1020-L1044`](https://github.com/apache/avro-rs/blob/04707999f75278fdea927ee8d2a59de41d8f22a7/avro/src/types.rs#L1020-L1044))
 whatever the writer's other branch is. So `main` also reads a mismatched 
column whose values are all null without an error.
   
   > aliases, reader-schema defaults, string-to-bytes promotion, name/order 
matching outside the partition record
   
   As I read `main`, the reader schema used few of these.
   - It never set aliases 
([`schema.rs#L95-L104`](https://github.com/apache/iceberg-rust/blob/ab047b5e2f6e2ba6b999731653a3f7722b84e6f7/crates/iceberg/src/avro/schema.rs#L95-L104)).
   - Its only defaults were null for optional fields 
([`schema.rs#L88-L94`](https://github.com/apache/iceberg-rust/blob/ab047b5e2f6e2ba6b999731653a3f7722b84e6f7/crates/iceberg/src/avro/schema.rs#L88-L94)).
 The `Option` fields and `#[serde(default)]` on `content` cover them, and the 
two field audits check each one.
   - A `string` written for a `bytes` field still reads, because 
`serde_bytes::ByteBuf` accepts a string.
   - Fields outside the partition record match by name in any order through 
serde. The writer-schema tests in `spec/manifest/mod.rs` cover reordered fields.
   
   Given that, do you see a manifest that the two readers would read 
differently? If you do, I'll add it as a fixture test.



-- 
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]

Reply via email to