tustvold commented on code in PR #3933:
URL: https://github.com/apache/arrow-rs/pull/3933#discussion_r1147579237
##########
arrow-array/src/array/union_array.rs:
##########
@@ -241,21 +243,29 @@ impl UnionArray {
///
/// Panics if `index` is greater than the length of the array.
pub fn type_id(&self, index: usize) -> i8 {
- assert!(index < self.len());
- self.data().buffers()[0].as_slice()[self.offset() + index] as i8
+ self.type_ids[index]
+ }
+
+ /// Returns the `type_ids` for this array
+ pub fn type_ids(&self) -> &ScalarBuffer<i8> {
+ &self.type_ids
+ }
+
+ /// Returns the `offsets` buffer if this is a dense array
+ pub fn offsets(&self) -> Option<&ScalarBuffer<i32>> {
+ self.offsets.as_ref()
}
/// Returns the offset into the underlying values array for the array slot
at `index`.
///
/// # Panics
///
/// Panics if `index` is greater than the length of the array.
- pub fn value_offset(&self, index: usize) -> i32 {
+ pub fn value_offset(&self, index: usize) -> usize {
assert!(index < self.len());
- if self.is_dense() {
- self.data().buffers()[1].typed_data::<i32>()[self.offset() + index]
- } else {
- (self.offset() + index) as i32
Review Comment:
This can potentially overflow, so I opted to change value_offset to return
usize as this is not only more correct, but is what most call-sites want anyway
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]