You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/11/15 22:09:55 UTC

[GitHub] [arrow-rs] tustvold opened a new pull request, #3122: Add GenericByteBuilder (#2969)

tustvold opened a new pull request, #3122:
URL: https://github.com/apache/arrow-rs/pull/3122

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Part of #2969
   
   # Rationale for this change
    
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking change` label.
   -->
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] viirya commented on a diff in pull request #3122: Add GenericByteBuilder (#2969)

Posted by GitBox <gi...@apache.org>.
viirya commented on code in PR #3122:
URL: https://github.com/apache/arrow-rs/pull/3122#discussion_r1028355055


##########
arrow-array/src/builder/generic_bytes_builder.rs:
##########
@@ -17,70 +17,81 @@
 
 use crate::builder::null_buffer_builder::NullBufferBuilder;
 use crate::builder::{ArrayBuilder, BufferBuilder, UInt8BufferBuilder};
-use crate::{ArrayRef, GenericBinaryArray, OffsetSizeTrait};
+use crate::types::{ByteArrayType, GenericBinaryType, GenericStringType};
+use crate::{ArrayRef, GenericByteArray, OffsetSizeTrait};
+use arrow_buffer::ArrowNativeType;
 use arrow_data::ArrayDataBuilder;
 use std::any::Any;
 use std::sync::Arc;
 
-///  Array builder for [`GenericBinaryArray`]
-#[derive(Debug)]
-pub struct GenericBinaryBuilder<OffsetSize: OffsetSizeTrait> {
+///  Array builder for [`GenericByteArray`]
+pub struct GenericByteBuilder<T: ByteArrayType> {
     value_builder: UInt8BufferBuilder,
-    offsets_builder: BufferBuilder<OffsetSize>,
+    offsets_builder: BufferBuilder<T::Offset>,
     null_buffer_builder: NullBufferBuilder,
 }
 
-impl<OffsetSize: OffsetSizeTrait> GenericBinaryBuilder<OffsetSize> {
-    /// Creates a new [`GenericBinaryBuilder`].
+impl<T: ByteArrayType> GenericByteBuilder<T> {
+    /// Creates a new [`GenericByteBuilder`].
     pub fn new() -> Self {
         Self::with_capacity(1024, 1024)
     }
 
-    /// Creates a new [`GenericBinaryBuilder`].
+    /// Creates a new [`GenericByteBuilder`].
     ///
     /// - `item_capacity` is the number of items to pre-allocate.
     ///   The size of the preallocated buffer of offsets is the number of items plus one.
     /// - `data_capacity` is the total number of bytes of string data to pre-allocate

Review Comment:
   ```suggestion
       /// - `data_capacity` is the total number of bytes of data to pre-allocate
   ```



##########
arrow-array/src/builder/generic_bytes_builder.rs:
##########
@@ -17,70 +17,81 @@
 
 use crate::builder::null_buffer_builder::NullBufferBuilder;
 use crate::builder::{ArrayBuilder, BufferBuilder, UInt8BufferBuilder};
-use crate::{ArrayRef, GenericBinaryArray, OffsetSizeTrait};
+use crate::types::{ByteArrayType, GenericBinaryType, GenericStringType};
+use crate::{ArrayRef, GenericByteArray, OffsetSizeTrait};
+use arrow_buffer::ArrowNativeType;
 use arrow_data::ArrayDataBuilder;
 use std::any::Any;
 use std::sync::Arc;
 
-///  Array builder for [`GenericBinaryArray`]
-#[derive(Debug)]
-pub struct GenericBinaryBuilder<OffsetSize: OffsetSizeTrait> {
+///  Array builder for [`GenericByteArray`]
+pub struct GenericByteBuilder<T: ByteArrayType> {
     value_builder: UInt8BufferBuilder,
-    offsets_builder: BufferBuilder<OffsetSize>,
+    offsets_builder: BufferBuilder<T::Offset>,
     null_buffer_builder: NullBufferBuilder,
 }
 
-impl<OffsetSize: OffsetSizeTrait> GenericBinaryBuilder<OffsetSize> {
-    /// Creates a new [`GenericBinaryBuilder`].
+impl<T: ByteArrayType> GenericByteBuilder<T> {
+    /// Creates a new [`GenericByteBuilder`].
     pub fn new() -> Self {
         Self::with_capacity(1024, 1024)
     }
 
-    /// Creates a new [`GenericBinaryBuilder`].
+    /// Creates a new [`GenericByteBuilder`].
     ///
     /// - `item_capacity` is the number of items to pre-allocate.
     ///   The size of the preallocated buffer of offsets is the number of items plus one.
     /// - `data_capacity` is the total number of bytes of string data to pre-allocate
     ///   (for all items, not per item).
     pub fn with_capacity(item_capacity: usize, data_capacity: usize) -> Self {
-        let mut offsets_builder = BufferBuilder::<OffsetSize>::new(item_capacity + 1);
-        offsets_builder.append(OffsetSize::zero());
+        let mut offsets_builder = BufferBuilder::<T::Offset>::new(item_capacity + 1);
+        offsets_builder.append(T::Offset::from_usize(0).unwrap());
         Self {
             value_builder: UInt8BufferBuilder::new(data_capacity),
             offsets_builder,
             null_buffer_builder: NullBufferBuilder::new(item_capacity),
         }
     }
 
-    /// Appends a byte slice into the builder.
+    /// Appends a value into the builder.
     #[inline]
-    pub fn append_value(&mut self, value: impl AsRef<[u8]>) {
-        self.value_builder.append_slice(value.as_ref());
+    pub fn append_value(&mut self, value: impl AsRef<T::Native>) {
+        self.value_builder.append_slice(value.as_ref().as_ref());
         self.null_buffer_builder.append(true);
         self.offsets_builder
-            .append(OffsetSize::from_usize(self.value_builder.len()).unwrap());
+            .append(T::Offset::from_usize(self.value_builder.len()).unwrap());
+    }
+
+    /// Append an `Option` value into the builder.
+    #[inline]
+    pub fn append_option(&mut self, value: Option<impl AsRef<T::Native>>) {
+        match value {
+            None => self.append_null(),
+            Some(v) => self.append_value(v),
+        };
     }
 
     /// Append a null value into the builder.
     #[inline]
     pub fn append_null(&mut self) {
         self.null_buffer_builder.append(false);
         self.offsets_builder
-            .append(OffsetSize::from_usize(self.value_builder.len()).unwrap());
+            .append(T::Offset::from_usize(self.value_builder.len()).unwrap());
     }
 
-    /// Builds the [`GenericBinaryArray`] and reset this builder.
-    pub fn finish(&mut self) -> GenericBinaryArray<OffsetSize> {
-        let array_type = GenericBinaryArray::<OffsetSize>::DATA_TYPE;
+    /// Builds the [`GenericByteBuilder`] and reset this builder.

Review Comment:
   ```suggestion
       /// Builds the [`GenericByteArray`] and reset this builder.
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold merged pull request #3122: Add GenericByteBuilder (#2969)

Posted by GitBox <gi...@apache.org>.
tustvold merged PR #3122:
URL: https://github.com/apache/arrow-rs/pull/3122


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] ursabot commented on pull request #3122: Add GenericByteBuilder (#2969)

Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #3122:
URL: https://github.com/apache/arrow-rs/pull/3122#issuecomment-1322525631

   Benchmark runs are scheduled for baseline = 4c06f48de6b835be68f45dffa4b58510cd07bb78 and contender = b3dbe7011ace86c7ab46b1a15388f128bffb5f6d. b3dbe7011ace86c7ab46b1a15388f128bffb5f6d is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/9de170c6698d4f609e471423ead2c841...e4156782ac8f4e48a4c8d2d1b0393168/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/419eff071d4640a384040fdc715eb2ef...02bc3c6f3f4b4212bafc5db82e89e51f/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/ed735ea8631440a988d95a0ba6a6732c...9729ee88df464447a33529046845d35b/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/6937424fa45a4dd3ae94cec3182890d3...93d45f1ba08942ef8d69ded94d81ab54/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org