pub struct BinColumnWriter<'a> { /* private fields */ }
Expand description

Fills a binary column buffer with elements from an Iterator. See crate::buffers::AnyColumnViewMut

Implementations

Fill the binary column with values by consuming the iterator and copying its items into the buffer. It will not extract more items from the iterator than the buffer may hold. This method panics if elements of the iterator are larger than the maximum element length of the buffer.

Changes the maximum element length the buffer can hold. This operation is useful if you find an unexpected large input during insertion. All values in the buffer will be set to NULL.

Parameters
  • new_max_len: New maximum element length

Maximum length

Changes the maximum element length the buffer can hold. This operation is useful if you find an unexpected large input during insertion.

This is however costly, as not only does the new buffer have to be allocated, but all values have to copied from the old to the new buffer.

This method could also be used to reduce the maximum element length, which would truncate values in the process.

This method does not adjust indicator buffers as these might hold values larger than the maximum element length.

Parameters
  • new_max_len: New maximum element length.
  • num_rows: Number of valid rows currently stored in this buffer.

Inserts a new element to the column buffer. Rebinds the buffer to increase maximum element length should the value be larger than the maximum allowed element length. The number of rows the column buffer can hold stays constant, but during rebind only values before index would be copied to the new memory location. Therefore this method is intended to be used to fill the buffer element-wise and in order. Hence the name append.

Parameters
  • index: Zero based index of the new row position. Must be equal to the number of rows currently in the buffer.
  • bytes: Value to store
Example
    BufferDescription, BufferKind, AnyColumnViewMut, AnyColumnView, buffer_from_description
};
let desc = BufferDescription {
    // Buffer size purposefully chosen too small, so we need to increase the buffer size if we
    // encounter larger inputs.
    kind: BufferKind::Binary { length: 1 },
    nullable: true,
};

// Input values to insert.
let input : [Option<&[u8]>; 5]= [
    Some(&[1]),
    Some(&[2,3]),
    Some(&[4,5,6]),
    None,
    Some(&[7,8,9,10,11,12]),
];

let mut buffer = buffer_from_description(input.len(), iter::once(desc));

buffer.set_num_rows(input.len());
if let AnyColumnViewMut::Binary(mut writer) = buffer.column_mut(0) {
    for (index, &bytes) in input.iter().enumerate() {
        writer.append(index, bytes)
    }
} else {
    panic!("Expected binary column writer");
}

let col_view = buffer.column(0).as_bin_view().expect("Expected binary column slice");
assert!(
    col_view
        .iter()
        .zip(input.iter().copied())
        .all(|(expected, actual)| expected == actual)
)

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.