Skip to content

Refactor: Extract helper functions to reduce sync/async duplication (Phase 1)#13

Merged
jayendra13 merged 1 commit into
mainfrom
refactor/phase1-extract-helpers
Feb 4, 2026
Merged

Refactor: Extract helper functions to reduce sync/async duplication (Phase 1)#13
jayendra13 merged 1 commit into
mainfrom
refactor/phase1-extract-helpers

Conversation

@jayendra13
Copy link
Copy Markdown
Owner

Summary

Phase 1 of refactoring to eliminate duplicated code between sync and async Zarr reading paths.

  • Extract apply_cf_time_conversion() helper to cf_time.rs for CF time conversion logic
  • Add helper functions in zarr_reader.rs to consolidate repeated patterns:
    • create_empty_result_stream() - Empty result stream for unmatched filters
    • build_projected_schema() - Schema building with coordinate filtering
    • coord_values_to_refs() - CoordValues to CoordValuesRef conversion
    • calculate_effective_sizes() - Filter-based size calculation
    • extract_filtered_coords() - Coordinate value extraction with ranges
    • calculate_query_coord_sizes() - Mixed-dimensionality size calculation
    • create_result_batch() - Final batch creation with empty projection handling
    • apply_limit_to_arrays() - Limit application to result arrays

Impact

  • Net change: -2 lines (283 additions, 285 deletions)
  • Improved maintainability: sync and async paths now share common logic
  • No functional changes - all tests pass

Test plan

  • cargo test - All tests pass
  • cargo clippy - No warnings
  • cargo fmt - Properly formatted

Part of #5

Phase 1 of refactoring to eliminate duplicated code between sync and async
Zarr reading paths.

Extracted helpers:
- apply_cf_time_conversion(): CF time conversion logic (cf_time.rs)
- create_empty_result_stream(): Empty result stream for unmatched filters
- build_projected_schema(): Schema building with coordinate filtering
- coord_values_to_refs(): CoordValues to CoordValuesRef conversion
- calculate_effective_sizes(): Filter-based size calculation
- extract_filtered_coords(): Coordinate value extraction with ranges
- calculate_query_coord_sizes(): Mixed-dimensionality size calculation
- create_result_batch(): Final batch creation with empty projection handling
- apply_limit_to_arrays(): Limit application to result arrays

Impact: Net reduction of ~2 lines with significantly improved maintainability.
The sync and async paths now share common logic through these helpers.

Part of: #5
@jayendra13 jayendra13 merged commit 474454b into main Feb 4, 2026
1 of 3 checks passed
@jayendra13 jayendra13 deleted the refactor/phase1-extract-helpers branch February 4, 2026 01:31
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.

1 participant