Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One dim reads #22

Closed
wants to merge 3 commits into from
Closed
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
93 changes: 58 additions & 35 deletions src/async_reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ where
&cols,
self.meta.get_real_dims(pos),
self.meta.get_chunk_patterns(),
self.meta.get_one_dim_repr_meta(),
)
.await;

Expand Down Expand Up @@ -757,39 +758,8 @@ mod zarr_async_reader_tests {
assert!(matched);
}

#[tokio::test]
async fn projection_tests() {
let zp = get_v2_test_data_path("compression_example.zarr".to_string());
let proj = ZarrProjection::keep(vec!["bool_data".to_string(), "int_data".to_string()]);
let stream_builder = ZarrRecordBatchStreamBuilder::new(zp).with_projection(proj);

let stream = stream_builder.build().await.unwrap();
let records: Vec<_> = stream.try_collect().await.unwrap();

let target_types = HashMap::from([
("bool_data".to_string(), DataType::Boolean),
("int_data".to_string(), DataType::Int64),
]);

// center chunk
let rec = &records[4];
validate_names_and_types(&target_types, rec);
validate_bool_column(
"bool_data",
rec,
&[false, true, false, false, true, false, false, true, false],
);
validate_primitive_column::<Int64Type, i64>(
"int_data",
rec,
&[-4, -3, -2, 4, 5, 6, 12, 13, 14],
);
}

#[tokio::test]
async fn filters_tests() {
// set the filters to select part of the raster, based on lat and
// lon coordinates.
// create a test filter
fn create_filter() -> ZarrChunkFilter {
let mut filters: Vec<Box<dyn ZarrArrowPredicate>> = Vec::new();
let f = ZarrArrowPredicateFn::new(
ZarrProjection::keep(vec!["lat".to_string()]),
Expand Down Expand Up @@ -822,9 +792,42 @@ mod zarr_async_reader_tests {
);
filters.push(Box::new(f));

ZarrChunkFilter::new(filters)
}

#[tokio::test]
async fn projection_tests() {
let zp = get_v2_test_data_path("compression_example.zarr".to_string());
let proj = ZarrProjection::keep(vec!["bool_data".to_string(), "int_data".to_string()]);
let stream_builder = ZarrRecordBatchStreamBuilder::new(zp).with_projection(proj);

let stream = stream_builder.build().await.unwrap();
let records: Vec<_> = stream.try_collect().await.unwrap();

let target_types = HashMap::from([
("bool_data".to_string(), DataType::Boolean),
("int_data".to_string(), DataType::Int64),
]);

// center chunk
let rec = &records[4];
validate_names_and_types(&target_types, rec);
validate_bool_column(
"bool_data",
rec,
&[false, true, false, false, true, false, false, true, false],
);
validate_primitive_column::<Int64Type, i64>(
"int_data",
rec,
&[-4, -3, -2, 4, 5, 6, 12, 13, 14],
);
}

#[tokio::test]
async fn filters_tests() {
let zp = get_v2_test_data_path("lat_lon_example.zarr".to_string());
let stream_builder =
ZarrRecordBatchStreamBuilder::new(zp).with_filter(ZarrChunkFilter::new(filters));
let stream_builder = ZarrRecordBatchStreamBuilder::new(zp).with_filter(create_filter());
let stream = stream_builder.build().await.unwrap();
let records: Vec<_> = stream.try_collect().await.unwrap();

Expand Down Expand Up @@ -867,6 +870,26 @@ mod zarr_async_reader_tests {
);
}

#[tokio::test]
async fn one_dim_repr_tests() {
let zp = get_v2_test_data_path("lat_lon_example_w_1d_repr.zarr".to_string());
let stream_builder = ZarrRecordBatchStreamBuilder::new(zp).with_filter(create_filter());

let stream = stream_builder.build().await.unwrap();
let records_from_one_d_repr: Vec<_> = stream.try_collect().await.unwrap();

let zp = get_v2_test_data_path("lat_lon_example.zarr".to_string());
let stream_builder = ZarrRecordBatchStreamBuilder::new(zp).with_filter(create_filter());

let stream = stream_builder.build().await.unwrap();
let records: Vec<_> = stream.try_collect().await.unwrap();

assert_eq!(records_from_one_d_repr.len(), records.len());
for (rec, rec_from_one_d_repr) in records.iter().zip(records_from_one_d_repr.iter()) {
assert_eq!(rec, rec_from_one_d_repr);
}
}

#[tokio::test]
async fn multiple_readers_tests() {
let zp = get_v2_test_data_path("compression_example.zarr".to_string());
Expand Down
Loading