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

GH-44626: [Java] fix SplitAndTransfer throws for empty MapVector #44627

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

myegorov
Copy link
Contributor

@myegorov myegorov commented Nov 3, 2024

Rationale for this change

Empty MapVector.splitAndTransfer throws java.lang.IndexOutOfBoundsException. Details in #44626

What changes are included in this PR?

Fixed for MapVector as for other vector types in #41066

Are these changes tested?

Added unit test mimicking the scenario we've observed where MapVector's offset buffer capacity is 0.

final int relativeOffset =
offsetBuffer.getInt((startIndex + i) * OFFSET_WIDTH) - startPoint;
to.offsetBuffer.setInt(i * OFFSET_WIDTH, relativeOffset);
if (length > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just return if length=0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do though my personal preference would be to avoid multiple returns. Current implementation is in keeping with how splitAndTransfer is implemented for other complex types (e.g. ListVector).

@github-actions github-actions bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Nov 3, 2024
ListVector toListVector = (ListVector) transferPair.getTo();

assertEquals(valueCount, toListVector.getValueCount());
fromListVector.clear();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use try-with-resources

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that there're several closeable resources here and toListVector cannot be constructed inside the same try as fromListVector. This is just to say that there'd be some ugly nesting if using try.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Sure.

@vibhatha
Copy link
Collaborator

vibhatha commented Nov 3, 2024

@lidavidm need some help to run the CIs.

MapVector dataVector = (MapVector) fromListVector.getDataVector();
dataVector.allocateNew();
// unset capacity to mimic observed failure mode
dataVector.getOffsetBuffer().capacity(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, a list vector is supposed to have 1 offset when it's empty. But I suppose other parts of the library have this issue/"optimization"

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Nov 8, 2024
@github-actions github-actions bot added awaiting merge Awaiting merge and removed awaiting changes Awaiting changes labels Nov 8, 2024
@lidavidm lidavidm merged commit 5fe87a3 into apache:main Nov 8, 2024
16 checks passed
@lidavidm lidavidm removed the awaiting merge Awaiting merge label Nov 8, 2024
Copy link

After merging your PR, Conbench analyzed the 3 benchmarking runs that have been run so far on merge-commit 5fe87a3.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details.

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

Successfully merging this pull request may close these issues.

4 participants