From 53e791f6452459b695013dd74a060259ce078f01 Mon Sep 17 00:00:00 2001 From: Jan Kaul Date: Tue, 17 Oct 2023 09:48:42 +0200 Subject: [PATCH 1/3] fix avro bytes test --- crates/iceberg/src/spec/values.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/iceberg/src/spec/values.rs b/crates/iceberg/src/spec/values.rs index fd1b2b574c..e5825a19cd 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()), @@ -995,7 +995,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(Into::::into(literal)).unwrap(); let encoded = writer.into_inner().unwrap(); let reader = apache_avro::Reader::new(&*encoded).unwrap(); From a46d980f1bc043af5b9afa1e2929d1d7204a15cc Mon Sep 17 00:00:00 2001 From: Jan Kaul Date: Wed, 18 Oct 2023 09:06:31 +0200 Subject: [PATCH 2/3] impl from Literal for vec u8 --- crates/iceberg/src/spec/values.rs | 32 ++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/crates/iceberg/src/spec/values.rs b/crates/iceberg/src/spec/values.rs index e5825a19cd..1d6ea0d2f6 100644 --- a/crates/iceberg/src/spec/values.rs +++ b/crates/iceberg/src/spec/values.rs @@ -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) => Vec::from(val), + PrimitiveLiteral::Binary(val) => Vec::from(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(Into::::into(literal)).unwrap(); + writer.append_ser(ByteBuf::from(literal)).unwrap(); let encoded = writer.into_inner().unwrap(); let reader = apache_avro::Reader::new(&*encoded).unwrap(); From a48a8c8163da570908e96291e85b79a7517ac3db Mon Sep 17 00:00:00 2001 From: Jan Kaul Date: Wed, 18 Oct 2023 09:10:16 +0200 Subject: [PATCH 3/3] fix clippy warnings --- crates/iceberg/src/spec/values.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/iceberg/src/spec/values.rs b/crates/iceberg/src/spec/values.rs index 1d6ea0d2f6..d924bd5121 100644 --- a/crates/iceberg/src/spec/values.rs +++ b/crates/iceberg/src/spec/values.rs @@ -495,8 +495,8 @@ impl From for Vec { 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) => Vec::from(val), - PrimitiveLiteral::Binary(val) => Vec::from(val), + PrimitiveLiteral::Fixed(val) => val, + PrimitiveLiteral::Binary(val) => val, PrimitiveLiteral::Decimal(_) => todo!(), }, _ => unimplemented!(),