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

Cleanup ArrowNativeType (#1918) #2793

Merged
merged 2 commits into from Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 3 additions & 10 deletions arrow-array/src/array/dictionary_array.rs
Expand Up @@ -308,20 +308,13 @@ impl<K: ArrowPrimitiveType> DictionaryArray<K> {

/// Return an iterator over the keys (indexes into the dictionary)
pub fn keys_iter(&self) -> impl Iterator<Item = Option<usize>> + '_ {
self.keys
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These checks make no sense as we have already validated the dictionary offsets are non-negative

.iter()
.map(|key| key.map(|k| k.to_usize().expect("Dictionary index not usize")))
self.keys.iter().map(|key| key.map(|k| k.as_usize()))
}

/// Return the value of `keys` (the dictionary key) at index `i`,
/// cast to `usize`, `None` if the value at `i` is `NULL`.
pub fn key(&self, i: usize) -> Option<usize> {
self.keys.is_valid(i).then(|| {
self.keys
.value(i)
.to_usize()
.expect("Dictionary index not usize")
})
self.keys.is_valid(i).then(|| self.keys.value(i).as_usize())
}

/// Downcast this dictionary to a [`TypedDictionaryArray`]
Expand Down Expand Up @@ -586,7 +579,7 @@ where

unsafe fn value_unchecked(&self, index: usize) -> Self::Item {
let val = self.dictionary.keys.value_unchecked(index);
let value_idx = val.to_usize().unwrap();
let value_idx = val.as_usize();

// As dictionary keys are only verified for non-null indexes
// we must check the value is within bounds
Expand Down
14 changes: 6 additions & 8 deletions arrow-array/src/array/list_array.rs
Expand Up @@ -80,18 +80,16 @@ impl<OffsetSize: OffsetSizeTrait> GenericListArray<OffsetSize> {
/// # Safety
/// Caller must ensure that the index is within the array bounds
pub unsafe fn value_unchecked(&self, i: usize) -> ArrayRef {
let end = *self.value_offsets().get_unchecked(i + 1);
let start = *self.value_offsets().get_unchecked(i);
self.values
.slice(start.to_usize().unwrap(), (end - start).to_usize().unwrap())
let end = self.value_offsets().get_unchecked(i + 1).as_usize();
let start = self.value_offsets().get_unchecked(i).as_usize();
self.values.slice(start, end - start)
}

/// Returns ith value of this list array.
pub fn value(&self, i: usize) -> ArrayRef {
let end = self.value_offsets()[i + 1];
let start = self.value_offsets()[i];
self.values
.slice(start.to_usize().unwrap(), (end - start).to_usize().unwrap())
let end = self.value_offsets()[i + 1].as_usize();
let start = self.value_offsets()[i].as_usize();
self.values.slice(start, end - start)
}

/// Returns the offset values in the offsets buffer
Expand Down
6 changes: 3 additions & 3 deletions arrow-array/src/builder/string_dictionary_builder.rs
Expand Up @@ -293,9 +293,9 @@ fn get_bytes<'a, K: ArrowNativeType>(values: &'a StringBuilder, key: &K) -> &'a
let offsets = values.offsets_slice();
let values = values.values_slice();

let idx = key.to_usize().unwrap();
let end_offset = offsets[idx + 1].to_usize().unwrap();
let start_offset = offsets[idx].to_usize().unwrap();
let idx = key.as_usize();
let end_offset = offsets[idx + 1].as_usize();
let start_offset = offsets[idx].as_usize();

&values[start_offset..end_offset]
}
Expand Down
1 change: 0 additions & 1 deletion arrow-buffer/Cargo.toml
Expand Up @@ -38,7 +38,6 @@ path = "src/lib.rs"
bench = false

[dependencies]
num = { version = "0.4", default-features = false, features = ["std"] }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is still a dependency elsewhere, but every little helps 😅

half = { version = "2.0", default-features = false }

[dev-dependencies]
Expand Down