Fokko commented on code in PR #82: URL: https://github.com/apache/iceberg-rust/pull/82#discussion_r1390768529
########## crates/iceberg/src/avro/schema.rs: ########## @@ -233,23 +222,46 @@ pub(crate) fn schema_to_avro_schema(name: impl ToString, schema: &Schema) -> Res visit_schema(schema, &mut converter).map(Either::unwrap_left) } -pub(crate) fn avro_fixed_schema(len: usize) -> Result<AvroSchema> { +fn avro_record_schema(name: &str, fields: Vec<AvroRecordField>) -> Result<AvroSchema> { + let lookup = fields + .iter() + .enumerate() + .map(|f| (f.1.name.clone(), f.0)) + .collect(); + + Ok(AvroSchema::Record(RecordSchema { + name: Name::new(name)?, + aliases: None, + doc: None, + fields, + lookup, + attributes: Default::default(), + })) +} + +pub(crate) fn avro_fixed_schema(len: usize, logical_type: Option<&str>) -> Result<AvroSchema> { + let attributes = if let Some(logical_type) = logical_type { + BTreeMap::from([( + LOGICAL_TYPE.to_string(), + Value::String(logical_type.to_string()), + )]) Review Comment: Just out of curiosity. Is `BTreeMap` the default in Rust? Trees tend to have many pointers and, therefore have faster lookups in exchange for a larger memory footprint (compared to a `HashMap`). ########## crates/iceberg/src/avro/schema.rs: ########## @@ -441,14 +453,35 @@ impl AvroSchemaVisitor for AvroSchemaToSchema { AvroSchema::Date => Type::Primitive(PrimitiveType::Date), AvroSchema::TimeMicros => Type::Primitive(PrimitiveType::Time), AvroSchema::TimestampMicros => Type::Primitive(PrimitiveType::Timestamp), - AvroSchema::Uuid => Type::Primitive(PrimitiveType::Uuid), AvroSchema::Boolean => Type::Primitive(PrimitiveType::Boolean), AvroSchema::Int => Type::Primitive(PrimitiveType::Int), AvroSchema::Long => Type::Primitive(PrimitiveType::Long), AvroSchema::Float => Type::Primitive(PrimitiveType::Float), AvroSchema::Double => Type::Primitive(PrimitiveType::Double), AvroSchema::String | AvroSchema::Enum(_) => Type::Primitive(PrimitiveType::String), - AvroSchema::Fixed(fixed) => Type::Primitive(PrimitiveType::Fixed(fixed.size as u64)), + AvroSchema::Fixed(fixed) => { + if let Some(logical_type) = fixed.attributes.get(LOGICAL_TYPE) { + let logical_type = logical_type.as_str().ok_or_else(|| { + Error::new( + ErrorKind::DataInvalid, + "logicalType in attributes of avro schema is not a string type", + ) + })?; + match logical_type { + UUID_LOGICAL_TYPE => Type::Primitive(PrimitiveType::Uuid), + ty => { Review Comment: For another PR, `logical_type` could also be a decimal: https://github.com/apache/iceberg-python/blob/main/pyiceberg/utils/schema_conversion.py#L571-L579 ########## crates/iceberg/src/spec/values.rs: ########## @@ -893,9 +925,9 @@ impl Literal { PrimitiveLiteral::Binary(_) => Type::Primitive(PrimitiveType::Binary), PrimitiveLiteral::String(_) => Type::Primitive(PrimitiveType::String), PrimitiveLiteral::UUID(_) => Type::Primitive(PrimitiveType::Uuid), - PrimitiveLiteral::Decimal(dec) => Type::Primitive(PrimitiveType::Decimal { - precision: 38, - scale: dec.scale(), + PrimitiveLiteral::Decimal(_) => Type::Primitive(PrimitiveType::Decimal { + precision: MAX_DECIMAL_PRECISION, + scale: 0, Review Comment: Are we ignoring the scale? -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org