From 048bb8aa02041708a1c5f9b2fc3b3da7c04c7c0a Mon Sep 17 00:00:00 2001 From: 0lai0 Date: Wed, 27 May 2026 14:03:48 +0800 Subject: [PATCH 1/2] Fix inconsistent PartialEq impl in ToJson --- native/spark-expr/src/json_funcs/to_json.rs | 38 +++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/native/spark-expr/src/json_funcs/to_json.rs b/native/spark-expr/src/json_funcs/to_json.rs index fa198bf7e7..bdb75a320f 100644 --- a/native/spark-expr/src/json_funcs/to_json.rs +++ b/native/spark-expr/src/json_funcs/to_json.rs @@ -80,7 +80,7 @@ impl Display for ToJson { impl PartialEq for ToJson { fn eq(&self, other: &dyn Any) -> bool { if let Some(other) = other.downcast_ref::() { - self.expr.eq(&other.expr) && self.timezone.eq(&other.timezone) + self == other } else { false } @@ -287,12 +287,14 @@ fn is_nan(input: &str) -> bool { #[cfg(test)] mod test { - use crate::json_funcs::to_json::struct_to_json; + use crate::json_funcs::to_json::{struct_to_json, ToJson}; use arrow::array::types::Int32Type; use arrow::array::{Array, PrimitiveArray, StringArray}; use arrow::array::{ArrayRef, BooleanArray, Int32Array, StructArray}; use arrow::datatypes::{DataType, Field}; use datafusion::common::Result; + use datafusion::physical_plan::expressions::Column; + use std::any::Any; use std::sync::Arc; #[test] @@ -390,4 +392,36 @@ mod test { Some(""), ])) } + + fn make_to_json(timezone: &str, ignore_null_fields: bool) -> ToJson { + ToJson::new( + Arc::new(Column::new("x", 0)), + timezone, + ignore_null_fields, + ) + } + + #[test] + fn test_partial_eq_same() { + let a = make_to_json("UTC", true); + let b = make_to_json("UTC", true); + assert_eq!(a, b); + assert!(>::eq(&a, &b as &dyn Any)); + } + + #[test] + fn test_partial_eq_dyn_any_differs_on_timezone() { + let a = make_to_json("UTC", true); + let b = make_to_json("America/New_York", true); + assert_ne!(a, b); + assert!(!>::eq(&a, &b as &dyn Any)); + } + + #[test] + fn test_partial_eq_dyn_any_differs_on_ignore_null_fields() { + let a = make_to_json("UTC", true); + let b = make_to_json("UTC", false); + assert_ne!(a, b); + assert!(!>::eq(&a, &b as &dyn Any)); + } } From 0299c1fa4cb5ffdfc7b9605c53c0968c95d48304 Mon Sep 17 00:00:00 2001 From: 0lai0 Date: Wed, 27 May 2026 20:52:17 +0800 Subject: [PATCH 2/2] fix fmt --- native/spark-expr/src/json_funcs/to_json.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/native/spark-expr/src/json_funcs/to_json.rs b/native/spark-expr/src/json_funcs/to_json.rs index bdb75a320f..66f912da88 100644 --- a/native/spark-expr/src/json_funcs/to_json.rs +++ b/native/spark-expr/src/json_funcs/to_json.rs @@ -394,11 +394,7 @@ mod test { } fn make_to_json(timezone: &str, ignore_null_fields: bool) -> ToJson { - ToJson::new( - Arc::new(Column::new("x", 0)), - timezone, - ignore_null_fields, - ) + ToJson::new(Arc::new(Column::new("x", 0)), timezone, ignore_null_fields) } #[test]