Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions vortex-array/src/dtype/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ pub(crate) fn draw_ptype(tc: &TestCase) -> PType {

/// Draws a [`DType`] with at most `depth` levels of nested containers.
///
/// Structs and unions have one to three children. Map keys are non-nullable primitives.
/// Structs and unions have one to three children. Map keys are non-nullable child dtypes.
/// Extension dtypes are not drawn, because they need a registered extension.
pub(crate) fn draw_dtype(tc: &TestCase, depth: u8) -> DType {
let kinds = if depth == 0 { 7 } else { 12 };
let kinds = if depth == 0 { 8 } else { 13 };
let nullability = Nullability::from(tc.draw(gs::booleans()));
let child = || draw_dtype(tc, depth - 1);
let width = || tc.draw(gs::integers::<usize>().min_value(1).max_value(3));
Expand All @@ -55,24 +55,28 @@ pub(crate) fn draw_dtype(tc: &TestCase, depth: u8) -> DType {
}
4 => DType::Utf8(nullability),
5 => DType::Binary(nullability),
6 => DType::Variant(nullability),
7 => DType::List(Arc::new(child()), nullability),
8 => DType::FixedSizeList(
6 => DType::FixedSizeBinary(tc.draw(gs::integers::<u32>()), nullability),
7 => DType::Variant(nullability),
8 => DType::List(Arc::new(child()), nullability),
9 => DType::FixedSizeList(
Arc::new(child()),
tc.draw(gs::integers::<u32>()),
nullability,
),
9 => DType::struct_(
10 => DType::struct_(
(0..width()).map(|i| (format!("f{i}"), child())),
nullability,
),
10 => DType::map(
DType::Primitive(draw_ptype(tc), Nullability::NonNullable),
child(),
tc.draw(gs::booleans()),
nullability,
)
.vortex_expect("map keys are non-nullable"),
11 => {
let raw_key = child();
let key = if matches!(raw_key, DType::Null) {
DType::Bool(Nullability::NonNullable)
} else {
raw_key.as_nonnullable()
};
DType::map(key, child(), tc.draw(gs::booleans()), nullability)
.vortex_expect("map keys are non-nullable")
}
_ => {
let n = width();
DType::Union(
Expand Down
58 changes: 0 additions & 58 deletions vortex-array/src/dtype/serde/flatbuffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,6 @@ impl TryFrom<fb::PType> for PType {

#[cfg(test)]
mod test {
use std::sync::Arc;

use flatbuffers::FlatBufferBuilder;
use flatbuffers::WIPOffset;
use flatbuffers::root;
Expand Down Expand Up @@ -792,62 +790,6 @@ mod test {
assert_eq!(dtype, deserialized);
}

#[test]
fn roundtrip() {
roundtrip_dtype(DType::Null);
roundtrip_dtype(DType::Bool(Nullability::NonNullable));
roundtrip_dtype(DType::Primitive(PType::U8, Nullability::NonNullable));
roundtrip_dtype(DType::Primitive(PType::U16, Nullability::NonNullable));
roundtrip_dtype(DType::Primitive(PType::U32, Nullability::NonNullable));
roundtrip_dtype(DType::Primitive(PType::U64, Nullability::NonNullable));
roundtrip_dtype(DType::Primitive(PType::I8, Nullability::NonNullable));
roundtrip_dtype(DType::Primitive(PType::I16, Nullability::NonNullable));
roundtrip_dtype(DType::Primitive(PType::I32, Nullability::NonNullable));
roundtrip_dtype(DType::Primitive(PType::I64, Nullability::NonNullable));
roundtrip_dtype(DType::Primitive(PType::F16, Nullability::NonNullable));
roundtrip_dtype(DType::Primitive(PType::F32, Nullability::NonNullable));
roundtrip_dtype(DType::Primitive(PType::F64, Nullability::NonNullable));
roundtrip_dtype(DType::Binary(Nullability::NonNullable));
roundtrip_dtype(DType::FixedSizeBinary(16, Nullability::NonNullable));
roundtrip_dtype(DType::FixedSizeBinary(0, Nullability::Nullable));
roundtrip_dtype(DType::Utf8(Nullability::NonNullable));
roundtrip_dtype(DType::List(
Arc::new(DType::Primitive(PType::F32, Nullability::Nullable)),
Nullability::NonNullable,
));
roundtrip_dtype(DType::FixedSizeList(
Arc::new(DType::Primitive(PType::F32, Nullability::Nullable)),
2,
Nullability::NonNullable,
));
roundtrip_dtype(DType::Struct(
StructFields::new(
["strings", "ints"].into(),
vec![
DType::Utf8(Nullability::NonNullable),
DType::Primitive(PType::U16, Nullability::Nullable),
],
),
Nullability::NonNullable,
));
let inner_map = DType::map(
DType::Primitive(PType::I32, Nullability::NonNullable),
DType::Utf8(Nullability::Nullable),
true,
Nullability::NonNullable,
)
.unwrap();
let map = DType::map(
inner_map,
DType::Utf8(Nullability::Nullable),
false,
Nullability::Nullable,
)
.unwrap();
roundtrip_dtype(DType::struct_([("map", map)], Nullability::NonNullable));
roundtrip_dtype(DType::Variant(Nullability::Nullable));
}

#[test]
fn equal_subtrees_are_written_once() -> VortexResult<()> {
let leaf = DType::Primitive(PType::I64, Nullability::NonNullable);
Expand Down
3 changes: 3 additions & 0 deletions vortex-array/src/dtype/serde/flatbuffers/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ impl DTypeVerifier<'_> {
fb::Type::Binary => {
required(dtype.type__as_binary(), "binary")?;
}
fb::Type::FixedSizeBinary => {
required(dtype.type__as_fixed_size_binary(), "fixed-size binary")?;
}
fb::Type::Variant => {
required(dtype.type__as_variant(), "variant")?;
}
Expand Down
Loading
Loading