Dandandan commented on code in PR #20428:
URL: https://github.com/apache/datafusion/pull/20428#discussion_r2831854746


##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -792,35 +805,40 @@ impl PhysicalExpr for InListExpr {
                                     })
                                     .collect::<BooleanArray>()
                             }
-                            ColumnarValue::Scalar(scalar) => {
-                                // Check if scalar is null once, before the 
loop
-                                if scalar.is_null() {
-                                    // If scalar is null, all comparisons 
return null
-                                    BooleanArray::from(vec![None; num_rows])
-                                } else {
-                                    // Convert scalar to 1-element array
-                                    let array = scalar.to_array()?;
-                                    let cmp = make_comparator(
-                                        value.as_ref(),
-                                        array.as_ref(),
-                                        SortOptions::default(),
-                                    )?;
-                                    // Compare each row of value with the 
single scalar element
-                                    (0..num_rows)
-                                        .map(|i| {
-                                            if value.is_null(i) {
-                                                None
-                                            } else {
-                                                Some(cmp(i, 0).is_eq())
-                                            }
-                                        })
-                                        .collect::<BooleanArray>()
-                                }
+                        }
+                        ColumnarValue::Scalar(scalar) => {
+                            if scalar.is_null() {
+                                // null compared to anything is null
+                                BooleanArray::new(
+                                    BooleanBuffer::new_unset(num_rows),
+                                    Some(NullBuffer::new_null(num_rows)),
+                                )
+                            } else if use_arrow_eq {
+                                // Vectorized scalar comparison
+                                let scalar_datum = scalar.to_scalar()?;
+                                arrow_eq(&value, &scalar_datum)?
+                            } else {
+                                // Row-by-row comparator for nested types
+                                let array = scalar.to_array()?;
+                                let cmp = make_comparator(
+                                    value.as_ref(),
+                                    array.as_ref(),
+                                    SortOptions::default(),
+                                )?;
+                                (0..num_rows)

Review Comment:
   BooleanBuffer::collect_bool + cloning the original null buffer is much 
faster.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to