You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sedona.apache.org by ja...@apache.org on 2026/09/01 20:48:25 UTC

(sedona-db) branch main updated: test(integration): broaden nodata function parity coverage (#1203)

This is an automated email from the ASF dual-hosted git repository.

james-willis pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/sedona-db.git


The following commit(s) were added to refs/heads/main by this push:
     new 95da42294 test(integration): broaden nodata function parity coverage (#1203)
95da42294 is described below

commit 95da42294713522e1f6cdea4271750ed0683c58d
Author: James Willis <ja...@users.noreply.github.com>
AuthorDate: Tue Sep 1 13:48:20 2026 -0700

    test(integration): broaden nodata function parity coverage (#1203)
---
 integration/spark-parity/test_rs_raster_out.py    | 211 ++++++++++++++++++++--
 integration/spark-parity/test_rs_scalar.py        | 161 +++++++++++++----
 python/sedonadb/python/sedonadb/raster_testing.py |  18 +-
 python/sedonadb/python/sedonadb/testing.py        |  93 ++++++++++
 python/sedonadb/python/sedonadb/testing_spark.py  |   6 +
 5 files changed, 431 insertions(+), 58 deletions(-)

diff --git a/integration/spark-parity/test_rs_raster_out.py b/integration/spark-parity/test_rs_raster_out.py
index 0ebceee07..7cae7fc61 100644
--- a/integration/spark-parity/test_rs_raster_out.py
+++ b/integration/spark-parity/test_rs_raster_out.py
@@ -19,9 +19,10 @@
 These exercise the raster round-trip *out* of each engine: SedonaDB decodes its
 native raster column; Sedona Spark transports the result as GeoTIFF bytes
 (`RS_AsGeoTiff`) and decodes it with rasterio. Both sides land as a
-`DecodedRaster` (pixels + geotransform + per-band nodata) and are compared with
-`assert_decoded_equal`. Same `xfail`-for-known-divergence policy as the scalar
-suite.
+`DecodedRaster` (pixels + geotransform + per-band nodata), which is how the
+harness-level `sedonadb.testing.compare` compares a raster result — a NULL
+raster from every engine also counts as agreement. Same
+`xfail`-for-known-divergence policy as the scalar suite.
 
 Both engines are constructed directly rather than through fixtures: this suite is
 only run deliberately, so a missing pyspark, JVM, or Sedona jar should be a
@@ -36,17 +37,9 @@ operation divergence — it isolates the transport. Pixel-transforming ops
 
 import pytest
 
-from sedonadb.raster_testing import (
-    assert_decoded_equal,
-    random_raster_data,
-    write_geotiff,
-)
-from sedonadb.testing import SedonaDB
+from sedonadb.testing import SedonaDB, compare
 from sedonadb.testing_spark import SedonaSpark
 
-GDAL_TRANSFORM = (100.0, 2.0, 0.0, 500.0, 0.0, -3.0)
-BANDS, HEIGHT, WIDTH = 2, 6, 7
-
 # Each value is representable in its dtype, so it packs into the band exactly.
 BAND_NODATA = {"uint8": 200.0, "int32": -99999.0, "float64": -12345.5}
 
@@ -56,16 +49,194 @@ def test_rs_setbandnodata(dtype, tmp_path):
     """RS_SetBandNoDataValue sets band 1's nodata and passes pixels through, so
     SedonaDB and Sedona Spark must return the same raster: identical pixels and
     geotransform, band 1's nodata set, band 2's still absent."""
-    tif = tmp_path / f"src_{dtype}.tif"
-    data = random_raster_data(dtype, bands=BANDS, height=HEIGHT, width=WIDTH)
-    write_geotiff(tif, data, gdal_transform=GDAL_TRANSFORM)  # no nodata to start
-
     sedona, spark = SedonaDB(), SedonaSpark()
     for eng in (sedona, spark):
-        eng.create_raster_view("src", tif)
+        # The new nodata value is also planted into the pixels: setting a
+        # band's nodata must not mask or rewrite pixels that happen to hold
+        # the sentinel. No nodata to start.
+        eng.create_random_raster_view(
+            "src",
+            tmp_path / "src.tif",
+            dtype=dtype,
+            plants={(1, 1): BAND_NODATA[dtype]},
+        )
 
     sql = f"SELECT RS_SetBandNoDataValue(rast, 1, {BAND_NODATA[dtype]}) FROM src"
-    assert_decoded_equal(
-        sedona.decode_raster_result(sql),
-        spark.decode_raster_result(sql),
+    compare(sql, sedona, spark)
+
+
+def test_rs_setbandnodata_band2(tmp_path):
+    """Setting band 2 must leave band 1's (absent) nodata alone — the case that
+    catches an off-by-one in band addressing."""
+    sedona, spark = SedonaDB(), SedonaSpark()
+    for eng in (sedona, spark):
+        eng.create_random_raster_view(
+            "band2_src", tmp_path / "band2_src.tif", dtype="float64"
+        )
+    sql = "SELECT RS_SetBandNoDataValue(rast, 2, 5.0) FROM band2_src"
+    compare(sql, sedona, spark)
+
+
+def test_rs_setbandnodata_overwrite(tmp_path):
+    """Replacing an existing nodata, and re-setting it to the value it already
+    holds, agree across engines."""
+    sedona, spark = SedonaDB(), SedonaSpark()
+    for eng in (sedona, spark):
+        eng.create_random_raster_view(
+            "ow_src", tmp_path / "ow_src.tif", bands=1, nodata=7.0
+        )
+    for sql in (
+        "SELECT RS_SetBandNoDataValue(rast, 1, 9.0) FROM ow_src",
+        "SELECT RS_SetBandNoDataValue(rast, 1, 7.0) FROM ow_src",
+    ):
+        compare(sql, sedona, spark)
+
+
+def test_rs_setbandnodata_two_arg_single_band(tmp_path):
+    """The 2-argument form (no band index) works on a single-band raster in
+    both engines."""
+    sedona, spark = SedonaDB(), SedonaSpark()
+    for eng in (sedona, spark):
+        eng.create_random_raster_view(
+            "two_arg_src", tmp_path / "two_arg_src.tif", bands=1
+        )
+    sql = "SELECT RS_SetBandNoDataValue(rast, 5.0) FROM two_arg_src"
+    compare(sql, sedona, spark)
+
+
+@pytest.mark.xfail(
+    reason="SedonaDB deliberately rejects the 2-arg form on a multi-band raster; "
+    "Sedona Spark defaults to band 1"
+)
+def test_rs_setbandnodata_two_arg_multi_band(tmp_path):
+    """The 2-argument form on a multi-band raster gets the same answer from
+    both engines."""
+    sedona, spark = SedonaDB(), SedonaSpark()
+    for eng in (sedona, spark):
+        eng.create_random_raster_view(
+            "two_arg_multi_src", tmp_path / "two_arg_multi_src.tif"
+        )
+    sql = "SELECT RS_SetBandNoDataValue(rast, 5.0) FROM two_arg_multi_src"
+    compare(sql, sedona, spark)
+
+
+@pytest.mark.parametrize(
+    "dtype,value",
+    [
+        pytest.param("uint8", "300.5", id="uint8-out-of-range-fractional"),
+        pytest.param("int32", "0.5", id="int32-fractional"),
+        pytest.param("int32", "CAST('NaN' AS DOUBLE)", id="int32-nan"),
+    ],
+)
+def test_rs_setbandnodata_invalid_value_rejected(dtype, value, tmp_path):
+    """Both engines refuse a nodata the band dtype cannot hold. Error types and
+    messages differ across engines, so parity here is parity on refusal."""
+    sedona, spark = SedonaDB(), SedonaSpark()
+    for eng in (sedona, spark):
+        eng.create_random_raster_view("inv_src", tmp_path / "inv_src.tif", dtype=dtype)
+    sql = f"SELECT RS_SetBandNoDataValue(rast, 1, {value}) FROM inv_src"
+    for eng in (sedona, spark):
+        with pytest.raises(Exception):
+            eng.decode_raster_result(sql)
+
+
+@pytest.mark.xfail(
+    reason="SedonaDB rejects -1.0 as a UInt8 nodata; Sedona Spark accepts it "
+    "and reports -1.0 on the uint8 band"
+)
+def test_rs_setbandnodata_negative_on_uint8(tmp_path):
+    """A negative nodata on an unsigned band is the value-validation case the
+    engines disagree on (contrast 300.5, which both refuse)."""
+    sedona, spark = SedonaDB(), SedonaSpark()
+    for eng in (sedona, spark):
+        eng.create_random_raster_view(
+            "neg_src", tmp_path / "neg_src.tif", dtype="uint8"
+        )
+    sql = "SELECT RS_SetBandNoDataValue(rast, 1, -1.0) FROM neg_src"
+    compare(sql, sedona, spark)
+
+
+@pytest.mark.parametrize("band", [0, 3])
+def test_rs_setbandnodata_out_of_range_band_rejected(band, tmp_path):
+    """Both engines refuse an out-of-range band index — unlike the getter,
+    where SedonaDB returns NULL (see test_rs_scalar.py)."""
+    sedona, spark = SedonaDB(), SedonaSpark()
+    for eng in (sedona, spark):
+        eng.create_random_raster_view(
+            "oob_set_src", tmp_path / "oob_set_src.tif", dtype="float64"
+        )
+    sql = f"SELECT RS_SetBandNoDataValue(rast, {band}, 5.0) FROM oob_set_src"
+    for eng in (sedona, spark):
+        with pytest.raises(Exception):
+            eng.decode_raster_result(sql)
+
+
+@pytest.mark.parametrize("dtype", ["float32", "float64"])
+@pytest.mark.xfail(
+    reason="after setting a NaN nodata, Sedona Spark reports the band nodata "
+    "as NULL where SedonaDB reports NaN"
+)
+def test_rs_setbandnodata_nan_on_float(dtype, tmp_path):
+    """Setting a NaN nodata on a float band reads back the same from both
+    engines."""
+    sedona, spark = SedonaDB(), SedonaSpark()
+    for eng in (sedona, spark):
+        eng.create_random_raster_view(
+            "nan_set_src", tmp_path / "nan_set_src.tif", dtype=dtype, bands=1
+        )
+    sql = (
+        "SELECT RS_SetBandNoDataValue(rast, 1, CAST('NaN' AS DOUBLE)) FROM nan_set_src"
+    )
+    compare(sql, sedona, spark)
+
+
+def test_rs_setbandnodata_null_band_and_value(tmp_path):
+    """A NULL band index or a NULL nodata value yields a NULL raster on both
+    engines."""
+    sedona, spark = SedonaDB(), SedonaSpark()
+    for eng in (sedona, spark):
+        eng.create_random_raster_view(
+            "null_arg_src", tmp_path / "null_arg_src.tif", dtype="float64"
+        )
+    for sql in (
+        "SELECT RS_SetBandNoDataValue(rast, CASE WHEN 1 = 0 THEN 1 END, 5.0) "
+        "FROM null_arg_src",
+        "SELECT RS_SetBandNoDataValue(rast, 1, CAST(NULL AS DOUBLE)) FROM null_arg_src",
+    ):
+        compare(sql, sedona, spark)
+
+
+@pytest.mark.xfail(
+    reason="the CASE that types the NULL loses the raster extension type in "
+    "SedonaDB, so no kernel matches; Sedona Spark returns a NULL raster"
+)
+def test_rs_setbandnodata_null_raster(tmp_path):
+    """NULL raster in, NULL raster out — phrased through CASE because neither
+    dialect types a bare NULL literal as a raster."""
+    sedona, spark = SedonaDB(), SedonaSpark()
+    for eng in (sedona, spark):
+        eng.create_random_raster_view(
+            "null_rast_src", tmp_path / "null_rast_src.tif", dtype="float64"
+        )
+    sql = (
+        "SELECT RS_SetBandNoDataValue(CASE WHEN 1 = 0 THEN rast END, 1, 5.0) "
+        "FROM null_rast_src"
     )
+    compare(sql, sedona, spark)
+
+
+def test_rs_setbandnodata_replace_flag_rejected(tmp_path):
+    """Sedona's Java layer ships a 4-argument overload (a replace flag), but at
+    1.9.1 the Spark SQL binding fails to evaluate it and SedonaDB has no such
+    kernel — both reject, so parity holds as parity on refusal. If Sedona Spark
+    wires the flag up, this starts failing and `replace` becomes a real parity
+    case."""
+    sedona, spark = SedonaDB(), SedonaSpark()
+    for eng in (sedona, spark):
+        eng.create_random_raster_view(
+            "replace_src", tmp_path / "replace_src.tif", bands=1
+        )
+    sql = "SELECT RS_SetBandNoDataValue(rast, 1, 5.0, true) FROM replace_src"
+    for eng in (sedona, spark):
+        with pytest.raises(Exception):
+            eng.decode_raster_result(sql)
diff --git a/integration/spark-parity/test_rs_scalar.py b/integration/spark-parity/test_rs_scalar.py
index aafae3ff0..11ca5a4d8 100644
--- a/integration/spark-parity/test_rs_scalar.py
+++ b/integration/spark-parity/test_rs_scalar.py
@@ -16,11 +16,11 @@
 # under the License.
 """SedonaDB vs Sedona Spark parity for the scalar raster readers.
 
-Unlike the geometry suite (which pins each engine against a fixed expected
-value), these tests assert the two engines return the *same* result for the
-*same* SQL over the *same* GeoTIFF — the parity question directly, with no
-oracle. SedonaDB's own correctness is covered by the rasterio-oracle tests in
-`test_rs_value.py`; this suite only asks whether Sedona Spark agrees.
+Sedona Spark is the compatibility target, so each test runs one shared SQL
+string on both engines and asserts they agree with the harness-level
+`sedonadb.testing.compare`: ``compare(sql, sedona, spark)``, SedonaDB as the
+subject and Sedona Spark as the expected side. SedonaDB's own correctness is
+covered by the rasterio-oracle tests in `test_rs_value.py`.
 
 Both engines are constructed directly rather than through fixtures: this suite is
 only run deliberately, so a missing pyspark, JVM, or Sedona jar should be a
@@ -29,49 +29,140 @@ failure with a real traceback, not a skip. `SedonaSpark` caches its
 
 Where the two engines are known to diverge and we intend to close the gap, mark
 the case `xfail(reason=...)` so the suite doubles as a catalog of what to fix —
-it flips to xpass the day the fix lands.
+it flips to xpass the day the fix lands. When today's divergence is that one
+engine raises, that error is what trips the xfail.
 """
 
 import pytest
 
-from sedonadb.raster_testing import random_raster_data, write_geotiff
-from sedonadb.testing import SedonaDB
+from sedonadb.testing import SedonaDB, compare
 from sedonadb.testing_spark import SedonaSpark
 
-# North-up, CRS-less: origin (100, 500) with 2-wide by 3-tall pixels. These
-# functions take no geometry, so a CRS would only add a reprojection difference.
-GDAL_TRANSFORM = (100.0, 2.0, 0.0, 500.0, 0.0, -3.0)
-BANDS, HEIGHT, WIDTH = 2, 6, 7
-
-# Each value is representable in its dtype, so the nodata reads back exactly.
-BAND_NODATA = {"uint8": 200.0, "int32": -99999.0, "float64": -12345.5}
-
-
-def _one(engine, sql):
-    """The single scalar (or list) result of `sql` on `engine`, as a Python value."""
-    table = engine.result_to_table(engine.execute_and_collect(sql))
-    return table.column(0)[0].as_py()
+# Each value is representable both in its dtype and exactly in f64, so the
+# nodata reads back exactly.
+BAND_NODATA = {
+    "uint8": 200.0,
+    "int8": -100.0,
+    "uint16": 60000.0,
+    "int16": -30000.0,
+    "uint32": 4000000000.0,
+    "int32": -99999.0,
+    "float32": -8000.5,
+    "float64": -12345.5,
+}
 
 
 @pytest.mark.parametrize("dtype", list(BAND_NODATA))
 def test_rs_band_nodata(dtype, tmp_path):
     """SedonaDB and Sedona Spark read back the same band nodata for the same
     GeoTIFF, and both return NULL for a band written without one."""
-    data = random_raster_data(dtype, bands=BANDS, height=HEIGHT, width=WIDTH)
-    with_nodata = tmp_path / f"nd_{dtype}.tif"
-    without_nodata = tmp_path / f"nond_{dtype}.tif"
-    write_geotiff(
-        with_nodata, data, gdal_transform=GDAL_TRANSFORM, nodata=BAND_NODATA[dtype]
-    )
-    write_geotiff(without_nodata, data, gdal_transform=GDAL_TRANSFORM)
-
     sedona, spark = SedonaDB(), SedonaSpark()
     for eng in (sedona, spark):
-        eng.create_raster_view("nd_raster", with_nodata)
-        eng.create_raster_view("nond_raster", without_nodata)
+        # The nodata value is also planted into the pixels: the getter reads
+        # band metadata, so a pixel that happens to hold the sentinel must not
+        # matter.
+        eng.create_random_raster_view(
+            "nd_raster",
+            tmp_path / "nd.tif",
+            dtype=dtype,
+            nodata=BAND_NODATA[dtype],
+            plants={(2, 3): BAND_NODATA[dtype]},
+        )
+        eng.create_random_raster_view(
+            "nond_raster",
+            tmp_path / "nond.tif",
+            dtype=dtype,
+            plants={(2, 3): BAND_NODATA[dtype]},
+        )
 
     for band in (1, 2):
-        with_sql = f"SELECT RS_BandNoDataValue(rast, {band}) FROM nd_raster"
-        without_sql = f"SELECT RS_BandNoDataValue(rast, {band}) FROM nond_raster"
-        assert _one(sedona, with_sql) == _one(spark, with_sql)
-        assert _one(sedona, without_sql) == _one(spark, without_sql)
+        for view in ("nd_raster", "nond_raster"):
+            sql = f"SELECT RS_BandNoDataValue(rast, {band}) FROM {view}"
+            compare(sql, sedona, spark)
+
+
+@pytest.mark.parametrize("dtype", ["float32", "float64"])
+@pytest.mark.xfail(
+    reason="SedonaDB reads a NaN file nodata back as NaN; Sedona Spark returns NULL"
+)
+def test_rs_band_nodata_nan(dtype, tmp_path):
+    """A float band whose file nodata is NaN (GeoTIFF encodes it) reads back
+    the same from both engines."""
+    sedona, spark = SedonaDB(), SedonaSpark()
+    for eng in (sedona, spark):
+        eng.create_random_raster_view(
+            "nan_nd_raster",
+            tmp_path / "nan_nd.tif",
+            dtype=dtype,
+            bands=1,
+            nodata=float("nan"),
+        )
+    sql = "SELECT RS_BandNoDataValue(rast, 1) FROM nan_nd_raster"
+    compare(sql, sedona, spark)
+
+
+@pytest.mark.xfail(
+    reason="SedonaDB packs the file nodata into the band dtype (0.5 becomes 0); "
+    "Sedona Spark reports the GDAL metadata value verbatim (0.5)"
+)
+def test_rs_band_nodata_fractional_on_int_band(tmp_path):
+    """TIFFTAG_GDAL_NODATA is ASCII metadata, so a file can claim a nodata its
+    band dtype cannot hold. rasterio refuses to write one beyond the dtype's
+    range, so the writable case is a fractional nodata on an integer band."""
+    sedona, spark = SedonaDB(), SedonaSpark()
+    for eng in (sedona, spark):
+        eng.create_random_raster_view(
+            "frac_nd_raster",
+            tmp_path / "frac_nd.tif",
+            dtype="int32",
+            bands=1,
+            nodata=0.5,
+        )
+    sql = "SELECT RS_BandNoDataValue(rast, 1) FROM frac_nd_raster"
+    compare(sql, sedona, spark)
+
+
+@pytest.mark.parametrize("band", [0, 3, -1])
+@pytest.mark.xfail(
+    reason="SedonaDB returns NULL for an out-of-range band (deliberate, per "
+    "rs_band_accessors.rs); Sedona Spark raises"
+)
+def test_rs_band_nodata_out_of_range_band(band, tmp_path):
+    """An out-of-range band index gets the same answer from both engines.
+    Contrast the setter, which both engines refuse (see test_rs_raster_out.py)."""
+    sedona, spark = SedonaDB(), SedonaSpark()
+    for eng in (sedona, spark):
+        eng.create_random_raster_view("oob_raster", tmp_path / "oob.tif", nodata=7.0)
+    sql = f"SELECT RS_BandNoDataValue(rast, {band}) FROM oob_raster"
+    compare(sql, sedona, spark)
+
+
+@pytest.mark.xfail(
+    reason="the CASE that types the NULL loses the raster extension type in "
+    "SedonaDB, so no kernel matches; Sedona Spark returns NULL"
+)
+def test_rs_band_nodata_null_raster(tmp_path):
+    """NULL raster in, NULL out — phrased through CASE because neither dialect
+    types a bare NULL literal as a raster."""
+    sedona, spark = SedonaDB(), SedonaSpark()
+    for eng in (sedona, spark):
+        eng.create_random_raster_view("null_src", tmp_path / "null_src.tif", nodata=7.0)
+    sql = "SELECT RS_BandNoDataValue(CASE WHEN 1 = 0 THEN rast END, 1) FROM null_src"
+    compare(sql, sedona, spark)
+
+
+@pytest.mark.xfail(
+    reason="SedonaDB coalesces a NULL band index to band 1 (unwrap_or(1) in "
+    "rs_band_accessors.rs); Sedona Spark returns NULL"
+)
+def test_rs_band_nodata_null_band(tmp_path):
+    """A NULL band index propagates the same way through both engines."""
+    sedona, spark = SedonaDB(), SedonaSpark()
+    for eng in (sedona, spark):
+        eng.create_random_raster_view(
+            "null_band_src", tmp_path / "null_band_src.tif", nodata=7.0
+        )
+    sql = (
+        "SELECT RS_BandNoDataValue(rast, CASE WHEN 1 = 0 THEN 1 END) FROM null_band_src"
+    )
+    compare(sql, sedona, spark)
diff --git a/python/sedonadb/python/sedonadb/raster_testing.py b/python/sedonadb/python/sedonadb/raster_testing.py
index 9e2930535..40e9f8cf1 100644
--- a/python/sedonadb/python/sedonadb/raster_testing.py
+++ b/python/sedonadb/python/sedonadb/raster_testing.py
@@ -158,15 +158,27 @@ def write_geotiff(
 
 
 def write_random_geotiff(
-    path, dtype, *, bands, height, width, gdal_transform, crs=None, nodata=None
+    path,
+    dtype,
+    *,
+    bands,
+    height,
+    width,
+    gdal_transform,
+    crs=None,
+    nodata=None,
+    plants=None,
 ) -> None:
     """Write a GeoTIFF of random `dtype` pixels on the given grid.
 
     Combines `random_raster_data` (dtype extremes planted in opposite corners)
     with `write_geotiff` — the input-raster fixture shape shared by raster warp
-    parity tests. `gdal_transform`, `crs`, and `nodata` are as `write_geotiff`.
+    parity tests. `gdal_transform`, `crs`, and `nodata` are as `write_geotiff`;
+    `plants` is as `random_raster_data`.
     """
-    data = random_raster_data(dtype, bands=bands, height=height, width=width)
+    data = random_raster_data(
+        dtype, bands=bands, height=height, width=width, plants=plants
+    )
     write_geotiff(path, data, gdal_transform=gdal_transform, nodata=nodata, crs=crs)
 
 
diff --git a/python/sedonadb/python/sedonadb/testing.py b/python/sedonadb/python/sedonadb/testing.py
index 88d212a7e..af7e88050 100644
--- a/python/sedonadb/python/sedonadb/testing.py
+++ b/python/sedonadb/python/sedonadb/testing.py
@@ -187,6 +187,43 @@ class DBEngine:
         """
         raise NotImplementedError()
 
+    def create_random_raster_view(
+        self,
+        name,
+        path,
+        *,
+        dtype="uint8",
+        bands=2,
+        height=6,
+        width=7,
+        gdal_transform=(100.0, 2.0, 0.0, 500.0, 0.0, -3.0),
+        nodata=None,
+        plants=None,
+    ) -> "DBEngine":
+        """Write a random GeoTIFF at `path` and register it as view `name`
+        (see `create_raster_view`).
+
+        The default grid is small and north-up/CRS-less so nothing reprojects
+        and results stay bit-comparable across engines. The pixels come from
+        `sedonadb.raster_testing.random_raster_data` with a fixed seed, so
+        registering the same `path` on several engines rewrites identical
+        bytes and every engine sees the same raster. `nodata` and `plants` are
+        as `write_random_geotiff`.
+        """
+        from sedonadb.raster_testing import write_random_geotiff
+
+        write_random_geotiff(
+            path,
+            dtype,
+            bands=bands,
+            height=height,
+            width=width,
+            gdal_transform=gdal_transform,
+            nodata=nodata,
+            plants=plants,
+        )
+        return self.create_raster_view(name, path)
+
     def decode_raster_result(self, sql):
         """Run `sql` (which selects a single raster column) and decode the result
         raster to a `sedonadb.raster_testing.DecodedRaster` — pixels, geotransform,
@@ -196,6 +233,16 @@ class DBEngine:
         """
         raise NotImplementedError()
 
+    def result_has_raster(self, sql) -> bool:
+        """Whether `sql` produces a raster column on this engine.
+
+        Answered from the engine's lazy result schema — nothing executes.
+        This is what lets `compare` pick between the tuple comparison and the
+        decoded-raster comparison without assuming a particular engine as the
+        subject.
+        """
+        raise NotImplementedError()
+
     def execute_and_collect(self, query):
         """Execute a query and collect results to the driver
 
@@ -411,6 +458,12 @@ class SedonaDB(DBEngine):
         table = self.execute_and_collect(loaded)
         return decode_raster(table.column(0)[0])
 
+    def result_has_raster(self, sql) -> bool:
+        schema = pa.schema(self.con.sql(sql).schema)
+        return any(
+            getattr(t, "extension_name", None) == "sedona.raster" for t in schema.types
+        )
+
     def execute_and_collect(self, query) -> "sedonadb.dataframe.DataFrame":
         # Use to_arrow_table() to maintain ordering of the input table
         return self.con.sql(query).to_arrow_table()
@@ -941,6 +994,46 @@ class ArrowSQLCache:
         self._dirty = False
 
 
+def compare(sql, *engines):
+    """Assert every engine returns the same result for one shared SQL string.
+
+    The cross-engine parity assertion. The first engine is the subject — its
+    result is the "got" side of every failure message — and each further
+    engine's result is an expected side, so with more than two engines the
+    subject is checked against every reference (which, by transitivity, means
+    they all agree).
+
+    Table-shaped results are compared in `result_to_tuples` form, the
+    representation built for verifying results between engines: Arrow
+    stringifies values identically on every side, NULL stays `None`, and NaN
+    becomes the string ``"nan"`` (bare float equality would lose it). A result
+    with a raster column is instead decoded on every engine
+    (`decode_raster_result`) and compared with
+    `sedonadb.raster_testing.assert_decoded_equal`; every engine agreeing the
+    raster is NULL also counts as agreement. The dispatch asks the subject's
+    `result_has_raster`, answered from its lazy result schema, so any engine
+    that implements the raster hooks can be the subject.
+    """
+    if len(engines) < 2:
+        raise ValueError("compare() needs at least two engines")
+    subject, references = engines[0], engines[1:]
+
+    if subject.result_has_raster(sql):
+        from sedonadb.raster_testing import assert_decoded_equal
+
+        got = subject.decode_raster_result(sql)
+        for reference in references:
+            expected = reference.decode_raster_result(sql)
+            if got is None and expected is None:
+                continue
+            assert_decoded_equal(got, expected, context=sql)
+    else:
+        result = subject.execute_and_collect(sql)
+        for reference in references:
+            expected = reference.result_to_tuples(reference.execute_and_collect(sql))
+            subject.assert_result(result, expected)
+
+
 def geom_or_null(arg, srid=None):
     """Format SQL expression for a geometry object or NULL"""
     if arg is None:
diff --git a/python/sedonadb/python/sedonadb/testing_spark.py b/python/sedonadb/python/sedonadb/testing_spark.py
index d8db15053..99f7caade 100644
--- a/python/sedonadb/python/sedonadb/testing_spark.py
+++ b/python/sedonadb/python/sedonadb/testing_spark.py
@@ -169,6 +169,12 @@ class SedonaSpark(DBEngine):
         # nodata None into a float NaN and mask the value under test.
         return result.toArrow()
 
+    def result_has_raster(self, sql) -> bool:
+        from sedona.spark.sql.types import RasterType
+
+        fields = self._session.sql(sql).schema.fields
+        return any(isinstance(field.dataType, RasterType) for field in fields)
+
     def decode_raster_result(self, sql):
         from sedonadb.raster_testing import DecodedRaster, decode_geotiff_bytes