mbutrovich commented on code in PR #2188:
URL: https://github.com/apache/iceberg-rust/pull/2188#discussion_r3326658466
##########
crates/iceberg/src/avro/schema.rs:
##########
@@ -37,18 +37,55 @@ const FIELD_ID_PROP: &str = "field-id";
const KEY_ID: &str = "key-id";
const VALUE_ID: &str = "value-id";
const MAP_LOGICAL_TYPE: &str = "map";
+const VARIANT_LOGICAL_TYPE: &str = "variant";
// This const may better to maintain in avro-rs.
const LOGICAL_TYPE: &str = "logicalType";
struct SchemaToAvroSchema {
schema: String,
+ // Stack of enclosing field ids, used to derive unique record names for
+ // structural types (e.g. variant) — mirrors Java TypeToSchema.fieldIds.
+ field_ids: Vec<i32>,
}
type AvroSchemaOrField = Either<AvroSchema, AvroRecordField>;
impl SchemaVisitor for SchemaToAvroSchema {
type T = AvroSchemaOrField;
+ fn before_struct_field(&mut self, field: &NestedFieldRef) -> Result<()> {
Review Comment:
The four `before_*`/`after_*` pairs all do the same push/pop. Could share a
helper:
```rust
fn enter_field(&mut self, f: &NestedFieldRef) -> Result<()> {
self.field_ids.push(f.id); Ok(()) }
fn leave_field(&mut self, _f: &NestedFieldRef) -> Result<()> {
self.field_ids.pop(); Ok(()) }
```
--
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]