Skip to content
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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

danking
Copy link
Member

@danking danking commented Dec 18, 2024

Lessons learned: do not merge without at least basic tests.

Four major changes:

  1. Fix arithmetic operations to be correct (vis-a-vis lengths and commuting).
  2. Basic test for binary_numeric, parameterized by an array (following the approach described in Compute function test harness #1719).
  3. Add FlippedSub and FlippedDiv to support checking if the RHS supports the given operation.
  4. Ensure the binary numeric implementation is always in 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.

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.
@danking danking requested review from lwwmanning and gatesn December 18, 2024 21:51
@danking danking marked this pull request as ready for review December 18, 2024 21:51
Sub,
/// Same as [BinaryNumericOperator::Sub] but with the parameters flipped: `right - left`.
FlippedSub,
Copy link
Contributor

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?

Copy link
Member Author

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?

Copy link
Contributor

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.

@danking danking enabled auto-merge (squash) December 19, 2024 02:33
array: &DictArray,
rhs: &ArrayData,
op: BinaryNumericOperator,
) -> VortexResult<Option<ArrayData>> {
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants