Skip to content

Commit

Permalink
Scaffolding to support generating arbitrary filter pipelines (#23)
Browse files Browse the repository at this point in the history
* Implement Filter with FilterData enum so we can derive PartialEq, Serialize, Deserialize

* Add proptest reflexive filter eq check

* Add test::filter::filter_list_arbitrary

* Datatype::is_real_type and is_byte_type

* Add FilterData::transform_datatype

* AttributeBuilder::filter_list consumes filter list

* Add FilterList::to_vec

* Arbitrary filter pipeline construction
  • Loading branch information
rroelke authored Mar 25, 2024
1 parent d1b95d1 commit db2c1e7
Show file tree
Hide file tree
Showing 14 changed files with 1,709 additions and 979 deletions.
2 changes: 1 addition & 1 deletion tiledb/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name = "tiledb"
path = "src/lib.rs"

[dependencies]
serde = "1.0.136"
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.114"
tiledb-sys = { workspace = true }

Expand Down
33 changes: 14 additions & 19 deletions tiledb/api/src/array/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ use std::fmt::{Debug, Formatter, Result as FmtResult};
use std::ops::Deref;

use serde_json::json;
pub use tiledb_sys::Datatype;

use crate::context::Context;
use crate::convert::{BitsEq, CAPIConverter};
use crate::error::Error;
use crate::filter_list::{FilterList, RawFilterList};
use crate::fn_typed;
use crate::Result as TileDBResult;
use crate::{Datatype, Result as TileDBResult};

pub(crate) enum RawAttribute {
Owned(*mut ffi::tiledb_attribute_t),
Expand Down Expand Up @@ -70,11 +69,7 @@ impl<'ctx> Attribute<'ctx> {
ffi::tiledb_attribute_get_type(c_context, *self.raw, &mut c_dtype)
};
if res == ffi::TILEDB_OK {
if let Some(dtype) = Datatype::from_u32(c_dtype) {
Ok(dtype)
} else {
Err(Error::from("Invalid Datatype value returned by TileDB"))
}
Datatype::try_from(c_dtype)
} else {
Err(self.context.expect_last_error())
}
Expand Down Expand Up @@ -238,13 +233,10 @@ impl<'ctx> Debug for Attribute<'ctx> {
} else {
None
},
/*
TODO
"filters": match self.filter_list() {
Ok(fl) => format!("{:?}", fl),
Err(e) => format!("<error reading filters: {}>", e)
},
*/
"raw": format!("{:p}", *self.raw)
});
write!(f, "{}", json)
Expand Down Expand Up @@ -274,15 +266,13 @@ impl<'c1, 'c2> PartialEq<Attribute<'c2>> for Attribute<'c1> {
return false;
}

/*
let filter_match = match (self.filter_list(), other.filter_list()) {
(Ok(mine), Ok(theirs)) => unimplemented!(),
(Ok(mine), Ok(theirs)) => mine == theirs,
_ => false,
};
if !filter_match {
return false;
}
*/

let cell_val_match = match (self.cell_val_num(), other.cell_val_num()) {
(Ok(mine), Ok(theirs)) => mine == theirs,
Expand Down Expand Up @@ -545,12 +535,17 @@ mod test {
{
let flist2 = FilterListBuilder::new(&ctx)
.expect("Error creating filter list builder.")
.add_filter(NoopFilterBuilder::new(&ctx)?.build())?
.add_filter(BitWidthReductionFilterBuilder::new(&ctx)?.build())?
.add_filter(
CompressionFilterBuilder::new(&ctx, CompressionType::Zstd)?
.build(),
)?
.add_filter(Filter::create(&ctx, FilterData::None)?)?
.add_filter(Filter::create(
&ctx,
FilterData::BitWidthReduction { max_window: None },
)?)?
.add_filter(Filter::create(
&ctx,
FilterData::Compression(CompressionData::new(
CompressionType::Zstd,
)),
)?)?
.build();

let attr = Builder::new(&ctx, "foo", Datatype::UInt8)
Expand Down
21 changes: 13 additions & 8 deletions tiledb/api/src/array/dimension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl<'ctx> Dimension<'ctx> {

assert_eq!(ffi::TILEDB_OK, c_ret);

Datatype::from_capi_enum(c_datatype)
Datatype::try_from(c_datatype).expect("Invalid dimension type")
}

pub fn domain<Conv: CAPIConverter>(&self) -> TileDBResult<[Conv; 2]> {
Expand Down Expand Up @@ -303,13 +303,12 @@ mod tests {
let domain: [i32; 2] = [1, 4];
let extent: i32 = 4;
let fl = FilterListBuilder::new(&context)?
.add_filter(
CompressionFilterBuilder::new(
&context,
.add_filter(Filter::create(
&context,
FilterData::Compression(CompressionData::new(
CompressionType::Lz4,
)?
.build(),
)?
)),
)?)?
.build();
let dimension: Dimension = Builder::new::<i32>(
&context,
Expand All @@ -327,7 +326,13 @@ mod tests {
assert_eq!(1, fl.get_num_filters().unwrap());

let outlz4 = fl.get_filter(0).unwrap();
assert_eq!(ffi::FilterType::Lz4, outlz4.get_type().unwrap());
match outlz4.filter_data().expect("Error reading filter data") {
FilterData::Compression(CompressionData {
kind: CompressionType::Lz4,
..
}) => (),
_ => unreachable!(),
}
}

Ok(())
Expand Down
Loading

0 comments on commit db2c1e7

Please sign in to comment.