|
3 | 3 | import dev.zarr.zarrjava.Utils; |
4 | 4 | import dev.zarr.zarrjava.ZarrException; |
5 | 5 | import dev.zarr.zarrjava.core.Group; |
| 6 | +import dev.zarr.zarrjava.v3.Array; |
| 7 | +import dev.zarr.zarrjava.v3.DataType; |
6 | 8 | import org.junit.jupiter.api.Assertions; |
7 | 9 | import org.junit.jupiter.api.BeforeAll; |
8 | 10 | import org.junit.jupiter.api.Test; |
| 11 | +import org.junit.jupiter.params.ParameterizedTest; |
| 12 | +import org.junit.jupiter.params.provider.ValueSource; |
9 | 13 |
|
10 | 14 | import java.io.IOException; |
11 | 15 | import java.nio.file.Path; |
@@ -123,4 +127,42 @@ public void testReadFromBufferedZipStore() throws ZarrException, IOException { |
123 | 127 |
|
124 | 128 | assertIsTestGroupV3(Group.open(readOnlyZipStore.resolve()), true); |
125 | 129 | } |
| 130 | + |
| 131 | + @ParameterizedTest |
| 132 | + @ValueSource(strings = {"start", "end"}) |
| 133 | + public void testPartialReadOfShardedArray(String indexLocation) throws ZarrException, IOException { |
| 134 | + // partial shard reads fetch the shard index via a suffix read when it is located at the end |
| 135 | + Path sourceDir = TESTOUTPUT.resolve("testShardedZipStore_" + indexLocation); |
| 136 | + Path targetDir = TESTOUTPUT.resolve("testShardedZipStore_" + indexLocation + ".zip"); |
| 137 | + Array writeArray = Array.create(new FilesystemStore(sourceDir).resolve(), Array.metadataBuilder() |
| 138 | + .withShape(24, 24) |
| 139 | + .withDataType(DataType.INT32) |
| 140 | + .withChunkShape(16, 16) |
| 141 | + .withCodecs(c -> c.withSharding(new int[]{8, 8}, c1 -> c1.withBytes("LITTLE"), indexLocation)) |
| 142 | + .withFillValue(0) |
| 143 | + .build()); |
| 144 | + int[] data = new int[24 * 24]; |
| 145 | + for (int i = 0; i < data.length; i++) { |
| 146 | + data[i] = i; |
| 147 | + } |
| 148 | + ucar.ma2.Array expected = ucar.ma2.Array.factory(ucar.ma2.DataType.INT, new int[]{24, 24}, data); |
| 149 | + writeArray.write(expected); |
| 150 | + |
| 151 | + Utils.zipFile(sourceDir, targetDir); |
| 152 | + |
| 153 | + Array[] readArrays = { |
| 154 | + Array.open(new ReadOnlyZipStore(targetDir).resolve()), |
| 155 | + Array.open(new BufferedZipStore(targetDir).resolve()) |
| 156 | + }; |
| 157 | + for (Array readArray : readArrays) { |
| 158 | + Assertions.assertArrayEquals(data, (int[]) readArray.read().get1DJavaArray(ucar.ma2.DataType.INT)); |
| 159 | + |
| 160 | + ucar.ma2.Array partial = readArray.read(new long[]{3, 5}, new long[]{14, 17}); |
| 161 | + for (int i = 0; i < 14; i++) { |
| 162 | + for (int j = 0; j < 17; j++) { |
| 163 | + Assertions.assertEquals(data[(i + 3) * 24 + (j + 5)], partial.getInt(i * 17 + j)); |
| 164 | + } |
| 165 | + } |
| 166 | + } |
| 167 | + } |
126 | 168 | } |
0 commit comments