c-thiel commented on code in PR #2188:
URL: https://github.com/apache/iceberg-rust/pull/2188#discussion_r3273182164
##########
crates/iceberg/src/avro/schema.rs:
##########
@@ -220,6 +257,46 @@ impl SchemaVisitor for SchemaToAvroSchema {
}
}
+ fn variant(&mut self, _v: &VariantType) -> Result<AvroSchemaOrField> {
+ let fields = vec![
+ AvroRecordField {
+ name: "metadata".to_string(),
+ schema: AvroSchema::Bytes,
+ order: RecordFieldOrder::Ignore,
+ position: 0,
+ doc: None,
+ aliases: None,
+ default: None,
+ custom_attributes: Default::default(),
+ },
+ AvroRecordField {
+ name: "value".to_string(),
+ schema: AvroSchema::Bytes,
+ order: RecordFieldOrder::Ignore,
+ position: 1,
+ doc: None,
+ aliases: None,
+ default: None,
+ custom_attributes: Default::default(),
+ },
+ ];
+ // Avro record names must be unique within a schema. Derive the name
from the
+ // enclosing field id.
+ let record_name = match self.field_ids.last() {
+ Some(id) => format!("r{id}"),
+ // falling back to "variant" when no enclosing id is set.
+ None => VARIANT_LOGICAL_TYPE.to_string(),
+ };
+ let mut schema = avro_record_schema(&record_name, fields)?;
+ if let AvroSchema::Record(record) = &mut schema {
+ record.attributes.insert(
+ LOGICAL_TYPE.to_string(),
+ Value::String(VARIANT_LOGICAL_TYPE.to_string()),
+ );
+ }
Review Comment:
Currently it is genuinely `unreachable` so I think this is the right call.
Fixed in
https://github.com/apache/iceberg-rust/pull/2188/commits/71ef18a15cf59cf04e9e90c4d5d428eee71e1cb7
--
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]