risingwave_common::array

Trait ArrayBuilder

source
pub trait ArrayBuilder:
    Send
    + Sync
    + Sized
    + 'static {
    type ArrayType: Array<Builder = Self>;

    // Required methods
    fn new(capacity: usize) -> Self;
    fn with_type(capacity: usize, ty: DataType) -> Self;
    fn append_n(
        &mut self,
        n: usize,
        value: Option<<Self::ArrayType as Array>::RefItem<'_>>,
    );
    fn append_array(&mut self, other: &Self::ArrayType);
    fn pop(&mut self) -> Option<()>;
    fn len(&self) -> usize;
    fn finish(self) -> Self::ArrayType;

    // Provided methods
    fn append(&mut self, value: Option<<Self::ArrayType as Array>::RefItem<'_>>) { ... }
    fn append_owned(
        &mut self,
        value: Option<<Self::ArrayType as Array>::OwnedItem>,
    ) { ... }
    fn append_null(&mut self) { ... }
    fn append_array_element(&mut self, other: &Self::ArrayType, idx: usize) { ... }
    fn is_empty(&self) -> bool { ... }
}
Expand description

A trait over all array builders.

ArrayBuilder is a trait over all builders. You could build an array with append with the help of ArrayBuilder trait. The append function always accepts reference to an element if it is not primitive. e.g. for PrimitiveArray, you could do builder.append(Some(1)). For Utf8Array, you must do builder.append(Some("xxx")). Note that you don’t need to construct a String.

The associated type ArrayType is the type of the corresponding array. It is the return type of finish.

Required Associated Types§

source

type ArrayType: Array<Builder = Self>

Corresponding Array of this builder, which is reciprocal to ArrayBuilder.

Required Methods§

source

fn new(capacity: usize) -> Self

Create a new builder with capacity. TODO: remove this function from the trait. Let it be methods of each concrete builders.

source

fn with_type(capacity: usize, ty: DataType) -> Self

§Panics

Panics if meta’s type mismatches with the array type.

source

fn append_n( &mut self, n: usize, value: Option<<Self::ArrayType as Array>::RefItem<'_>>, )

Append a value multiple times.

This should be more efficient than calling append multiple times.

source

fn append_array(&mut self, other: &Self::ArrayType)

Append an array to builder.

source

fn pop(&mut self) -> Option<()>

Pop an element from the builder.

It’s used in rollback in source parser.

§Returns

Returns None if there is no elements in the builder.

source

fn len(&self) -> usize

Return the number of elements in the builder.

source

fn finish(self) -> Self::ArrayType

Finish build and return a new array.

Provided Methods§

source

fn append(&mut self, value: Option<<Self::ArrayType as Array>::RefItem<'_>>)

Append a value to builder.

source

fn append_owned(&mut self, value: Option<<Self::ArrayType as Array>::OwnedItem>)

Append an owned value to builder.

source

fn append_null(&mut self)

source

fn append_array_element(&mut self, other: &Self::ArrayType, idx: usize)

Append an element in another array into builder.

source

fn is_empty(&self) -> bool

Return true if the array has a length of 0.

Object Safety§

This trait is not object safe.

Implementors§