askoa commented on code in PR #3553: URL: https://github.com/apache/arrow-rs/pull/3553#discussion_r1083979913
########## arrow-array/src/builder/generic_byte_ree_array_builder.rs: ########## @@ -0,0 +1,423 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use crate::{ + types::{ + ArrowRunEndIndexType, BinaryType, ByteArrayType, LargeBinaryType, LargeUtf8Type, + Utf8Type, + }, + ArrowPrimitiveType, RunEndEncodedArray, +}; + +use super::{GenericByteBuilder, PrimitiveBuilder}; + +use arrow_buffer::ArrowNativeType; +use arrow_schema::ArrowError; + +/// Array builder for [`RunEndEncodedArray`] for String and Binary types. +/// +/// # Example: +/// +/// ``` +/// +/// # use arrow_array::builder::GenericByteREEArrayBuilder; +/// # use arrow_array::{GenericByteArray, BinaryArray}; +/// # use arrow_array::types::{BinaryType, Int16Type}; +/// # use arrow_array::{Array, Int16Array}; +/// +/// let mut builder = +/// GenericByteREEArrayBuilder::<Int16Type, BinaryType>::new(); +/// builder.append_value(b"abc").unwrap(); +/// builder.append_value(b"abc").unwrap(); +/// builder.append_null().unwrap(); +/// builder.append_value(b"def").unwrap(); +/// let array = builder.finish(); +/// +/// assert_eq!( +/// array.run_ends(), +/// &Int16Array::from(vec![Some(2), Some(3), Some(4)]) +/// ); +/// +/// let av = array.values(); +/// +/// assert!(!av.is_null(0)); +/// assert!(av.is_null(1)); +/// assert!(!av.is_null(2)); +/// +/// // Values are polymorphic and so require a downcast. +/// let ava: &BinaryArray = av.as_any().downcast_ref::<BinaryArray>().unwrap(); +/// +/// assert_eq!(ava.value(0), b"abc"); +/// assert_eq!(ava.value(2), b"def"); +/// ``` +#[derive(Debug)] +pub struct GenericByteREEArrayBuilder<R, V> +where + R: ArrowPrimitiveType, + V: ByteArrayType, +{ + run_ends_builder: PrimitiveBuilder<R>, + values_builder: GenericByteBuilder<V>, + current_value: Option<Vec<u8>>, Review Comment: On the second thought, the byte array builders are not designed to use something like `V::Owned`. For e.g. the function `values_slice` returns `&[u8]` and not `&[V::Owned]`. I don't see why we need to introduce the constraint in this case. When we are building byte builder what's wrong with storing as bytes? I am not planning to make any change for this suggestion. -- 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]
