feat(rust/sedona-raster): add ViewEntries view-spec module - #934
Conversation
Introduce the ViewEntries newtype over Vec<ViewEntry> with the view machinery — validation, identity check, visible-shape derivation, and composition — plus the view_entries! construction macro. Move ViewEntry into the module and re-export it from traits so existing import paths keep working. Pure, allocation-light spec logic with unit tests; no behavior change to band construction or reads yet.
paleolimbot
left a comment
There was a problem hiding this comment.
Thank you!
I am still a tiny bit confused as to why source_axis is part of the view entry, since it seems there's a bit of work spent validating it only appears once. Can it be dropped and the index of the ViewEntry in the Vec be used instead? (Or if not, can a comment get added explaining why that can't happen?)
One functionality of this views feature is to allow bands to be permuted, e.g. The index cannot be used to define the source axis because it is used to define the target axis. One example: GDAL-backed functions with band stacking require y then x are the last two dimensions. If the source raster does not have this behavior a permutation is neccessary. |
|
Got it...this is also defining the permutation in addition to the view. |
Address review: remove the pub-use re-export of ViewEntry from traits (internal crates import from view_entries directly), and add a try_new(inner, source_shape) that wraps and validates in one step.
This PR isolates just the machinery for the lazy view support. A subsequent PR will contain the integration(s) into the raster type.
This is spun out from #813
AI generated description
Adds
view_entries.rs, the per-axis view-spec layer for N-D raster bands. No consumers are wired up yet — the reader/builder integration is the follow-up — so there is no behavior change.ViewEntryThe per-axis spec
(source_axis, start, step, steps), moved here fromtraits.rsand re-exported ascrate::traits::ViewEntryso existing import paths are unchanged.step == 0is broadcast, negativestepis reverse iteration, andsteps == 0is an empty axis.ViewEntriesA newtype over
Vec<ViewEntry>that owns the view logic:validate(source_shape)— the load-bearing check: view length matchessource_shape, eachsource_axisis in range and the axes form a permutation of0..ndim,steps >= 0, and the addressed extentstart + (steps - 1) * stepstays within[0, source_shape[axis]). Useschecked_*arithmetic so a pathological spec errors rather than wrapping.visible_shape()— the visible extent (stepsper axis); this is what a band reports as itsshape().is_identity(source_shape)— whether the view is the canonical no-op, so it can be stored as a NULL view row.compose(next)— stacks a new view over an already-viewed band, translatingnext's axes (which index the visible axes) back onto the source axes. This is what lets views nest without materializing.identity_for_shape, pluslen/is_empty/as_slice/iteraccessors.view_entries!macroA terse constructor taking
start:stophalf-open ranges per axis:view_entries![0:4, 1:5]yieldssource_axis = position,step = 1,steps = stop - startfor each axis. Convenience for call sites and tests.Scope
Pure spec logic — no I/O, no Arrow columns; the only allocation is the small
Vec<ViewEntry>(ndim is a handful). Fully unit-tested in-module (validation rejections, composition, identity, visible-shape). It's the substrate the integration PR builds on.