liurenjie1024 commented on code in PR #406:
URL: https://github.com/apache/iceberg-rust/pull/406#discussion_r1641882147


##########
crates/iceberg/src/spec/values.rs:
##########
@@ -105,6 +108,115 @@ pub struct Datum {
     literal: PrimitiveLiteral,
 }
 
+impl Serialize for Datum {
+    fn serialize<S: serde::Serializer>(
+        &self,
+        serializer: S,
+    ) -> std::result::Result<S::Ok, S::Error> {
+        let mut strucet_ser = serializer
+            .serialize_struct("Datum", 2)
+            .map_err(serde::ser::Error::custom)?;
+        strucet_ser
+            .serialize_field("type", &self.r#type)
+            .map_err(serde::ser::Error::custom)?;
+        strucet_ser
+            .serialize_field(
+                "literal",
+                &RawLiteral::try_from(
+                    Literal::Primitive(self.literal.clone()),
+                    &Type::Primitive(self.r#type.clone()),
+                )
+                .unwrap(),

Review Comment:
   We should not panic here.



##########
crates/iceberg/src/spec/values.rs:
##########
@@ -105,6 +108,115 @@ pub struct Datum {
     literal: PrimitiveLiteral,
 }
 
+impl Serialize for Datum {
+    fn serialize<S: serde::Serializer>(
+        &self,
+        serializer: S,
+    ) -> std::result::Result<S::Ok, S::Error> {
+        let mut strucet_ser = serializer
+            .serialize_struct("Datum", 2)
+            .map_err(serde::ser::Error::custom)?;
+        strucet_ser
+            .serialize_field("type", &self.r#type)
+            .map_err(serde::ser::Error::custom)?;
+        strucet_ser
+            .serialize_field(
+                "literal",
+                &RawLiteral::try_from(

Review Comment:
   I think the key here is that we should implement ser/de for `Literal` using 
`RawLiteral`, and then derive Ser/De of `Datum`, in this case we can avoid 
boilerplate code of ser/de of `Datum`.



##########
crates/iceberg/src/expr/predicate.rs:
##########
@@ -37,6 +38,29 @@ pub struct LogicalExpression<T, const N: usize> {
     inputs: [Box<T>; N],
 }
 
+impl<T: Serialize, const N: usize> Serialize for LogicalExpression<T, N> {
+    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, 
S::Error>
+    where
+        S: serde::Serializer,
+    {
+        self.inputs.serialize(serializer)
+    }
+}
+
+impl<'de, T: Deserialize<'de>, const N: usize> Deserialize<'de> for 
LogicalExpression<T, N> {
+    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
+    where
+        D: serde::Deserializer<'de>,
+    {
+        let inputs = Vec::<Box<T>>::deserialize(deserializer)?;
+        Ok(LogicalExpression::new(
+            array_init::from_iter(inputs.into_iter()).ok_or_else(|| {
+                serde::de::Error::custom("Failed to deserialize 
LogicalExpression")

Review Comment:
   In what case this may fail? If the only failure is the vec length, we should 
make it explicit in error message.



-- 
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

Reply via email to