-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-43768: [C++] Fix the case when boolean_{any|all} meets constant input with length in Acero #43799
Conversation
|
@zanmato1984 @pitrou @felipecrv would you mind take a look? |
Co-authored-by: Rossi Sun <zanmato1984@gmail.com>
this->all = !scalar.is_valid || checked_cast<const BooleanScalar&>(scalar).value; | ||
this->has_nulls |= !scalar.is_valid; | ||
this->count += scalar.is_valid * batch.length; | ||
this->all &= !scalar.is_valid || checked_cast<const BooleanScalar&>(scalar).value; | ||
return Status::OK(); | ||
} | ||
const ArraySpan& data = batch[0].array; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why didn't change has_null =
to has_null |=
as what you did for any
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And my question is why make it |=
instead of simply =
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason is in #43799 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
this->has_nulls = !scalar.is_valid; | ||
this->any = scalar.is_valid && checked_cast<const BooleanScalar&>(scalar).value; | ||
this->count += scalar.is_valid; | ||
this->has_nulls |= !scalar.is_valid; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct? If the argument is a scalar, isn't it as if the whole batch was made from repeated values of that scalar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- If previous is
has_null
, it always has_null ( that's why using|=
) !scalar.is_valid
means has-null, so it would set by this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @mapleFU is right here. this->has_nulls
is meant to represent whether any null was encountered, so it should never change from true
to false
.
this->any = scalar.is_valid && checked_cast<const BooleanScalar&>(scalar).value; | ||
this->count += scalar.is_valid; | ||
this->has_nulls |= !scalar.is_valid; | ||
this->any |= scalar.is_valid && checked_cast<const BooleanScalar&>(scalar).value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the |
? Isn't that necessary only in MergeFrom
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #43799 (comment)
this->count += scalar.is_valid; | ||
this->has_nulls |= !scalar.is_valid; | ||
this->any |= scalar.is_valid && checked_cast<const BooleanScalar&>(scalar).value; | ||
this->count += scalar.is_valid * batch.length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one I understand.
this->all = !scalar.is_valid || checked_cast<const BooleanScalar&>(scalar).value; | ||
this->has_nulls |= !scalar.is_valid; | ||
this->count += scalar.is_valid * batch.length; | ||
this->all &= !scalar.is_valid || checked_cast<const BooleanScalar&>(scalar).value; | ||
return Status::OK(); | ||
} | ||
const ArraySpan& data = batch[0].array; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And my question is why make it |=
instead of simply =
?
@felipecrv The problem is here, the |
Isn't that a problem in itself? |
IMO we don't declare that /// \brief Kernel data structure for implementations of
/// ScalarAggregateFunction. The four necessary components of an aggregation
/// kernel are the init, consume, merge, and finalize functions.
///
/// * init: creates a new KernelState for a kernel.
/// * consume: processes an ExecSpan and updates the KernelState found in the
/// KernelContext.
/// * merge: combines one KernelState with another.
/// * finalize: produces the end result of the aggregation using the
/// KernelState in the KernelContext.
struct ARROW_EXPORT ScalarAggregateKernel : public Kernel { The I would also glad to put the acero with other method but I think modify |
Makes sense @mapleFU. I'm learning. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM. But what you think @bkietz?
std::vector<ExecBatch> batches{ | ||
ExecBatchFromJSON({int32()}, "[[42], [42], [42], [42]]")}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to test more cases? Something like:
struct AnyAllCase {
std::string batches_json;
std::string expected_json;
};
std::vector<AnyAllCase> cases {
{"[[42], []]", "[[false]]"},
{"[[42, 42], []]", "[[true]]"},
{"[[42], [42]]", "[[true]]"},
{"[[42], [42, 42]]", "[[true]]"},
{"[[42], []]", "[[false]]"},
{"[[42, 42], []]", "[[true]]"},
{"[[42], [42]]", "[[true]]"},
{"[[42], [42, 42]]", "[[true]]"},
};
Also vary the skip_nulls
and the boolean literal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit hard to build test like this since the Literal column would only built by Projection
here, but I've tried
Project cannot make "different" literal in this scenerio
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pitrou Would you mind take a quick look that whether the testing is ok?
135227f
to
5616f8c
Compare
5616f8c
to
72f9b83
Compare
72f9b83
to
140e3be
Compare
After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 9cafbb2. There were no benchmark performance regressions. 🎉 The full Conbench report has more details. It also includes information about 7 possible false positives for unstable benchmarks that are known to sometimes produce them. |
…ant input with length in Acero (apache#43799) ### Rationale for this change See apache#43768 ### What changes are included in this PR? Fix the case when boolean_{any|all} meets constant input with length in Acero ### Are these changes tested? Yes ### Are there any user-facing changes? no * GitHub Issue: apache#43768 Lead-authored-by: mwish <maplewish117@gmail.com> Co-authored-by: mwish <1506118561@qq.com> Co-authored-by: Rossi Sun <zanmato1984@gmail.com> Signed-off-by: mwish <maplewish117@gmail.com>
…ant input with length in Acero (apache#43799) ### Rationale for this change See apache#43768 ### What changes are included in this PR? Fix the case when boolean_{any|all} meets constant input with length in Acero ### Are these changes tested? Yes ### Are there any user-facing changes? no * GitHub Issue: apache#43768 Lead-authored-by: mwish <maplewish117@gmail.com> Co-authored-by: mwish <1506118561@qq.com> Co-authored-by: Rossi Sun <zanmato1984@gmail.com> Signed-off-by: mwish <maplewish117@gmail.com>
…ant input with length in Acero (apache#43799) ### Rationale for this change See apache#43768 ### What changes are included in this PR? Fix the case when boolean_{any|all} meets constant input with length in Acero ### Are these changes tested? Yes ### Are there any user-facing changes? no * GitHub Issue: apache#43768 Lead-authored-by: mwish <maplewish117@gmail.com> Co-authored-by: mwish <1506118561@qq.com> Co-authored-by: Rossi Sun <zanmato1984@gmail.com> Signed-off-by: mwish <maplewish117@gmail.com>
Rationale for this change
See #43768
What changes are included in this PR?
Fix the case when boolean_{any|all} meets constant input with length in Acero
Are these changes tested?
Yes
Are there any user-facing changes?
no