Skip to content

Commit aec1bb2

Browse files
committed
add storageTransformers attribute
1 parent 8eec486 commit aec1bb2

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

src/main/java/dev/zarr/zarrjava/v3/ArrayMetadata.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public final class ArrayMetadata {
5555
@Nullable
5656
@JsonProperty("dimension_names")
5757
public String[] dimensionNames;
58+
@Nullable
59+
@JsonProperty("storage_transformers")
60+
public Map<String, Object>[] storageTransformers;
5861

5962
@JsonIgnore
6063
public CoreArrayMetadata coreArrayMetadata;
@@ -64,11 +67,12 @@ public ArrayMetadata(
6467
Object fillValue,
6568
@Nonnull Codec[] codecs,
6669
@Nullable String[] dimensionNames,
67-
@Nullable Map<String, Object> attributes
70+
@Nullable Map<String, Object> attributes,
71+
@Nullable Map<String, Object>[] storageTransformers
6872
) throws ZarrException {
6973
this(ZARR_FORMAT, NODE_TYPE, shape, dataType, chunkGrid, chunkKeyEncoding, fillValue, codecs,
7074
dimensionNames,
71-
attributes
75+
attributes, storageTransformers
7276
);
7377
}
7478

@@ -83,7 +87,8 @@ public ArrayMetadata(
8387
@JsonProperty(value = "fill_value", required = true) Object fillValue,
8488
@Nonnull @JsonProperty(value = "codecs") Codec[] codecs,
8589
@Nullable @JsonProperty(value = "dimension_names") String[] dimensionNames,
86-
@Nullable @JsonProperty(value = "attributes") Map<String, Object> attributes
90+
@Nullable @JsonProperty(value = "attributes") Map<String, Object> attributes,
91+
@Nullable @JsonProperty(value = "storage_transformers") Map<String, Object>[] storageTransformers
8792
) throws ZarrException {
8893
if (zarrFormat != this.zarrFormat) {
8994
throw new ZarrException(
@@ -126,6 +131,7 @@ public ArrayMetadata(
126131
this.codecs = codecs;
127132
this.dimensionNames = dimensionNames;
128133
this.attributes = attributes;
134+
this.storageTransformers = storageTransformers;
129135
this.coreArrayMetadata =
130136
new CoreArrayMetadata(shape, ((RegularChunkGrid) chunkGrid).configuration.chunkShape,
131137
dataType,

src/main/java/dev/zarr/zarrjava/v3/ArrayMetadataBuilder.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class ArrayMetadataBuilder {
2929
Object fillValue = 0;
3030
Codec[] codecs = new Codec[]{new BytesCodec(Endian.LITTLE)};
3131
Map<String, Object> attributes = new HashMap<>();
32+
Map<String, Object>[] storageTransformers = new HashMap[]{};
3233
String[] dimensionNames = null;
3334

3435
protected ArrayMetadataBuilder() {
@@ -44,6 +45,7 @@ protected static ArrayMetadataBuilder fromArrayMetadata(ArrayMetadata arrayMetad
4445
builder.codecs = arrayMetadata.codecs;
4546
builder.attributes = arrayMetadata.attributes;
4647
builder.dimensionNames = arrayMetadata.dimensionNames;
48+
builder.storageTransformers = arrayMetadata.storageTransformers;
4749
return builder;
4850
}
4951

@@ -125,6 +127,10 @@ public ArrayMetadataBuilder withAttributes(Map<String, Object> attributes) {
125127
this.attributes = attributes;
126128
return this;
127129
}
130+
public ArrayMetadataBuilder withStorageTransformers(Map<String, Object>[] storageTransformers) {
131+
this.storageTransformers = storageTransformers;
132+
return this;
133+
}
128134

129135
public ArrayMetadata build() throws ZarrException {
130136
if (shape == null) {
@@ -140,7 +146,8 @@ public ArrayMetadata build() throws ZarrException {
140146

141147
return new ArrayMetadata(shape, dataType, chunkGrid, chunkKeyEncoding, fillValue, codecs,
142148
dimensionNames,
143-
attributes
149+
attributes,
150+
storageTransformers
144151
);
145152
}
146153
}

src/test/java/dev/zarr/zarrjava/ZarrTest.java

+24-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.fasterxml.jackson.databind.ObjectMapper;
77
import com.github.luben.zstd.Zstd;
88
import com.github.luben.zstd.ZstdCompressCtx;
9+
import com.google.common.collect.Maps;
910
import dev.zarr.zarrjava.store.*;
1011
import dev.zarr.zarrjava.utils.MultiArrayUtils;
1112
import dev.zarr.zarrjava.v3.*;
@@ -631,9 +632,31 @@ public void testReadL4Sample(String mag) throws IOException, ZarrException {
631632

632633
assert MultiArrayUtils.allValuesEqual(httpData2, localData2);
633634
}
635+
634636
@Test
635637
public void testMetadataAcceptsStorageTransformer() throws ZarrException, IOException {
636638
StoreHandle localStoreHandle = new FilesystemStore(TESTDATA).resolve("storage_transformer");
637-
Array localArray = Array.open(localStoreHandle);
639+
Map<String, Object>[] storageTransformers1 = Array.open(localStoreHandle).metadata.storageTransformers;
640+
641+
Array array2 = Array.create(
642+
new FilesystemStore(TESTOUTPUT).resolve("storage_transformer"),
643+
Array.metadataBuilder()
644+
.withShape(1)
645+
.withChunkShape(1)
646+
.withDataType(DataType.UINT8)
647+
.withStorageTransformers(new HashMap[]{new HashMap<String, Object>(){
648+
{
649+
put("name", "chunk-manifest-json");
650+
put("configuration", new HashMap<String, Object>(){
651+
{
652+
put("manifest", "./manifest.json");
653+
}
654+
});
655+
}
656+
}})
657+
.build()
658+
);
659+
Map<String, Object>[] storageTransformers2 = array2.metadata.storageTransformers;
660+
assert Maps.difference(storageTransformers1[0], storageTransformers2[0]).areEqual();
638661
}
639662
}

0 commit comments

Comments
 (0)