diff --git a/vortex-dict/src/compute.rs b/vortex-dict/src/compute.rs index 1d435d71a1..ef26882dd9 100644 --- a/vortex-dict/src/compute.rs +++ b/vortex-dict/src/compute.rs @@ -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}; diff --git a/vortex-ree/src/ree.rs b/vortex-ree/src/ree.rs index 414431cef1..e80b67d012 100644 --- a/vortex-ree/src/ree.rs +++ b/vortex-ree/src/ree.rs @@ -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; diff --git a/vortex-scalar/src/bool.rs b/vortex-scalar/src/bool.rs index f84cf9e8a0..c069750487 100644 --- a/vortex-scalar/src/bool.rs +++ b/vortex-scalar/src/bool.rs @@ -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; diff --git a/vortex-scalar/src/extension.rs b/vortex-scalar/src/extension.rs index 52d6dcc37f..18bb247927 100644 --- a/vortex-scalar/src/extension.rs +++ b/vortex-scalar/src/extension.rs @@ -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; diff --git a/vortex-scalar/src/lib.rs b/vortex-scalar/src/lib.rs index 643dc07fbc..429640e477 100644 --- a/vortex-scalar/src/lib.rs +++ b/vortex-scalar/src/lib.rs @@ -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; diff --git a/vortex-scalar/src/primitive.rs b/vortex-scalar/src/primitive.rs index 039e387783..d739458d21 100644 --- a/vortex-scalar/src/primitive.rs +++ b/vortex-scalar/src/primitive.rs @@ -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}; @@ -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; diff --git a/vortex-scalar/src/serde.rs b/vortex-scalar/src/serde.rs index 7331a6c264..1c990195cd 100644 --- a/vortex-scalar/src/serde.rs +++ b/vortex-scalar/src/serde.rs @@ -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}; @@ -109,10 +109,11 @@ impl WriteFlatBuffer for Scalar { } } -impl TryFrom> for Scalar { +impl ReadFlatBuffer for Scalar { + type Source<'a> = fb::Scalar<'a>; type Error = VortexError; - fn try_from(fb: fb::Scalar<'_>) -> Result { + fn read_flatbuffer(fb: &Self::Source<'_>) -> Result { let nullability = Nullability::from(fb.nullability()); match fb.type_type() { fb::Type::Binary => { @@ -179,7 +180,7 @@ impl<'de> Visitor<'de> for ScalarDeserializer { E: serde::de::Error, { let fb = root::(v).map_err(E::custom)?; - Scalar::try_from(fb).map_err(E::custom) + Scalar::read_flatbuffer(&fb).map_err(E::custom) } } @@ -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 { +// let bytes = self.reader.read_slice()?; +// let scalar = root::(&bytes) +// .map_err(|_e| VortexError::InvalidArgument("Invalid FlatBuffer".into())) +// .unwrap(); + +// } +// +// fn read_primitive_scalar(&mut self) -> VortexResult { +// 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)) +// } +// } +// } diff --git a/vortex-scalar/src/struct_.rs b/vortex-scalar/src/struct_.rs index eff79fd0d1..d52e5f771f 100644 --- a/vortex-scalar/src/struct_.rs +++ b/vortex-scalar/src/struct_.rs @@ -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; diff --git a/vortex-scalar/src/utf8.rs b/vortex-scalar/src/utf8.rs index 06383116ac..b3923f8ffd 100644 --- a/vortex-scalar/src/utf8.rs +++ b/vortex-scalar/src/utf8.rs @@ -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;