You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/06/29 02:50:38 UTC
[GitHub] [arrow-datafusion] liukun4515 opened a new pull request, #2809: InList: fix bug for compare with Null in the list using the set optimization
liukun4515 opened a new pull request, #2809:
URL: https://github.com/apache/arrow-datafusion/pull/2809
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #2800
Part of #2755
In the SQL system like Mysql or spark
```
select 1 not in (2,NULL);
NULL
select 2 in (1,NULL)
NULL
```
# Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
# What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2809: InList: fix bug for comparing with Null in the list using the set optimization
Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2809:
URL: https://github.com/apache/arrow-datafusion/pull/2809#discussion_r914014969
##########
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:
We have definitely seen cases where
```rust
if $NEGATED {
// loop
} else {
// loop
}
```
Was faster than
```rust
loop {
if $NEGATED {
// ..
} else {
// ..
}
}
```
But I think the only way to find out if that applies in this case would be with a benchmark
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on pull request #2809: InList: fix bug for comparing with Null in the list using the set optimization
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #2809:
URL: https://github.com/apache/arrow-datafusion/pull/2809#issuecomment-1173002469
> Thank you @liukun4515 -- I reviewed the tests carefully and I think this looks good.
>
> The code "feels" a little more complicated than needed but I think it is doing what it needs to and the test coverage is good.
>
> I wonder if it is worth just 1 test in `sql_integration` somewhere that ensures this implementation is hooked up correctly rather than just relying on tests in `in_list.rs`
>
> I think it would be good if @Ted-Jiang was also able to review this PR prior to merging it, but it isn't necessary.
https://github.com/apache/arrow-datafusion/issues/2832 issue to track it
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on a diff in pull request #2809: InList: fix bug for comparing with Null in the list using the set optimization
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #2809:
URL: https://github.com/apache/arrow-datafusion/pull/2809#discussion_r912423512
##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -209,26 +183,109 @@ macro_rules! make_contains_primitive {
}};
}
-macro_rules! set_contains_with_negated {
- ($ARRAY:expr, $LIST_VALUES:expr, $NEGATED:expr) => {{
- if $NEGATED {
- return Ok(ColumnarValue::Array(Arc::new(
+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 {
$ARRAY
.iter()
- .map(|x| x.map(|v| !$LIST_VALUES.contains(&v.try_into().unwrap())))
- .collect::<BooleanArray>(),
- )));
+ .map(|vop| {
+ match vop.map(|v| !$SET_VALUES.contains(&v.try_into().unwrap())) {
Review Comment:
@alamb I will optimize this with follow-up pr with issue https://github.com/apache/arrow-datafusion/issues/2831
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 merged pull request #2809: InList: fix bug for comparing with Null in the list using the set optimization
Posted by GitBox <gi...@apache.org>.
liukun4515 merged PR #2809:
URL: https://github.com/apache/arrow-datafusion/pull/2809
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on a diff in pull request #2809: InList: fix bug for comparing with Null in the list using the set optimization
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #2809:
URL: https://github.com/apache/arrow-datafusion/pull/2809#discussion_r912421384
##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -163,16 +139,14 @@ macro_rules! make_contains_primitive {
ColumnarValue::Scalar(s) => match s {
ScalarValue::$SCALAR_VALUE(Some(v)) => Some(*v),
ScalarValue::$SCALAR_VALUE(None) => None,
- // TODO this is bug, for primitive the expr list should be cast to the same data type
- ScalarValue::Utf8(None) => None,
- datatype => unimplemented!("Unexpected type {} for InList", datatype),
+ datatype => unreachable!("InList can't reach other data type {} for {}.", datatype, s),
},
ColumnarValue::Array(_) => {
unimplemented!("InList does not yet support nested columns.")
}
})
.collect::<Vec<_>>();
-
+ // TODO do we need to replace this below logic by `in_list_primitive`?
Review Comment:
> I reviewed the logic below and it looked correct to me -- are you asking about the trying to refactor to reduce duplication?
Yes, I want to replace the logic in the `in_list_primitive` by the macro `collection_contains_check`.
I will replace the duplicated code in the in_list_primitive.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on a diff in pull request #2809: InList: fix bug for compare with Null in the list using the set optimization
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #2809:
URL: https://github.com/apache/arrow-datafusion/pull/2809#discussion_r909152444
##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -209,26 +183,109 @@ macro_rules! make_contains_primitive {
}};
}
-macro_rules! set_contains_with_negated {
- ($ARRAY:expr, $LIST_VALUES:expr, $NEGATED:expr) => {{
- if $NEGATED {
- return Ok(ColumnarValue::Array(Arc::new(
+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 {
$ARRAY
.iter()
- .map(|x| x.map(|v| !$LIST_VALUES.contains(&v.try_into().unwrap())))
- .collect::<BooleanArray>(),
- )));
+ .map(|vop| {
+ match vop.map(|v| !$SET_VALUES.contains(&v.try_into().unwrap())) {
Review Comment:
The f32 is not implemented the `eq` trait, we can't use the `set::<f32>.contains`
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] codecov-commenter commented on pull request #2809: InList: fix bug for comparing with Null in the list using the set optimization
Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #2809:
URL: https://github.com/apache/arrow-datafusion/pull/2809#issuecomment-1169493729
# [Codecov](https://codecov.io/gh/apache/arrow-datafusion/pull/2809?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#2809](https://codecov.io/gh/apache/arrow-datafusion/pull/2809?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (d7541f3) into [master](https://codecov.io/gh/apache/arrow-datafusion/commit/7afd4377309eba65100b7bfc07e0c6cd5bf3d780?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (7afd437) will **increase** coverage by `0.19%`.
> The diff coverage is `82.84%`.
```diff
@@ Coverage Diff @@
## master #2809 +/- ##
==========================================
+ Coverage 85.10% 85.30% +0.19%
==========================================
Files 273 274 +1
Lines 48243 48784 +541
==========================================
+ Hits 41059 41616 +557
+ Misses 7184 7168 -16
```
| [Impacted Files](https://codecov.io/gh/apache/arrow-datafusion/pull/2809?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [...atafusion/physical-expr/src/expressions/in\_list.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2809/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9waHlzaWNhbC1leHByL3NyYy9leHByZXNzaW9ucy9pbl9saXN0LnJz) | `83.17% <82.84%> (+11.81%)` | :arrow_up: |
| [datafusion/core/src/physical\_plan/join\_utils.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2809/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb3JlL3NyYy9waHlzaWNhbF9wbGFuL2pvaW5fdXRpbHMucnM=) | `93.61% <0.00%> (-3.20%)` | :arrow_down: |
| [datafusion/proto/src/logical\_plan.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2809/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9wcm90by9zcmMvbG9naWNhbF9wbGFuLnJz) | `17.63% <0.00%> (-0.33%)` | :arrow_down: |
| [datafusion/sql/src/planner.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2809/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9zcWwvc3JjL3BsYW5uZXIucnM=) | `81.34% <0.00%> (-0.02%)` | :arrow_down: |
| [datafusion/optimizer/src/projection\_push\_down.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2809/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9vcHRpbWl6ZXIvc3JjL3Byb2plY3Rpb25fcHVzaF9kb3duLnJz) | `98.08% <0.00%> (ø)` | |
| [...tafusion/optimizer/src/common\_subexpr\_eliminate.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2809/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9vcHRpbWl6ZXIvc3JjL2NvbW1vbl9zdWJleHByX2VsaW1pbmF0ZS5ycw==) | `94.11% <0.00%> (ø)` | |
| [...fusion/optimizer/src/single\_distinct\_to\_groupby.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2809/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9vcHRpbWl6ZXIvc3JjL3NpbmdsZV9kaXN0aW5jdF90b19ncm91cGJ5LnJz) | `98.80% <0.00%> (ø)` | |
| [...on/core/src/physical\_optimizer/coalesce\_batches.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2809/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb3JlL3NyYy9waHlzaWNhbF9vcHRpbWl6ZXIvY29hbGVzY2VfYmF0Y2hlcy5ycw==) | `100.00% <0.00%> (ø)` | |
| [datafusion/optimizer/src/reduce\_outer\_join.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2809/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9vcHRpbWl6ZXIvc3JjL3JlZHVjZV9vdXRlcl9qb2luLnJz) | `99.39% <0.00%> (ø)` | |
| [datafusion/expr/src/utils.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2809/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9leHByL3NyYy91dGlscy5ycw==) | `90.73% <0.00%> (+0.05%)` | :arrow_up: |
| ... and [10 more](https://codecov.io/gh/apache/arrow-datafusion/pull/2809/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/arrow-datafusion/pull/2809?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/arrow-datafusion/pull/2809?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [7afd437...d7541f3](https://codecov.io/gh/apache/arrow-datafusion/pull/2809?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on a diff in pull request #2809: InList: fix bug for compare with Null in the list using the set optimization
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #2809:
URL: https://github.com/apache/arrow-datafusion/pull/2809#discussion_r909152021
##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -163,16 +139,14 @@ macro_rules! make_contains_primitive {
ColumnarValue::Scalar(s) => match s {
ScalarValue::$SCALAR_VALUE(Some(v)) => Some(*v),
ScalarValue::$SCALAR_VALUE(None) => None,
- // TODO this is bug, for primitive the expr list should be cast to the same data type
- ScalarValue::Utf8(None) => None,
- datatype => unimplemented!("Unexpected type {} for InList", datatype),
+ datatype => unreachable!("InList can't reach other data type {} for {}.", datatype, s),
},
ColumnarValue::Array(_) => {
unimplemented!("InList does not yet support nested columns.")
}
})
.collect::<Vec<_>>();
-
+ // TODO do we need to replace this below logic by `in_list_primitive`?
Review Comment:
Do we need to replace below logic by the macro `collection_contains_check`?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] viirya commented on a diff in pull request #2809: InList: fix bug for comparing with Null in the list using the set optimization
Posted by GitBox <gi...@apache.org>.
viirya commented on code in PR #2809:
URL: https://github.com/apache/arrow-datafusion/pull/2809#discussion_r912441168
##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -532,66 +521,131 @@ impl PhysicalExpr for InListExpr {
match value_data_type {
DataType::Boolean => {
let array = array.as_any().downcast_ref::<BooleanArray>().unwrap();
- set_contains_with_negated!(array, set, self.negated)
+ Ok(set_contains_for_primitive!(
Review Comment:
I'm wondering why `set_contains_for_primitive` is macro, but `set_contains_utf` and `make_set_contains_decimal` are methods?
##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -363,25 +349,28 @@ fn make_set_contains_decimal(
.collect::<Vec<_>>();
let native_set: HashSet<i128> = HashSet::from_iter(native_array);
- if !negated {
- // In
- array
- .iter()
- .map(|v| v.map(|v128| native_set.contains(&v128)))
- .collect::<BooleanArray>()
- } else {
- // Not in
- if contains_null {
- // If the expr is NOT IN and the list contains NULL value
- // All the result must be NONE
- BooleanArray::from(vec![None; array.len()])
- } else {
- array
- .iter()
- .map(|v| v.map(|v128| !native_set.contains(&v128)))
- .collect::<BooleanArray>()
- }
- }
+ collection_contains_check!(array, native_set, negated, contains_null)
+}
+
+fn set_contains_utf<OffsetSize: OffsetSizeTrait>(
Review Comment:
```suggestion
fn make_set_contains_utf8<OffsetSize: OffsetSizeTrait>(
```
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on pull request #2809: InList: fix bug for comparing with Null in the list using the set optimization
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #2809:
URL: https://github.com/apache/arrow-datafusion/pull/2809#issuecomment-1170695911
> I don't get it clearly what this is targeted to fix. The issue it closes is "support decimal in (NULL)", but by a quick look, seems the change is more than that. Although there is a few description, but I cannot get it from it too.
>
> Could you rephrase the issue this is going to fix?
sorry for the confused description.
I have described the issue in https://github.com/apache/arrow-datafusion/issues/2817.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on a diff in pull request #2809: InList: fix bug for comparing with Null in the list using the set optimization
Posted by GitBox <gi...@apache.org>.
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on a diff in pull request #2809: InList: fix bug for comparing with Null in the list using the set optimization
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #2809:
URL: https://github.com/apache/arrow-datafusion/pull/2809#discussion_r912423708
##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -1139,4 +1242,192 @@ mod tests {
Ok(())
}
+
+ #[test]
+ fn in_list_set_bool() -> Result<()> {
+ let schema = Schema::new(vec![Field::new("a", DataType::Boolean, true)]);
+ let a = BooleanArray::from(vec![Some(true), None, Some(false)]);
+ let col_a = col("a", &schema)?;
+ let batch = RecordBatch::try_new(Arc::new(schema.clone()), vec![Arc::new(a)])?;
+
+ // expression: "a in (true,null,true.....)"
+ let mut list = vec![
+ lit(ScalarValue::Boolean(Some(true))),
+ lit(ScalarValue::Boolean(None)),
+ ];
+ for _ in 1..(OPTIMIZER_INSET_THRESHOLD + 1) {
Review Comment:
change to `0..OPTIMIZER_INSET_THRESHOLD`
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2809: InList: fix bug for comparing with Null in the list using the set optimization
Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2809:
URL: https://github.com/apache/arrow-datafusion/pull/2809#discussion_r912340297
##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -1139,4 +1242,192 @@ mod tests {
Ok(())
}
+
+ #[test]
+ fn in_list_set_bool() -> Result<()> {
+ let schema = Schema::new(vec![Field::new("a", DataType::Boolean, true)]);
+ let a = BooleanArray::from(vec![Some(true), None, Some(false)]);
+ let col_a = col("a", &schema)?;
+ let batch = RecordBatch::try_new(Arc::new(schema.clone()), vec![Arc::new(a)])?;
+
+ // expression: "a in (true,null,true.....)"
+ let mut list = vec![
+ lit(ScalarValue::Boolean(Some(true))),
+ lit(ScalarValue::Boolean(None)),
+ ];
+ for _ in 1..(OPTIMIZER_INSET_THRESHOLD + 1) {
Review Comment:
I don't understand the choice of bounds of `1` ... `OPTIMIZER_INSET_THRESHOLD + 1` -- why not `0..OPTIMIZER_INSET_THRESHOLD`? Not that this way is wrong, I just don't understand it
##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -1139,4 +1242,192 @@ mod tests {
Ok(())
}
+
+ #[test]
+ fn in_list_set_bool() -> Result<()> {
+ let schema = Schema::new(vec![Field::new("a", DataType::Boolean, true)]);
+ let a = BooleanArray::from(vec![Some(true), None, Some(false)]);
+ let col_a = col("a", &schema)?;
+ let batch = RecordBatch::try_new(Arc::new(schema.clone()), vec![Arc::new(a)])?;
+
+ // expression: "a in (true,null,true.....)"
+ let mut list = vec![
+ lit(ScalarValue::Boolean(Some(true))),
+ lit(ScalarValue::Boolean(None)),
+ ];
+ for _ in 1..(OPTIMIZER_INSET_THRESHOLD + 1) {
+ list.push(lit(ScalarValue::Boolean(Some(true))));
+ }
+ in_list!(
+ batch,
+ list.clone(),
+ &false,
+ vec![Some(true), None, None],
+ col_a.clone(),
+ &schema
+ );
+ in_list!(
+ batch,
+ list,
+ &true,
+ vec![Some(false), None, None],
+ col_a.clone(),
+ &schema
+ );
+ Ok(())
+ }
+
+ #[test]
+ fn in_list_set_int64() -> Result<()> {
+ let schema = Schema::new(vec![Field::new("a", DataType::Int64, true)]);
+ let a = Int64Array::from(vec![Some(0), Some(2), None]);
+ let col_a = col("a", &schema)?;
+ let batch = RecordBatch::try_new(Arc::new(schema.clone()), vec![Arc::new(a)])?;
+
+ // expression: "a in (0,3,4....)"
+ let mut list = vec![
+ lit(ScalarValue::Int64(Some(0))),
+ lit(ScalarValue::Int64(None)),
+ lit(ScalarValue::Int64(Some(3))),
+ ];
+ for v in 4..(OPTIMIZER_INSET_THRESHOLD + 4) {
+ list.push(lit(ScalarValue::Int64(Some(v as i64))));
+ }
+
+ in_list!(
+ batch,
+ list.clone(),
+ &false,
+ vec![Some(true), None, None],
+ col_a.clone(),
+ &schema
+ );
+
+ in_list!(
+ batch,
+ list.clone(),
+ &true,
+ vec![Some(false), None, None],
+ col_a.clone(),
+ &schema
+ );
+
+ Ok(())
+ }
+
+ #[test]
+ fn in_list_set_float64() -> Result<()> {
+ let schema = Schema::new(vec![Field::new("a", DataType::Float64, true)]);
+ let a = Float64Array::from(vec![Some(0.0), Some(2.0), None]);
+ let col_a = col("a", &schema)?;
+ let batch = RecordBatch::try_new(Arc::new(schema.clone()), vec![Arc::new(a)])?;
+
+ // expression: "a in (0.0,3.0,4.0 ....)"
Review Comment:
```suggestion
// expression: "a in (0.0,Null,3.0,4.0 ....)"
```
##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -163,16 +139,14 @@ macro_rules! make_contains_primitive {
ColumnarValue::Scalar(s) => match s {
ScalarValue::$SCALAR_VALUE(Some(v)) => Some(*v),
ScalarValue::$SCALAR_VALUE(None) => None,
- // TODO this is bug, for primitive the expr list should be cast to the same data type
- ScalarValue::Utf8(None) => None,
- datatype => unimplemented!("Unexpected type {} for InList", datatype),
+ datatype => unreachable!("InList can't reach other data type {} for {}.", datatype, s),
},
ColumnarValue::Array(_) => {
unimplemented!("InList does not yet support nested columns.")
}
})
.collect::<Vec<_>>();
-
+ // TODO do we need to replace this below logic by `in_list_primitive`?
Review Comment:
I reviewed the logic below and it looked correct to me -- are you asking about the trying to refactor to reduce duplication?
##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -1139,4 +1242,192 @@ mod tests {
Ok(())
}
+
Review Comment:
I really like the test coverage
##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -1139,4 +1242,192 @@ mod tests {
Ok(())
}
+
+ #[test]
+ fn in_list_set_bool() -> Result<()> {
+ let schema = Schema::new(vec![Field::new("a", DataType::Boolean, true)]);
+ let a = BooleanArray::from(vec![Some(true), None, Some(false)]);
+ let col_a = col("a", &schema)?;
+ let batch = RecordBatch::try_new(Arc::new(schema.clone()), vec![Arc::new(a)])?;
+
+ // expression: "a in (true,null,true.....)"
+ let mut list = vec![
+ lit(ScalarValue::Boolean(Some(true))),
+ lit(ScalarValue::Boolean(None)),
+ ];
+ for _ in 1..(OPTIMIZER_INSET_THRESHOLD + 1) {
+ list.push(lit(ScalarValue::Boolean(Some(true))));
+ }
+ in_list!(
+ batch,
+ list.clone(),
+ &false,
+ vec![Some(true), None, None],
+ col_a.clone(),
+ &schema
+ );
+ in_list!(
+ batch,
+ list,
+ &true,
+ vec![Some(false), None, None],
+ col_a.clone(),
+ &schema
+ );
+ Ok(())
+ }
+
+ #[test]
+ fn in_list_set_int64() -> Result<()> {
+ let schema = Schema::new(vec![Field::new("a", DataType::Int64, true)]);
+ let a = Int64Array::from(vec![Some(0), Some(2), None]);
+ let col_a = col("a", &schema)?;
+ let batch = RecordBatch::try_new(Arc::new(schema.clone()), vec![Arc::new(a)])?;
+
+ // expression: "a in (0,3,4....)"
Review Comment:
```suggestion
// expression: "a in (0,Null,3,4....)"
```
##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -209,26 +183,109 @@ macro_rules! make_contains_primitive {
}};
}
-macro_rules! set_contains_with_negated {
- ($ARRAY:expr, $LIST_VALUES:expr, $NEGATED:expr) => {{
- if $NEGATED {
- return Ok(ColumnarValue::Array(Arc::new(
+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 {
$ARRAY
.iter()
- .map(|x| x.map(|v| !$LIST_VALUES.contains(&v.try_into().unwrap())))
- .collect::<BooleanArray>(),
- )));
+ .map(|vop| {
+ match vop.map(|v| !$SET_VALUES.contains(&v.try_into().unwrap())) {
Review Comment:
Elsewhere in DataFusion (including in `ScalarValue`) we use `ordered_float` to compare floating point numbers
It might be possible to use `set::<OrderedFloat<f32>>`, which would be more space efficient (fewer bytes than `ScalarValue`) as well as faster (as the comparison doens't have to dispatch on the type each time)
https://github.com/apache/arrow-datafusion/blob/88b88d4360054a85982987aa07b3f3afd2db7d70/datafusion/common/src/scalar.rs#L33
##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -1139,4 +1242,192 @@ mod tests {
Ok(())
}
+
+ #[test]
+ fn in_list_set_bool() -> Result<()> {
+ let schema = Schema::new(vec![Field::new("a", DataType::Boolean, true)]);
+ let a = BooleanArray::from(vec![Some(true), None, Some(false)]);
+ let col_a = col("a", &schema)?;
+ let batch = RecordBatch::try_new(Arc::new(schema.clone()), vec![Arc::new(a)])?;
+
+ // expression: "a in (true,null,true.....)"
+ let mut list = vec![
+ lit(ScalarValue::Boolean(Some(true))),
+ lit(ScalarValue::Boolean(None)),
+ ];
+ for _ in 1..(OPTIMIZER_INSET_THRESHOLD + 1) {
+ list.push(lit(ScalarValue::Boolean(Some(true))));
+ }
+ in_list!(
+ batch,
+ list.clone(),
+ &false,
+ vec![Some(true), None, None],
Review Comment:
👍
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] viirya commented on pull request #2809: InList: fix bug for comparing with Null in the list using the set optimization
Posted by GitBox <gi...@apache.org>.
viirya commented on PR #2809:
URL: https://github.com/apache/arrow-datafusion/pull/2809#issuecomment-1170376136
I don't get it clearly what this is targeted to fix. The issue it closes is "support decimal in (NULL)", but by a quick look, seems the change is more than that. Although there is a few description, but I cannot get it from it too.
Could you rephrase the issue this is going to fix?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on a diff in pull request #2809: InList: fix bug for comparing with Null in the list using the set optimization
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #2809:
URL: https://github.com/apache/arrow-datafusion/pull/2809#discussion_r912479940
##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -532,66 +521,131 @@ impl PhysicalExpr for InListExpr {
match value_data_type {
DataType::Boolean => {
let array = array.as_any().downcast_ref::<BooleanArray>().unwrap();
- set_contains_with_negated!(array, set, self.negated)
+ Ok(set_contains_for_primitive!(
Review Comment:
`set_contains_utf` and `make_set_contains_decimal` are just apply to a specified data type case which are not compatible with other primitive case.
`set_contains_for_primitive` will apply to many similar case and same logic
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] viirya commented on a diff in pull request #2809: InList: fix bug for comparing with Null in the list using the set optimization
Posted by GitBox <gi...@apache.org>.
viirya commented on code in PR #2809:
URL: https://github.com/apache/arrow-datafusion/pull/2809#discussion_r912515638
##########
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:
Two `$NEGATED` cases look very similar, is it possible to combine them to save code?
e.g.
```rust
if $CONTAINS_NULL {
$ARRAY
.iter()
.map(|vop| match vop.map(|v| {
if $NEGATED { !$VALUES.contains(&v) } else { $VALUES.contains(&v) }
}) {
Some(true) if $NEGATED => None,
Some(false) if !$NEGATED => None,
x => x,
})
.collect::<BooleanArray>()
} else {
$ARRAY
.iter()
.map(|vop| vop.map(|v| {
if $NEGATED { !$VALUES.contains(&v) } else { $VALUES.contains(&v) }
})
.collect::<BooleanArray>()
}
```
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on a diff in pull request #2809: InList: fix bug for comparing with Null in the list using the set optimization
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #2809:
URL: https://github.com/apache/arrow-datafusion/pull/2809#discussion_r912572979
##########
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:
Thanks @viirya
these two branches can be merged.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on a diff in pull request #2809: InList: fix bug for comparing with Null in the list using the set optimization
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #2809:
URL: https://github.com/apache/arrow-datafusion/pull/2809#discussion_r912577528
##########
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:
https://github.com/apache/arrow-datafusion/issues/2833 track this.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] liukun4515 commented on a diff in pull request #2809: InList: fix bug for compare with Null in the list using the set optimization
Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #2809:
URL: https://github.com/apache/arrow-datafusion/pull/2809#discussion_r909152773
##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -209,26 +183,109 @@ macro_rules! make_contains_primitive {
}};
}
-macro_rules! set_contains_with_negated {
- ($ARRAY:expr, $LIST_VALUES:expr, $NEGATED:expr) => {{
- if $NEGATED {
- return Ok(ColumnarValue::Array(Arc::new(
+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 {
$ARRAY
.iter()
- .map(|x| x.map(|v| !$LIST_VALUES.contains(&v.try_into().unwrap())))
- .collect::<BooleanArray>(),
- )));
+ .map(|vop| {
+ match vop.map(|v| !$SET_VALUES.contains(&v.try_into().unwrap())) {
Review Comment:
We just use the `set::<Scalarvalue::Float32/Float64>
##########
datafusion/physical-expr/src/expressions/in_list.rs:
##########
@@ -209,26 +183,109 @@ macro_rules! make_contains_primitive {
}};
}
-macro_rules! set_contains_with_negated {
- ($ARRAY:expr, $LIST_VALUES:expr, $NEGATED:expr) => {{
- if $NEGATED {
- return Ok(ColumnarValue::Array(Arc::new(
+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 {
$ARRAY
.iter()
- .map(|x| x.map(|v| !$LIST_VALUES.contains(&v.try_into().unwrap())))
- .collect::<BooleanArray>(),
- )));
+ .map(|vop| {
+ match vop.map(|v| !$SET_VALUES.contains(&v.try_into().unwrap())) {
Review Comment:
We just use the `set::<Scalarvalue::Float32/Float64>`
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org