Skip to content

[GH-3330] Preserve other raster bands when replacing NoData - #3347

Merged
jiayuasu merged 1 commit into
apache:masterfrom
jiayuasu:fix/nodata-preserve-bands
Sep 13, 2026
Merged

jiayuasu merged 1 commit into
apache:masterfrom
jiayuasu:fix/nodata-preserve-bands

Conversation

@jiayuasu

Copy link
Copy Markdown
Member

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 rasteralgebraTest passed:

mvn -B -pl spark/common -am spotless:apply \
  -Dtest=RasterBandEditorsTest,RasterBandAccessorsTest,SerdeTest \
  -Dsurefire.failIfNoSpecifiedTests=false -DfailIfNoTests=false \
  -Dsuites=org.apache.sedona.sql.rasteralgebraTest package

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.

@jiayuasu jiayuasu added this to the sedona-2.0.0 milestone Sep 13, 2026
@jiayuasu
jiayuasu merged commit 98bb35c into apache:master Sep 13, 2026
43 checks passed
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.
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.

RS_SetBandNoDataValue with replace=true zeroes every band except the target one

1 participant