diff --git a/datafusion/physical-expr/src/array_expressions.rs b/datafusion/physical-expr/src/array_expressions.rs index 45169e2d0ae5..8a9fb4499e3d 100644 --- a/datafusion/physical-expr/src/array_expressions.rs +++ b/datafusion/physical-expr/src/array_expressions.rs @@ -1281,7 +1281,8 @@ fn general_replace( } _ => { let from_arr = Scalar::new(from_array_row); - arrow_ord::cmp::eq(&list_array_row, &from_arr)? + // use not_distinct so NULL = NULL + arrow_ord::cmp::not_distinct(&list_array_row, &from_arr)? } }; diff --git a/datafusion/sqllogictest/test_files/array.slt b/datafusion/sqllogictest/test_files/array.slt index ec67e9cb5690..0d9f27d3b85a 100644 --- a/datafusion/sqllogictest/test_files/array.slt +++ b/datafusion/sqllogictest/test_files/array.slt @@ -1744,7 +1744,7 @@ create table t as values # ([3, 1, NULL, 3], 3, 4, 2) => [4, 1, NULL, 4] NULL not matched -# ([3, 1, NULL, 3], NULL, 5, 2) => [3, 1, NULL, 3] NULL not replaced (not eq) +# ([3, 1, NULL, 3], NULL, 5, 2) => [3, 1, NULL, 3] NULL is replaced with 5 # ([NULL], 3, 2, 1) => NULL # ([3, 1, 3], 3, NULL, 1) => [NULL, 1 3] @@ -1752,7 +1752,7 @@ query ?III? select column1, column2, column3, column4, array_replace_n(column1, column2, column3, column4) from t; ---- [3, 1, , 3] 3 4 2 [4, 1, , 4] -[3, 1, , 3] NULL 5 2 [3, 1, , 3] +[3, 1, , 3] NULL 5 2 [3, 1, 5, 3] NULL 3 2 1 NULL [3, 1, 3] 3 NULL 1 [, 1, 3]