seddonm1 commented on a change in pull request #9038:
URL: https://github.com/apache/arrow/pull/9038#discussion_r550808963



##########
File path: rust/datafusion/src/physical_plan/expressions.rs
##########
@@ -2414,6 +2417,212 @@ impl PhysicalSortExpr {
     }
 }
 
+/// InList
+#[derive(Debug)]
+pub struct InListExpr {
+    expr: Arc<dyn PhysicalExpr>,
+    list: Vec<Arc<dyn PhysicalExpr>>,
+}
+
+macro_rules! make_contains {
+    ($ARRAY:expr, $LIST_VALUES:expr, $SCALAR_VALUE:ident, $ARRAY_TYPE:ident) 
=> {{
+        let array = $ARRAY.as_any().downcast_ref::<$ARRAY_TYPE>().unwrap();
+
+        let values = $LIST_VALUES
+            .iter()
+            .map(|expr| match expr {
+                ColumnarValue::Scalar(s) => match s {
+                    ScalarValue::$SCALAR_VALUE(Some(v)) => v,
+                    datatype => unimplemented!("Unexpected type {} for 
InList", datatype),
+                },
+                ColumnarValue::Array(_) => {
+                    unimplemented!("InList should not receive Array")
+                }
+            })
+            .collect::<Vec<_>>();
+
+        Ok(ColumnarValue::Array(Arc::new(
+            array
+                .iter()
+                .map(|x| x.map(|x| values.contains(&&x)))

Review comment:
       This approach of mapping the array was suggested by @jorgecarleitao when 
helping me with the StringExpressions: 
https://github.com/apache/arrow/blob/master/rust/datafusion/src/physical_plan/string_expressions.rs#L84.
 The benefit is that if the input value is `NULL` (i.e. `None`) then we don't 
have to do any work on it (the second `map`).
   
   I have confirmed this is the desired behavior against Postgres 13.1 so that 
any `NULL` input `expr` should return null:
   
   ```sql
   SELECT NULL IN ('a'); -> NULL
   SELECT NULL NOT IN ('a'); -> NULL
   SELECT NULL IN (NULL, 'a'); -> NULL
   SELECT NULL NOT IN (NULL, 'a'); -> NULL
   ```




----------------------------------------------------------------
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.

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


Reply via email to