Skip to content

Commit

Permalink
Add Prost
Browse files Browse the repository at this point in the history
  • Loading branch information
gatesn committed May 4, 2024
1 parent d9db497 commit a43e88f
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 23 deletions.
3 changes: 1 addition & 2 deletions vortex-dict/src/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ mod test {
use vortex::array::primitive::PrimitiveArray;
use vortex::array::varbin::VarBinArray;
use vortex::{IntoArray, ToArray};
use vortex_dtype::DType;
use vortex_dtype::Nullability;
use vortex_dtype::{DType, Nullability};

use crate::{dict_encode_typed_primitive, dict_encode_varbin, DictArray};

Expand Down
3 changes: 1 addition & 2 deletions vortex-ree/src/ree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ mod test {
use vortex::compute::slice::slice;
use vortex::validity::Validity;
use vortex::{ArrayDType, ArrayTrait, IntoArray};
use vortex_dtype::Nullability;
use vortex_dtype::{DType, PType};
use vortex_dtype::{DType, Nullability, PType};

use crate::REEArray;

Expand Down
3 changes: 1 addition & 2 deletions vortex-scalar/src/bool.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::fmt::{Display, Formatter};

use vortex_dtype::DType;
use vortex_dtype::Nullability;
use vortex_dtype::{DType, Nullability};
use vortex_error::{vortex_bail, vortex_err, VortexError, VortexResult};

use crate::value::ScalarValue;
Expand Down
3 changes: 1 addition & 2 deletions vortex-scalar/src/extension.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::fmt::{Display, Formatter};
use std::sync::Arc;

use vortex_dtype::Nullability;
use vortex_dtype::{DType, ExtDType, ExtID, ExtMetadata};
use vortex_dtype::{DType, ExtDType, ExtID, ExtMetadata, Nullability};
use vortex_error::{vortex_bail, VortexResult};

use crate::Scalar;
Expand Down
3 changes: 1 addition & 2 deletions vortex-scalar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ pub use null::*;
pub use primitive::*;
pub use struct_::*;
pub use utf8::*;
use vortex_dtype::DType;
use vortex_dtype::NativePType;
use vortex_dtype::Nullability;
use vortex_dtype::{DType, Nullability};
use vortex_error::VortexResult;

mod binary;
Expand Down
6 changes: 2 additions & 4 deletions vortex-scalar/src/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use std::mem::size_of;

use num_traits::identities::Zero;
use vortex_dtype::half::f16;
use vortex_dtype::DType;
use vortex_dtype::Nullability;
use vortex_dtype::{match_each_integer_ptype, match_each_native_ptype};
use vortex_dtype::{DType, Nullability};
use vortex_dtype::{NativePType, PType};
use vortex_error::{vortex_bail, vortex_err, VortexError, VortexResult};

Expand Down Expand Up @@ -411,9 +410,8 @@ impl Display for PScalar {

#[cfg(test)]
mod test {
use vortex_dtype::DType;
use vortex_dtype::Nullability;
use vortex_dtype::PType;
use vortex_dtype::{DType, Nullability};
use vortex_error::VortexError;

use crate::Scalar;
Expand Down
66 changes: 61 additions & 5 deletions vortex-scalar/src/serde.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#![cfg(feature = "serde")]
#![cfg(feature = "flatbuffers")]
#[cfg(feature = "flatbuffers")]
use flatbuffers::{root, FlatBufferBuilder, WIPOffset};
use serde::de::Visitor;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use vortex_dtype::match_each_native_ptype;
use vortex_dtype::Nullability;
use vortex_error::{vortex_bail, VortexError};
use vortex_flatbuffers::{FlatBufferRoot, FlatBufferToBytes, WriteFlatBuffer};
use vortex_flatbuffers::{FlatBufferRoot, FlatBufferToBytes, ReadFlatBuffer, WriteFlatBuffer};

use crate::flatbuffers::scalar as fb;
use crate::{PScalar, PrimitiveScalar, Scalar, Utf8Scalar};
Expand Down Expand Up @@ -109,10 +109,11 @@ impl WriteFlatBuffer for Scalar {
}
}

impl TryFrom<fb::Scalar<'_>> for Scalar {
impl ReadFlatBuffer for Scalar {
type Source<'a> = fb::Scalar<'a>;
type Error = VortexError;

fn try_from(fb: fb::Scalar<'_>) -> Result<Self, Self::Error> {
fn read_flatbuffer(fb: &Self::Source<'_>) -> Result<Self, Self::Error> {
let nullability = Nullability::from(fb.nullability());
match fb.type_type() {
fb::Type::Binary => {
Expand Down Expand Up @@ -179,7 +180,7 @@ impl<'de> Visitor<'de> for ScalarDeserializer {
E: serde::de::Error,
{
let fb = root::<fb::Scalar>(v).map_err(E::custom)?;
Scalar::try_from(fb).map_err(E::custom)
Scalar::read_flatbuffer(&fb).map_err(E::custom)
}
}

Expand All @@ -192,3 +193,58 @@ impl<'de> Deserialize<'de> for Scalar {
deserializer.deserialize_bytes(ScalarDeserializer)
}
}

// impl<'a, 'b> ScalarReader<'a, 'b> {
// pub fn read(&mut self) -> VortexResult<Scalar> {
// let bytes = self.reader.read_slice()?;
// let scalar = root::<scalar::Scalar>(&bytes)
// .map_err(|_e| VortexError::InvalidArgument("Invalid FlatBuffer".into()))
// .unwrap();

// }
//
// fn read_primitive_scalar(&mut self) -> VortexResult<PrimitiveScalar> {
// let ptype = self.reader.ptype()?;
// let is_present = self.reader.read_option_tag()?;
// if is_present {
// let pscalar = match ptype {
// PType::U8 => PrimitiveScalar::some(PScalar::U8(u8::from_le_bytes(
// self.reader.read_nbytes()?,
// ))),
// PType::U16 => PrimitiveScalar::some(PScalar::U16(u16::from_le_bytes(
// self.reader.read_nbytes()?,
// ))),
// PType::U32 => PrimitiveScalar::some(PScalar::U32(u32::from_le_bytes(
// self.reader.read_nbytes()?,
// ))),
// PType::U64 => PrimitiveScalar::some(PScalar::U64(u64::from_le_bytes(
// self.reader.read_nbytes()?,
// ))),
// PType::I8 => PrimitiveScalar::some(PScalar::I8(i8::from_le_bytes(
// self.reader.read_nbytes()?,
// ))),
// PType::I16 => PrimitiveScalar::some(PScalar::I16(i16::from_le_bytes(
// self.reader.read_nbytes()?,
// ))),
// PType::I32 => PrimitiveScalar::some(PScalar::I32(i32::from_le_bytes(
// self.reader.read_nbytes()?,
// ))),
// PType::I64 => PrimitiveScalar::some(PScalar::I64(i64::from_le_bytes(
// self.reader.read_nbytes()?,
// ))),
// PType::F16 => PrimitiveScalar::some(PScalar::F16(f16::from_le_bytes(
// self.reader.read_nbytes()?,
// ))),
// PType::F32 => PrimitiveScalar::some(PScalar::F32(f32::from_le_bytes(
// self.reader.read_nbytes()?,
// ))),
// PType::F64 => PrimitiveScalar::some(PScalar::F64(f64::from_le_bytes(
// self.reader.read_nbytes()?,
// ))),
// };
// Ok(pscalar)
// } else {
// Ok(PrimitiveScalar::none(ptype))
// }
// }
// }
3 changes: 1 addition & 2 deletions vortex-scalar/src/struct_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use std::cmp::Ordering;
use std::fmt::{Display, Formatter};

use itertools::Itertools;
use vortex_dtype::Nullability;
use vortex_dtype::{DType, FieldNames, StructDType};
use vortex_dtype::{DType, FieldNames, Nullability, StructDType};
use vortex_error::{vortex_bail, vortex_err, VortexResult};

use crate::Scalar;
Expand Down
3 changes: 1 addition & 2 deletions vortex-scalar/src/utf8.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::fmt::{Display, Formatter};

use vortex_dtype::DType;
use vortex_dtype::Nullability::{NonNullable, Nullable};
use vortex_dtype::{DType, Nullability::NonNullable, Nullability::Nullable};
use vortex_error::{vortex_bail, vortex_err, VortexError, VortexResult};

use crate::value::ScalarValue;
Expand Down

0 comments on commit a43e88f

Please sign in to comment.