ariesdevil commented on code in PR #5557:
URL: https://github.com/apache/arrow-rs/pull/5557#discussion_r1548101252


##########
parquet/src/arrow/buffer/offset_buffer.rs:
##########
@@ -125,18 +128,50 @@ impl<I: OffsetSizeTrait> OffsetBuffer<I> {
 
     /// Converts this into an [`ArrayRef`] with the provided `data_type` and 
`null_buffer`
     pub fn into_array(self, null_buffer: Option<Buffer>, data_type: ArrowType) 
-> ArrayRef {
-        let array_data_builder = ArrayDataBuilder::new(data_type)
-            .len(self.len())
-            .add_buffer(Buffer::from_vec(self.offsets))
-            .add_buffer(Buffer::from_vec(self.values))
-            .null_bit_buffer(null_buffer);
-
-        let data = match cfg!(debug_assertions) {
-            true => array_data_builder.build().unwrap(),
-            false => unsafe { array_data_builder.build_unchecked() },
-        };
-
-        make_array(data)
+        match data_type {
+            ArrowType::Utf8View => {
+                let mut builder = self.build_generic_byte_view();
+                Arc::new(builder.finish().to_stringview().unwrap())
+            }
+            ArrowType::BinaryView => {
+                let mut builder = self.build_generic_byte_view();
+                Arc::new(builder.finish())
+            }
+            _ => {
+                let array_data_builder = ArrayDataBuilder::new(data_type)
+                    .len(self.len())
+                    .add_buffer(Buffer::from_vec(self.offsets))
+                    .add_buffer(Buffer::from_vec(self.values))
+                    .null_bit_buffer(null_buffer);
+
+                let data = match cfg!(debug_assertions) {
+                    true => array_data_builder.build().unwrap(),
+                    false => unsafe { array_data_builder.build_unchecked() },
+                };
+
+                make_array(data)
+            }
+        }
+    }
+
+    fn build_generic_byte_view(&self) -> 
GenericByteViewBuilder<BinaryViewType> {
+        let mut builder = 
GenericByteViewBuilder::<BinaryViewType>::with_capacity(self.len());
+        for i in self.offsets.windows(2) {
+            let start = i[0];
+            let end = i[1];
+            let b = unsafe {
+                std::slice::from_raw_parts(
+                    self.values.as_ptr().offset(start.to_isize().unwrap()),
+                    (end - start).to_usize().unwrap(),
+                )
+            };
+            if b.is_empty() {
+                builder.append_null();
+            } else {
+                builder.append_value(b);

Review Comment:
   I've changed the code so that it doesn't need to copy bytes anymore. 
   And I agree not using the `OffsetBuffer` for view types, maybe next PR.



-- 
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]

Reply via email to