diff --git a/crates/iceberg/src/spec/values.rs b/crates/iceberg/src/spec/values.rs index fd1b2b574..d924bd512 100644 --- a/crates/iceberg/src/spec/values.rs +++ b/crates/iceberg/src/spec/values.rs @@ -450,9 +450,9 @@ impl From for ByteBuf { Literal::Primitive(prim) => match prim { PrimitiveLiteral::Boolean(val) => { if val { - ByteBuf::from([0u8]) - } else { ByteBuf::from([1u8]) + } else { + ByteBuf::from([0u8]) } } PrimitiveLiteral::Int(val) => ByteBuf::from(val.to_le_bytes()), @@ -474,6 +474,36 @@ impl From for ByteBuf { } } +impl From for Vec { + fn from(value: Literal) -> Self { + match value { + Literal::Primitive(prim) => match prim { + PrimitiveLiteral::Boolean(val) => { + if val { + Vec::from([1u8]) + } else { + Vec::from([0u8]) + } + } + PrimitiveLiteral::Int(val) => Vec::from(val.to_le_bytes()), + PrimitiveLiteral::Long(val) => Vec::from(val.to_le_bytes()), + PrimitiveLiteral::Float(val) => Vec::from(val.to_le_bytes()), + PrimitiveLiteral::Double(val) => Vec::from(val.to_le_bytes()), + PrimitiveLiteral::Date(val) => Vec::from(val.to_le_bytes()), + PrimitiveLiteral::Time(val) => Vec::from(val.to_le_bytes()), + PrimitiveLiteral::Timestamp(val) => Vec::from(val.to_le_bytes()), + PrimitiveLiteral::TimestampTZ(val) => Vec::from(val.to_le_bytes()), + PrimitiveLiteral::String(val) => Vec::from(val.as_bytes()), + PrimitiveLiteral::UUID(val) => Vec::from(val.as_u128().to_be_bytes()), + PrimitiveLiteral::Fixed(val) => val, + PrimitiveLiteral::Binary(val) => val, + PrimitiveLiteral::Decimal(_) => todo!(), + }, + _ => unimplemented!(), + } + } +} + impl From<&Literal> for JsonValue { fn from(value: &Literal) -> Self { match value { @@ -995,7 +1025,7 @@ mod tests { assert_eq!(literal, expected_literal); let mut writer = apache_avro::Writer::new(&schema, Vec::new()); - writer.append_ser(bytes).unwrap(); + writer.append_ser(ByteBuf::from(literal)).unwrap(); let encoded = writer.into_inner().unwrap(); let reader = apache_avro::Reader::new(&*encoded).unwrap();