Skip to content

Commit

Permalink
Zarr V2 creation: fix bug when creating dataset with partial blocks a…
Browse files Browse the repository at this point in the history
…nd need to re-read them in the writing process when compression is involved

Embarassingly, we were trying to decompress chunks with the ...
compressor ... instead of the decompressor.

Fixes OSGeo#11016
  • Loading branch information
rouault committed Oct 15, 2024
1 parent 81721eb commit dc51819
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions autotest/gdrivers/zarr_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5523,3 +5523,25 @@ def test_zarr_read_cf1_zarrv3():
ds.GetSpatialRef().ExportToProj4()
== "+proj=utm +zone=11 +ellps=clrk66 +units=m +no_defs"
)


###############################################################################
# Test bug fix for https://github.com/OSGeo/gdal/issues/11016


@gdaltest.enable_exceptions()
@pytest.mark.require_driver("PNG")
def test_zarr_write_partial_blocks_compressed(tmp_vsimem):

if "lz4" not in gdal.GetDriverByName("Zarr").GetMetadataItem("BLOSC_COMPRESSORS"):
pytest.skip("LZ4 compression missing")

out_filename = "/vsimem/test.zarr"
src_ds = gdal.Open("data/png/rgba16.png")
gdal.Translate(
out_filename,
src_ds,
options="-of ZARR -co FORMAT=ZARR_V2 -co BLOCKSIZE=4,5,6 -co COMPRESS=LZ4 -co INTERLEAVE=BAND",
)
out_ds = gdal.Open(out_filename)
assert out_ds.ReadRaster() == src_ds.ReadRaster()
2 changes: 1 addition & 1 deletion frmts/zarr/zarr_v2_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ std::shared_ptr<GDALMDArray> ZarrV2Group::CreateMDArray(
if (!EQUAL(pszCompressor, "NONE"))
{
psCompressor = CPLGetCompressor(pszCompressor);
psDecompressor = CPLGetCompressor(pszCompressor);
psDecompressor = CPLGetDecompressor(pszCompressor);
if (psCompressor == nullptr || psDecompressor == nullptr)
{
CPLError(CE_Failure, CPLE_NotSupported,
Expand Down

0 comments on commit dc51819

Please sign in to comment.