alamb commented on a change in pull request #9038:
URL: https://github.com/apache/arrow/pull/9038#discussion_r550761457
##########
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:
I wonder if this handles `NULL` correctly -- like for a value of where
`expr` is NULL the output should be NULL (not true/false). The semantics when
there is a literal `NULL` in the inlist are even stranger (but likely could be
handled as a follow on PR)
For example:
```
sqlite> create table t(c1 int);
sqlite> insert into t values (10);
sqlite> insert into t values (20);
sqlite> insert into t values(NULL);
sqlite> select c1, c1 IN (20, NULL) from t;
10|
20|1
|
sqlite> select c1, c1 IN (20) from t;
10|0
20|1
|
```
Note that `10 IN (20, NULL)` is actually `NULL` rather than `FALSE`. Crazy
##########
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:
I wonder if this handles `NULL` correctly -- like for a value of where
`expr` is NULL the output should be NULL (not true/false). The semantics when
there is a literal `NULL` in the inlist are even stranger (but likely could be
handled as a follow on PR)
For example:
```SQL
sqlite> create table t(c1 int);
sqlite> insert into t values (10);
sqlite> insert into t values (20);
sqlite> insert into t values(NULL);
sqlite> select c1, c1 IN (20, NULL) from t;
10|
20|1
|
sqlite> select c1, c1 IN (20) from t;
10|0
20|1
|
```
Note that `10 IN (20, NULL)` is actually `NULL` rather than `FALSE`. Crazy
----------------------------------------------------------------
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]