-
Notifications
You must be signed in to change notification settings - Fork 32
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
fix: binary_numeric is now correct (+ tests!) #1721
base: develop
Are you sure you want to change the base?
Conversation
Lessons learned: do not merge without at least basic tests. We check for a constant array but do not create a new constant array with the appropriate length for the child on which we want to delegate the binary numeric operation. That is now fixed. I also added a very basic test suite for applying the (now six) numeric operations on pairs of arrays where one of the two are constant. In order to properly support constant arrays on the left- hand-side, I added FlippedSub and FlippedDiv which allow us to commute/flip the operator so that we need not teach ConstantArray to check if its right-hand-side supports an operation on constants.
Sub, | ||
/// Same as [BinaryNumericOperator::Sub] but with the parameters flipped: `right - left`. | ||
FlippedSub, |
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'm not sure about these operators... it sort of forces everyone to handle bi-directional operators?
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 an array has no clever binary numeric operation, it just uses the Arrow implementation, but, yes, if an array implements subtract and it wants to handle constant right-hand-sides, it needs to deal with FlippedSub.
I suppose, if we had unary negation, we could use Add to flip. It seems bad to introduce a second pass over the array though.
An array could implement just Sub
and fallback to Arrow for FlippedSub
.
I kinda think this is just the essential complexity of a non-commutative operation? Or maybe I misunderstand what you mean about bi-directional operators?
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 idea sounds cool but I think the clever binary numeric functions are easy to implemented for both LHS and RHS. Maybe other operators would have some benefits by doing this? I'm not sure.
array: &DictArray, | ||
rhs: &ArrayData, | ||
op: BinaryNumericOperator, | ||
) -> VortexResult<Option<ArrayData>> { |
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.
We need a pre-check to verify that the values of the dictionary array are of a primitive type. If not, we can fast-fail to avoid creating a new ConstantArray.
Lessons learned: do not merge without at least basic tests.
Four major changes:
binary_numeric.rs
We check for a constant array but do not create a new constant array with the appropriate length for the child on which we want to delegate the binary numeric operation. That is now fixed.
I also added a very basic test suite for applying the (now six) numeric operations on pairs of arrays where one of the two are constant.
In order to properly support constant arrays on the left-hand-side, I added FlippedSub and FlippedDiv which allow us to commute/flip the operator so that we need not teach ConstantArray to check if its right-hand-side supports an operation on constants.