Skip to content

Features/chunked nc reader - #98

Merged
robinskil merged 3 commits into
mainfrom
features/chunked-nc-reader
Oct 6, 2025
Merged

robinskil merged 3 commits into
mainfrom
features/chunked-nc-reader

Conversation

@robinskil

Copy link
Copy Markdown
Collaborator

Support chunked reading for netcdf files

@robinskil robinskil self-assigned this Oct 6, 2025
Copilot AI review requested due to automatic review settings October 6, 2025 13:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for chunked reading of netCDF files, enabling streaming access to large datasets by reading data in configurable chunks rather than loading entire files into memory at once.

  • Introduces a new Stream struct that implements both synchronous and asynchronous iteration over netCDF data chunks
  • Adds flexible chunking strategies including automatic balancing, custom chunk sizes, and no chunking
  • Refactors the existing reader to use the new streaming infrastructure while maintaining backward compatibility

Reviewed Changes

Copilot reviewed 8 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
beacon-arrow-netcdf/src/reader.rs Refactored to use Arc for thread safety, added streaming methods, and updated variable reading to support chunked access
beacon-arrow-netcdf/src/chunked_stream.rs New module implementing the core streaming functionality with chunking logic and dimension validation
beacon-arrow-netcdf/src/nc_array.rs Added convenience constructor for Dimension struct
beacon-arrow-netcdf/src/lib.rs Added chunked_stream module export
beacon-arrow-netcdf/src/error.rs Added Stream and Reader error variants
beacon-arrow-netcdf/Cargo.toml Added futures and serde dependencies
beacon-api/Cargo.toml Fixed jemalloc dependency to be platform-specific
Cargo.toml Added derive feature to serde and serde feature to indexmap

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +42 to +51
file.dimensions().try_for_each(|dim| {
if dimensions.contains(&dim.name().to_string()) {
Ok(())
} else {
Err(ArrowNetCDFError::Reader(format!(
"Dimension '{}' not found in NetCDF file.",
dim.name()
)))
}
})?;

Copilot AI Oct 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic is inverted - this should check if the provided dimensions exist in the file, not if file dimensions exist in the provided list. Currently it will error when the file has dimensions not in the input list, rather than when input dimensions don't exist in the file.

Suggested change
file.dimensions().try_for_each(|dim| {
if dimensions.contains(&dim.name().to_string()) {
Ok(())
} else {
Err(ArrowNetCDFError::Reader(format!(
"Dimension '{}' not found in NetCDF file.",
dim.name()
)))
}
})?;
let file_dimension_names: Vec<String> = file
.dimensions()
.map(|dim| dim.name().to_string())
.collect();
for dim in &dimensions {
if !file_dimension_names.contains(dim) {
return Err(ArrowNetCDFError::Reader(format!(
"Provided dimension '{}' not found in NetCDF file.",
dim
)));
}
}

Copilot uses AI. Check for mistakes.
Comment on lines +84 to +85
// Also remove variable attributes if the parent variable is removed
|| (field_name.contains('.') && {

Copilot AI Oct 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic on line 84-89 is incorrect. The condition should retain fields that are NOT in removable_variables AND retain attribute fields whose parent variables are NOT removed. The current logic uses || where it should use &&, and the second condition has incorrect negation.

Suggested change
// Also remove variable attributes if the parent variable is removed
|| (field_name.contains('.') && {
// Also remove variable attributes only if the parent variable is not removed
&& (!field_name.contains('.') || {

Copilot uses AI. Check for mistakes.
Comment on lines +220 to 222
{
fill_value = read_fill_value_attribute(&$var)?.and_then(|fv| fv.$as_ref())
}

Copilot AI Oct 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The braces around this single statement are unnecessary and reduce code readability.

Suggested change
{
fill_value = read_fill_value_attribute(&$var)?.and_then(|fv| fv.$as_ref())
}
fill_value = read_fill_value_attribute(&$var)?.and_then(|fv| fv.$as_ref())

Copilot uses AI. Check for mistakes.
Comment on lines +316 to +320
println!(
"Reading variable {} with hyper slab: {:?}",
variable.name(),
hyper_slab
);

Copilot AI Oct 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statements should not be left in production code. Consider using a proper logging framework or removing this statement.

Copilot uses AI. Check for mistakes.
@robinskil
robinskil merged commit edff25b into main Oct 6, 2025
1 check passed
robinskil added a commit that referenced this pull request Oct 13, 2025
* init

* wip chunked stream

* wip chunked reader
@robinskil
robinskil deleted the features/chunked-nc-reader branch October 22, 2025 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants