feat(rust/sedona-raster): array-level column overrides for metadata setters - #1198
Open
james-willis wants to merge 1 commit into
Open
feat(rust/sedona-raster): array-level column overrides for metadata setters#1198james-willis wants to merge 1 commit into
james-willis wants to merge 1 commit into
Conversation
…etters
Closes DB-99.
`RS_SetCRS`, `RS_SetSRID` and `RS_SetGeoReference` change only top-level
metadata — one of five columns on the raster `StructArray`. The bands column,
which holds every pixel byte, is untouched by definition.
Two ways to produce that output existed, and the setters were split across
both:
* `swap_crs_column` (private to `rs_setsrid.rs`, hardcoded to the CRS column)
replaced one column and carried the rest over as the same `Arc`. Correct,
but unreachable from anywhere else.
* `RasterBuilder::copy_raster_from` walked every band and re-emitted every
band field into a fresh builder. `RS_SetGeoReference` used this. The pixel
buffers were shared by refcount, but all the band metadata was rebuilt to
change one number — and the bands came out identical only if the rebuild
was faithful. DB-506 is what happens when it isn't: that rebuild silently
dropped band names.
Generalize the first into a shared `with_column_overrides` and move all three
setters onto it.
* `RasterColumnOverrides { crs, transform }` uses the `Override<T>` trinary
from #1158. `Keep` leaves a column in place sharing its `Arc`, `Clear` nulls
it, `Set(a)` installs a per-row array. `Override` rather than `Option`
because `RS_SetSRID(raster, 0)` must *clear* the CRS while keeping the
raster — distinct from leaving the column alone, which `Option` cannot
express. That is why `swap_crs_column` was bespoke.
* The helper also absorbs the input-null merge that was duplicated inline at
both `rs_setsrid.rs` call sites, including the length-1 broadcast for scalar
arguments. A null *argument* nulls the whole raster row; that is a separate
axis from `Clear`ing a column.
* It is a free function taking `&StructArray`, not a method on
`RasterStructArray`, so it does not require parsing and validating every
column for what is pure column surgery — and so introduces no failure mode
`swap_crs_column` did not have.
* `RS_SetGeoReference` builds a `List<Float64>` transform column directly and
drops `copy_raster_from`. Its bands are now provably untouched.
Note this keeps two override vocabularies on purpose. `RasterOverrides` stays
the *builder's* language — a scalar applied while a row is constructed. The
array path replaces whole columns and takes per-row values already in an
array. Forcing the setters onto the scalar struct would regress `RS_SetSRID`
from per-row CRS (`broadcast_string_view` passes an N-row array straight
through) to a single CRS per call. They share `Override<T>`, which is the
vocabulary that matters.
`with_column_overrides_shares_untouched_columns` asserts `Arc::ptr_eq` on
every carried-over column, which is the only assertion that distinguishes a
shared column from an equal-looking rebuild.
james-willis
force-pushed
the
james/db-99-array-level-override
branch
from
August 28, 2026 18:01
0040157 to
b170d19
Compare
james-willis
marked this pull request as ready for review
August 28, 2026 19:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes DB-99. Stacked on #1158 — review that first; this diff shows only its own commit.
The problem
A raster is an Arrow
StructArraywith five columns:RS_SetCRS,RS_SetSRIDandRS_SetGeoReferencechange column 0 or 1. Column 4 is untouched by definition. But the three setters were split across two very different ways of producing that output:swap_crs_columnArcrs_setsrid.rsand hardcoded to CRScopy_raster_fromRS_SetGeoReferenceused the builder. Pixel buffers were shared by refcount, but the bands came out identical only if the rebuild was faithful. #1192 is what happens when it isn't — that same rebuild silently dropped every band name.The change
Generalize the first into a shared free function and move all three setters onto it.
Override<T>, notOption—RS_SetSRID(raster, 0)must clear the CRS while keeping the raster, which is distinct from leaving the column alone.Optioncan't say both; that's exactly whyswap_crs_columnwas bespoke.rs_setsrid.rscall sites, including the length-1 broadcast for scalar arguments. A null argument nulls the raster row — a separate axis fromClearing a column.&StructArray, not a method onRasterStructArray. This is pure column surgery; routing it throughtry_newwould parse and validate all five columns and add a failure modeswap_crs_columnnever had.RS_SetGeoReferencedropscopy_raster_from, building aList<Float64>transform column directly. Its bands are now provably untouched.Two override vocabularies, deliberately
The ticket asked for one shared
RasterOverrides. That can't work:RasterOverridesis a scalar — one value per call — whilebroadcast_string_viewpasses an N-row CRS array straight through when it's already the right length.RS_SetSRID(raster_col, srid_col)assigns a different CRS per row, and folding it onto a scalar struct would regress that to one CRS for the whole call.So
RasterOverridesstays the builder's language (a scalar applied while constructing a row), and the array path gets column-shaped overrides. They share theOverride<T>trinary from #1158, which is the vocabulary that actually matters.Also worth noting: the ticket assigns "extend
RasterOverrideswith acrsfield and switch it toOverride<T>" to DB-98, but #1158 only convertedBandOverrides. That prerequisite is moot under this design — the array path doesn't useRasterOverridesat all.Tests
with_column_overrides_shares_untouched_columnsassertsArc::ptr_eqon every carried-over column — the only assertion that distinguishes a shared column from an equal-looking rebuild.with_column_overrides_clear_and_null_mergepinsClear(nulls the column, keeps the raster) againstinput_nulls(nulls the raster).I tried the same
ptr_eqassertion end-to-end throughScalarUdfTesterand removed it: the harness re-materializes the raster argument through DataFusion's extension-type plumbing, so it measures the harness rather than the contract.fmt and clippy clean;
sedona-raster-gdalbuilds.