[GH-3330] Preserve other raster bands when replacing NoData - #3347
Merged
Merged
Conversation
james-willis
added a commit
to james-willis/sedona-db
that referenced
this pull request
Sep 23, 2026
…rload Adds the 4-argument form Sedona Spark has, RS_SetBandNoDataValue(raster, band, nodata, replace). With replace true, every pixel in the addressed band holding that band's current nodata is rewritten to the new sentinel before it is declared, so the pixels that read as nodata before the call still read as nodata after it. Other bands are untouched, and replacing against a band with no existing nodata is an error — there is nothing to match, and Sedona Spark raises there too. A null nodata still clears the band, which leaves no sentinel to rewrite pixels to, so replace is moot and no pixel is touched. The match is on raw little-endian bytes rather than decoded values, which is exact for every band data type without dispatching over them: the new sentinel arrives already packed into the band's type by nodata_f64_to_bytes, so both sides are the same width by construction. The one inherited behavior is that a NaN sentinel matches only pixels carrying the identical NaN bit pattern, where Sedona Spark compares numerically and NaN never matches itself. Because it rewrites pixels, this form cannot share the source buffer the way the metadata-only forms do, so the UDF is now tagged needs_pixels and the planner materializes its raster argument through RS_EnsureLoaded. That is what makes it work on an OutDb raster, which is what the parity fixtures read; the cost is that the metadata-only forms are materialized too, where previously they passed an OutDb raster through untouched. The parity suite's single-band replace case now agrees on the released Sedona jar and loses its xfail. The multiband case still trips apache/sedona#3330, where Sedona Spark zeroes every band except the target; that is fixed on Sedona master by apache/sedona#3347 and verified there against a jar built from it, but no release carries it yet, so the case keeps an xfail naming the release it waits on.
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.
Did you read the Contributor Guide?
Yes, I have read the Contributor Rules and Contributor Development Guide.
Is this PR related to a ticket?
Closes #3330.
What changes were proposed in this PR?
RS_SetBandNoDataValue(raster, band, value, true)creates a new writable raster when replacing existing NoData samples. Previously, it filled only the selected band, leaving every other band's pixels at zero.Copy the source raster into the new raster before replacing the selected band's samples. This preserves the other bands and leaves the source unchanged.
How was this patch tested?
The new Java regression fails without the fix. It covers all six pixel types and each target band in a three-band raster, checking all pixel values, NoData values, grid geometry, data type, and source preservation. A SQL regression also checks fractional samples and materialized raster serialization.
On Java 11 and Spark 3.5.0, 59 Java tests and all 169 tests in
rasteralgebraTestpassed:Formatting and pre-commit checks passed.
Did this PR include necessary documentation updates?
No documentation changes are needed. This restores the existing function's expected behavior.