vortex_serde/layouts/read/
mod.rsuse std::fmt::Debug;
use arrow_buffer::BooleanBuffer;
use vortex::array::BoolArray;
use vortex::validity::Validity;
use vortex::{Array, IntoArray as _, IntoArrayVariant as _};
use vortex_error::VortexResult;
mod batch;
mod buffered;
mod builder;
mod cache;
mod context;
mod filtering;
mod footer;
mod layouts;
mod recordbatchreader;
mod stream;
pub use builder::LayoutReaderBuilder;
pub use cache::LayoutMessageCache;
pub use context::*;
pub use filtering::RowFilter;
pub use footer::LayoutDescriptorReader;
pub use recordbatchreader::{AsyncRuntime, VortexRecordBatchReader};
pub use stream::LayoutBatchStream;
pub use vortex_schema::projection::Projection;
pub use vortex_schema::Schema;
use crate::stream_writer::ByteRange;
pub const INITIAL_READ_SIZE: usize = 8 * 1024 * 1024;
pub const DEFAULT_BATCH_SIZE: usize = 65536;
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct Scan {
indices: Option<Array>,
projection: Projection,
filter: Option<RowFilter>,
batch_size: usize,
}
pub type LayoutPartId = u16;
pub type MessageId = Vec<LayoutPartId>;
pub type Message = (MessageId, ByteRange);
#[derive(Debug)]
pub enum ReadResult {
ReadMore(Vec<Message>),
Batch(Array),
}
pub trait LayoutReader: Debug + Send {
fn read_next(&mut self) -> VortexResult<Option<ReadResult>>;
}
pub fn null_as_false(array: BoolArray) -> VortexResult<Array> {
Ok(match array.validity() {
Validity::NonNullable => array.into_array(),
Validity::AllValid => {
BoolArray::try_new(array.boolean_buffer(), Validity::NonNullable)?.into_array()
}
Validity::AllInvalid => BoolArray::from(BooleanBuffer::new_unset(array.len())).into_array(),
Validity::Array(v) => {
let bool_buffer = &array.boolean_buffer() & &v.into_bool()?.boolean_buffer();
BoolArray::from(bool_buffer).into_array()
}
})
}
#[cfg(test)]
mod tests {
use vortex::array::BoolArray;
use vortex::validity::Validity;
use vortex::IntoArrayVariant;
use super::*;
#[test]
fn coerces_nulls() {
let bool_array = BoolArray::from_vec(
vec![true, true, false, false],
Validity::Array(BoolArray::from(vec![true, false, true, false]).into()),
);
let non_null_array = null_as_false(bool_array).unwrap().into_bool().unwrap();
assert_eq!(
non_null_array.boolean_buffer().iter().collect::<Vec<_>>(),
vec![true, false, false, false]
);
}
}