liukun4515 commented on code in PR #2809:
URL: https://github.com/apache/arrow-datafusion/pull/2809#discussion_r912577312
##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -170,86 +146,114 @@ macro_rules! make_contains_primitive {
})
.collect::<Vec<_>>();
- if $NEGATED {
+ Ok(collection_contains_check!(array, values, $NEGATED, contains_null))
+ }};
+}
+
+macro_rules! set_contains_for_float {
+ ($ARRAY:expr, $SET_VALUES:expr, $SCALAR_VALUE:ident, $NEGATED:expr,
$PHY_TYPE:ty) => {{
+ let contains_null = $SET_VALUES.iter().any(|s| s.is_null());
+ let bool_array = if $NEGATED {
+ // Not in
if contains_null {
- Ok(ColumnarValue::Array(Arc::new(
- array
- .iter()
- .map(|x| match x.map(|v| !values.contains(&v)) {
+ $ARRAY
+ .iter()
+ .map(|vop| {
+ match vop.map(|v|
!$SET_VALUES.contains(&v.try_into().unwrap())) {
Some(true) => None,
x => x,
- })
- .collect::<BooleanArray>(),
- )))
+ }
+ })
+ .collect::<BooleanArray>()
} else {
- Ok(ColumnarValue::Array(Arc::new(
- not_in_list_primitive(array, &values)?,
- )))
+ $ARRAY
+ .iter()
+ .map(|vop| vop.map(|v|
!$SET_VALUES.contains(&v.try_into().unwrap())))
+ .collect::<BooleanArray>()
}
} else {
+ // In
if contains_null {
- Ok(ColumnarValue::Array(Arc::new(
- array
- .iter()
- .map(|x| match x.map(|v| values.contains(&v)) {
+ $ARRAY
+ .iter()
+ .map(|vop| {
+ match vop.map(|v|
$SET_VALUES.contains(&v.try_into().unwrap())) {
Some(false) => None,
x => x,
- })
- .collect::<BooleanArray>(),
- )))
+ }
+ })
+ .collect::<BooleanArray>()
} else {
- Ok(ColumnarValue::Array(Arc::new(in_list_primitive(
- array, &values,
- )?)))
+ $ARRAY
+ .iter()
+ .map(|vop| vop.map(|v|
$SET_VALUES.contains(&v.try_into().unwrap())))
+ .collect::<BooleanArray>()
}
- }
+ };
+ ColumnarValue::Array(Arc::new(bool_array))
+ }};
+}
+
+macro_rules! set_contains_for_primitive {
+ ($ARRAY:expr, $SET_VALUES:expr, $SCALAR_VALUE:ident, $NEGATED:expr,
$PHY_TYPE:ty) => {{
+ let contains_null = $SET_VALUES.iter().any(|s| s.is_null());
+ let native_array = $SET_VALUES
+ .iter()
+ .flat_map(|v| match v {
+ $SCALAR_VALUE(value) => *value,
+ datatype => {
+ unreachable!(
+ "InList can't reach other data type {} for {}.",
+ datatype, v
+ )
+ }
+ })
+ .collect::<Vec<_>>();
+ let native_set: HashSet<$PHY_TYPE> = HashSet::from_iter(native_array);
+
+ collection_contains_check!($ARRAY, native_set, $NEGATED, contains_null)
}};
}
-macro_rules! set_contains_with_negated {
- ($ARRAY:expr, $LIST_VALUES:expr, $NEGATED:expr) => {{
- if $NEGATED {
- return Ok(ColumnarValue::Array(Arc::new(
+macro_rules! collection_contains_check {
+ ($ARRAY:expr, $VALUES:expr, $NEGATED:expr, $CONTAINS_NULL:expr) => {{
+ let bool_array = if $NEGATED {
Review Comment:
@viirya @alamb
each loop will check the `$NEGATED` and has two branches for switching.
Is this can use the vectorization?
I am not sure about this, so I will remain current implementation.
We can discuss it until getting the conclusion.
--
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]