-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
224 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod bool; | ||
pub mod primitive; | ||
pub mod ree; | ||
pub mod r#struct; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use vortex::scalar::Scalar; | ||
use vortex_error::VortexResult; | ||
|
||
use crate::array::r#struct::StructArray; | ||
use crate::compute::{ArrayCompute, ScalarAtFn}; | ||
|
||
impl ArrayCompute for StructArray<'_> { | ||
fn scalar_at(&self) -> Option<&dyn ScalarAtFn> { | ||
Some(self) | ||
} | ||
} | ||
|
||
impl ScalarAtFn for StructArray<'_> { | ||
fn scalar_at(&self, _index: usize) -> VortexResult<Scalar> { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
mod compute; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
use vortex_error::{vortex_bail, VortexResult}; | ||
use vortex_schema::{DType, FieldNames}; | ||
|
||
use crate::impl_encoding; | ||
use crate::validity::ArrayValidity; | ||
use crate::visitor::{AcceptArrayVisitor, ArrayVisitor}; | ||
use crate::{Array, ArrayMetadata}; | ||
use crate::{ArrayData, TypedArrayData}; | ||
use crate::{ArrayView, ToArrayData}; | ||
|
||
impl_encoding!("vortex.struct", Struct); | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
pub struct StructMetadata { | ||
length: usize, | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct StructArray<'a> { | ||
dtype: &'a DType, | ||
// Note(ngates): for arrays with variable-length children, we don't want to | ||
// allocate a Vec<Array>, so instead we defer child access by storing a reference to the parts. | ||
parts: &'a dyn ArrayParts, | ||
length: usize, | ||
} | ||
|
||
impl<'a> StructArray<'a> { | ||
pub fn child(&'a self, idx: usize) -> Option<Array<'a>> { | ||
let DType::Struct(_, fields) = self.dtype() else { | ||
unreachable!() | ||
}; | ||
let dtype = fields.get(idx)?; | ||
self.parts.child(idx, dtype) | ||
} | ||
|
||
pub fn names(&self) -> &FieldNames { | ||
let DType::Struct(names, _fields) = self.dtype() else { | ||
unreachable!() | ||
}; | ||
names | ||
} | ||
|
||
pub fn fields(&self) -> &[DType] { | ||
let DType::Struct(_names, fields) = self.dtype() else { | ||
unreachable!() | ||
}; | ||
fields.as_slice() | ||
} | ||
|
||
pub fn ncolumns(&self) -> usize { | ||
self.fields().len() | ||
} | ||
|
||
pub fn len(&self) -> usize { | ||
self.length | ||
} | ||
} | ||
|
||
impl<'v> TryFromArrayParts<'v, StructMetadata> for StructArray<'v> { | ||
fn try_from_parts( | ||
parts: &'v dyn ArrayParts, | ||
metadata: &'v StructMetadata, | ||
) -> VortexResult<Self> { | ||
let DType::Struct(_names, dtypes) = parts.dtype() else { | ||
unreachable!() | ||
}; | ||
if parts.nchildren() != dtypes.len() { | ||
vortex_bail!( | ||
"Expected {} children, found {}", | ||
dtypes.len(), | ||
parts.nchildren() | ||
); | ||
} | ||
Ok(StructArray { | ||
dtype: parts.dtype(), | ||
parts, | ||
length: metadata.length, | ||
}) | ||
} | ||
} | ||
|
||
impl ArrayTrait for StructArray<'_> { | ||
fn dtype(&self) -> &DType { | ||
self.dtype | ||
} | ||
|
||
fn len(&self) -> usize { | ||
self.length | ||
} | ||
} | ||
|
||
impl ArrayValidity for StructArray<'_> { | ||
fn is_valid(&self, _index: usize) -> bool { | ||
todo!() | ||
} | ||
} | ||
|
||
impl ToArrayData for StructArray<'_> { | ||
fn to_array_data(&self) -> ArrayData { | ||
todo!() | ||
} | ||
} | ||
|
||
impl AcceptArrayVisitor for StructArray<'_> { | ||
fn accept(&self, visitor: &mut dyn ArrayVisitor) -> VortexResult<()> { | ||
for (idx, name) in self.names().iter().enumerate() { | ||
let child = self.child(idx).unwrap(); | ||
visitor.visit_column(name, &child)?; | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use arrow_buffer::Buffer; | ||
use vortex::serde::data::ArrayData; | ||
use vortex_error::VortexResult; | ||
use vortex_schema::DType; | ||
|
||
use crate::visitor::ArrayVisitor; | ||
use crate::Array; | ||
|
||
/// A column batch contains the flattened list of columns. | ||
pub struct ColumnBatch { | ||
dtype: DType, | ||
columns: Vec<Array<'static>>, | ||
} | ||
|
||
pub struct ColumnBatchBuilder { | ||
columns: Vec<ArrayData>, | ||
} | ||
|
||
impl ArrayVisitor for ColumnBatchBuilder { | ||
fn visit_column(&mut self, _name: &str, _array: &Array) -> VortexResult<()> { | ||
todo!() | ||
} | ||
|
||
fn visit_child(&mut self, _name: &str, _array: &Array) -> VortexResult<()> { | ||
// If the array is a struct, then pull out each column. | ||
// But we can't do this in case some non-column child is a struct. | ||
// Can we ask an array for column(idx)? Seems like a lot of work. | ||
todo!() | ||
} | ||
|
||
fn visit_buffer(&mut self, _buffer: &Buffer) -> VortexResult<()> { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.