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

Add ValuesIter to iterate defined values in ArrayAccessor (#2578) #2579

Closed
wants to merge 2 commits into from

Conversation

tustvold
Copy link
Contributor

Draft as I need to double check this doesn't regress benchmarks and I'm not a massive fan of this

Which issue does this PR close?

Closes #2578

Rationale for this change

What changes are included in this PR?

Are there any user-facing changes?

@tustvold tustvold requested a review from viirya August 24, 2022 18:10
unsafe { Some(Some(self.array.value_unchecked(old))) }
}
}

fn size_hint(&self) -> (usize, Option<usize>) {
(
self.array.len() - self.current,
Some(self.array.len() - self.current),
self.current_end - self.current,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Drive by fix, the DoubleEndedIterator size hint previously would be incorrect

/// the key at a null index is unspecified, and consequently may exceed the bounds of the
/// values array.
///
const NULLS_DEFINED: bool;
Copy link
Contributor Author

@tustvold tustvold Aug 24, 2022

Choose a reason for hiding this comment

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

I don't especially like that we end up polluting everything just because dictionaries have strange null behaviour...

@github-actions github-actions bot added the arrow Changes to the arrow crate label Aug 24, 2022
@@ -307,9 +307,8 @@ fn cast_primitive_to_decimal<T: ArrayAccessor, F>(
where
F: Fn(T::Item) -> i128,
{
#[allow(clippy::redundant_closure)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ran into this issue also, and was similarly baffled by it. rust-lang/rust-clippy#1608 provided the solution, so I fixed up the other callsites

// Dictionary indexes should be valid
unsafe { self.values.value_unchecked(value_idx) }
}
const NULLS_DEFINED: bool = false;

unsafe fn value_unchecked(&self, index: usize) -> Self::Item {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I think the problematic one is value_unchecked, no? value always checks is_valid of the key.

But in value_unchecked, the key is retrieved by value_unchecked so it could be unspecified and cause undefined value from values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just moved value to be default implemented, I will revert as the panic messages are better this way

Comment on lines +64 to +71
let comparison =
ValuesIter::new(left)
.zip(ValuesIter::new(right))
.map(|(a, b)| match (a, b) {
(Some(a), Some(b)) => op(a, b),
_ => false,
});
// SAFETY: ValuesIter is a trusted length iterator
Copy link
Member

Choose a reason for hiding this comment

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

Not sure how much this impacts performance.

@tustvold
Copy link
Contributor Author

This represents a non-trivial performance regression currently 😢

@tustvold
Copy link
Contributor Author

I'm going to handle this differently

@tustvold tustvold closed this Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Potential OOB Access in Unreleased Comparison Kernels
2 participants