You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "kosiew (via GitHub)" <gi...@apache.org> on 2026/06/01 09:33:57 UTC
Re: [PR] feat(physical-expr): port Literal to try_to_proto / try_from_proto hooks [datafusion]
kosiew commented on code in PR #22636:
URL: https://github.com/apache/datafusion/pull/22636#discussion_r3333085499
##########
datafusion/physical-expr/src/expressions/literal.rs:
##########
@@ -190,3 +225,93 @@ mod tests {
Ok(())
}
}
+
+/// Tests for the `try_to_proto` / `try_from_proto` hooks.
+#[cfg(all(test, feature = "proto"))]
+mod proto_tests {
+ use super::*;
+ use crate::proto_test_util::{StubEncoder, UnreachableDecoder, column_node};
+ use datafusion_common::DataFusionError;
+ use datafusion_physical_expr_common::physical_expr::proto_decode::PhysicalExprDecodeCtx;
+ use datafusion_physical_expr_common::physical_expr::proto_encode::PhysicalExprEncodeCtx;
+ use datafusion_proto_models::protobuf::physical_expr_node;
+
+ fn i32_literal() -> Literal {
+ Literal::new(ScalarValue::Int32(Some(42)))
+ }
+
+ // ── try_to_proto ─────────────────────────────────────────────────────────
+
+ #[test]
+ fn try_to_proto_encodes_literal() {
+ let literal = i32_literal();
+ let encoder = StubEncoder::ok();
+ let ctx = PhysicalExprEncodeCtx::new(&encoder);
+
+ let node = literal
+ .try_to_proto(&ctx)
+ .unwrap()
+ .expect("Literal should encode to Some(node)");
+
+ // Literal nodes never set expr_id.
+ assert!(node.expr_id.is_none());
+ // Variant must be Literal, not any other expr type.
+ assert!(matches!(
+ node.expr_type,
+ Some(physical_expr_node::ExprType::Literal(_))
+ ));
+ }
+
+ #[test]
+ fn try_to_proto_null_literal() {
+ let literal = Literal::new(ScalarValue::Int32(None));
+ let encoder = StubEncoder::ok();
+ let ctx = PhysicalExprEncodeCtx::new(&encoder);
+
+ let node = literal
+ .try_to_proto(&ctx)
+ .unwrap()
+ .expect("null Literal should encode to Some(node)");
+
+ assert!(matches!(
Review Comment:
Nice test. One thing that might make it a bit stronger is to verify the decoded payload as well, not just the proto variant.
Since the contract is that this round-trips as a null Int32 literal, could we also decode the literal payload and assert that it equals `ScalarValue::Int32(None)`? That would help ensure both the variant and the encoded value are preserved correctly.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org