Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions datafusion/core/src/physical_optimizer/projection_pushdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,6 @@ mod tests {

#[test]
fn test_update_matching_exprs() -> Result<()> {
let udf = Arc::new(ScalarUDF::new_from_impl(DummyUDF::new()));
let exprs: Vec<Arc<dyn PhysicalExpr>> = vec![
Arc::new(BinaryExpr::new(
Arc::new(Column::new("a", 3)),
Expand All @@ -1404,7 +1403,7 @@ mod tests {
Arc::new(NegativeExpr::new(Arc::new(Column::new("f", 4)))),
Arc::new(ScalarFunctionExpr::new(
"scalar_expr",
Arc::clone(&udf),
Arc::new(ScalarUDF::new_from_impl(DummyUDF::new())),
vec![
Arc::new(BinaryExpr::new(
Arc::new(Column::new("b", 1)),
Expand Down Expand Up @@ -1469,7 +1468,7 @@ mod tests {
Arc::new(NegativeExpr::new(Arc::new(Column::new("f", 5)))),
Arc::new(ScalarFunctionExpr::new(
"scalar_expr",
Arc::clone(&udf),
Arc::new(ScalarUDF::new_from_impl(DummyUDF::new())),
vec![
Arc::new(BinaryExpr::new(
Arc::new(Column::new("b", 1)),
Expand Down Expand Up @@ -1523,7 +1522,6 @@ mod tests {

#[test]
fn test_update_projected_exprs() -> Result<()> {
let udf = Arc::new(ScalarUDF::new_from_impl(DummyUDF::new()));
let exprs: Vec<Arc<dyn PhysicalExpr>> = vec![
Arc::new(BinaryExpr::new(
Arc::new(Column::new("a", 3)),
Expand All @@ -1538,7 +1536,7 @@ mod tests {
Arc::new(NegativeExpr::new(Arc::new(Column::new("f", 4)))),
Arc::new(ScalarFunctionExpr::new(
"scalar_expr",
Arc::clone(&udf),
Arc::new(ScalarUDF::new_from_impl(DummyUDF::new())),
vec![
Arc::new(BinaryExpr::new(
Arc::new(Column::new("b", 1)),
Expand Down Expand Up @@ -1603,7 +1601,7 @@ mod tests {
Arc::new(NegativeExpr::new(Arc::new(Column::new("f_new", 5)))),
Arc::new(ScalarFunctionExpr::new(
"scalar_expr",
Arc::clone(&udf),
Arc::new(ScalarUDF::new_from_impl(DummyUDF::new())),
vec![
Arc::new(BinaryExpr::new(
Arc::new(Column::new("b_new", 1)),
Expand Down
45 changes: 0 additions & 45 deletions datafusion/expr/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2503,51 +2503,6 @@ mod test {
assert_eq!(udf.signature().volatility, Volatility::Volatile);
}

#[test]
fn test_scalar_udf_eq_pointer() {
#[derive(Debug)]
struct DummyUDF {
signature: Signature,
}

impl DummyUDF {
fn new() -> Self {
Self {
signature: Signature::variadic_any(Volatility::Immutable),
}
}
}

impl ScalarUDFImpl for DummyUDF {
fn as_any(&self) -> &dyn Any {
self
}

fn name(&self) -> &str {
"dummy_udf"
}

fn signature(&self) -> &Signature {
&self.signature
}

fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
Ok(DataType::Int32)
}

fn invoke(&self, _args: &[ColumnarValue]) -> Result<ColumnarValue> {
unimplemented!("DummyUDF::invoke")
}
}

let udf1 = ScalarUDF::new_from_impl(DummyUDF::new());
let udf1_clone = udf1.clone();
let udf2 = ScalarUDF::new_from_impl(DummyUDF::new());

assert!(udf1.eq(&udf1_clone));
assert!(!udf1.eq(&udf2));
}

use super::*;

#[test]
Expand Down
8 changes: 3 additions & 5 deletions datafusion/expr/src/udf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub struct ScalarUDF {

impl PartialEq for ScalarUDF {
fn eq(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.inner, &other.inner)
self.inner.equals(other.inner.as_ref())
}
}

Expand Down Expand Up @@ -678,11 +678,9 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
/// - symmetric: `a.equals(b)` implies `b.equals(a)`;
/// - transitive: `a.equals(b)` and `b.equals(c)` implies `a.equals(c)`.
///
/// By default, checks for pointer equality.
/// By default, compares [`Self::name`] and [`Self::signature`].
fn equals(&self, other: &dyn ScalarUDFImpl) -> bool {
let self_ptr = self as *const _ as *const ();
let other_ptr = other as *const _ as *const ();
std::ptr::eq(self_ptr, other_ptr)
self.name() == other.name() && self.signature() == other.signature()
}

/// Returns a hash value for this scalar UDF.
Expand Down
Loading