Skip to content

Commit 61659ff

Browse files
committed
remove detectDimensionSeparator
1 parent d584375 commit 61659ff

2 files changed

Lines changed: 0 additions & 149 deletions

File tree

src/main/java/dev/zarr/zarrjava/v2/Array.java

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,6 @@ public static Array open(StoreHandle storeHandle) throws IOException, ZarrExcept
6060
Utils.toArray(storeHandle.resolve(ZATTRS).readNonNull()),
6161
Attributes.class
6262
);
63-
64-
// Auto-detect dimension separator if not specified and array has multiple dimensions
65-
if (metadata.dimensionSeparator == null && metadata.shape.length > 1) {
66-
Separator detectedSeparator = detectDimensionSeparator(storeHandle, metadata.chunks);
67-
if (detectedSeparator != null) {
68-
// Create a new metadata instance with the detected separator
69-
metadata = new ArrayMetadata(
70-
metadata.zarrFormat,
71-
metadata.shape,
72-
metadata.chunks,
73-
metadata.dataType,
74-
metadata.parsedFillValue,
75-
metadata.order,
76-
metadata.filters,
77-
metadata.compressor,
78-
detectedSeparator,
79-
metadata.attributes
80-
);
81-
}
82-
}
83-
8463
return new Array(
8564
storeHandle,
8665
metadata
@@ -272,70 +251,6 @@ public Array updateAttributes(Function<Attributes, Attributes> attributeMapper)
272251
return setAttributes(attributeMapper.apply(metadata.attributes));
273252
}
274253

275-
/**
276-
* Detects dimension separator from existing chunk files in the store.
277-
* Similar to JZarr's ZarrArray::findNestedChunks method.
278-
*
279-
* @param storeHandle the store containing the array
280-
* @param chunks the chunk shape
281-
* @return the detected separator (SLASH or DOT), or null if detection fails
282-
*/
283-
@Nullable
284-
private static Separator detectDimensionSeparator(StoreHandle storeHandle, int[] chunks) {
285-
// Only attempt detection if store supports listing
286-
if (!(storeHandle.store instanceof Store.ListableStore)) {
287-
return null;
288-
}
289-
290-
try {
291-
// List all files in the array directory, excluding metadata files (.zarray, .zattrs, .zgroup)
292-
String[] chunkFiles = storeHandle.list()
293-
.filter(key -> !key.startsWith(".z"))
294-
.toArray(String[]::new);
295-
296-
if (chunkFiles.length == 0) {
297-
// No chunks exist yet, cannot detect
298-
return null;
299-
}
300-
301-
// Build regex pattern to match nested chunks (SLASH separator)
302-
// Pattern: \d+/\d+/... for multi-dimensional arrays
303-
StringBuilder nestedPattern = new StringBuilder("\\d+");
304-
for (int i = 1; i < chunks.length; i++) {
305-
nestedPattern.append("/\\d+");
306-
}
307-
String nestedRegex = nestedPattern.toString();
308-
309-
// Check if any chunk file matches the nested pattern
310-
for (String chunkFile : chunkFiles) {
311-
if (chunkFile.matches(nestedRegex)) {
312-
return Separator.SLASH;
313-
}
314-
}
315-
316-
// Build regex pattern to match flat chunks (DOT separator)
317-
// Pattern: \d+.\d+.... for multi-dimensional arrays
318-
StringBuilder flatPattern = new StringBuilder("\\d+");
319-
for (int i = 1; i < chunks.length; i++) {
320-
flatPattern.append("\\.\\d+");
321-
}
322-
String flatRegex = flatPattern.toString();
323-
324-
// Check if any chunk file matches the flat pattern
325-
for (String chunkFile : chunkFiles) {
326-
if (chunkFile.matches(flatRegex)) {
327-
return Separator.DOT;
328-
}
329-
}
330-
331-
// Could not detect separator from existing chunks
332-
return null;
333-
} catch (Exception e) {
334-
// If listing fails, return null
335-
return null;
336-
}
337-
}
338-
339254
@Override
340255
public String toString() {
341256
return String.format("<v2.Array {%s} (%s) %s>", storeHandle,

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

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -453,68 +453,4 @@ public void testDefaultChunkShape() throws IOException, ZarrException {
453453
Assertions.assertTrue(mixedArray.metadata().chunks[2] > 0);
454454
Assertions.assertTrue(mixedArray.metadata().chunks[2] <= 2048);
455455
}
456-
457-
@Test
458-
public void testDimensionSeparatorAutoDetection() throws IOException, ZarrException {
459-
// Test with SLASH separator
460-
StoreHandle slashStoreHandle = new FilesystemStore(TESTOUTPUT).resolve("v2_separator_detection_slash");
461-
Array slashArray = Array.create(
462-
slashStoreHandle,
463-
Array.metadataBuilder()
464-
.withShape(10, 10)
465-
.withDataType(DataType.UINT8)
466-
.withChunks(5, 5)
467-
.withDimensionSeparator(dev.zarr.zarrjava.core.chunkkeyencoding.Separator.SLASH)
468-
.build()
469-
);
470-
471-
// Write some data to create chunk files
472-
slashArray.write(new long[]{0, 0}, ucar.ma2.Array.factory(ucar.ma2.DataType.UBYTE, new int[]{5, 5}));
473-
474-
// Now open without specifying separator - it should auto-detect SLASH
475-
Array reopenedSlashArray = Array.open(slashStoreHandle);
476-
Assertions.assertEquals(dev.zarr.zarrjava.core.chunkkeyencoding.Separator.SLASH,
477-
reopenedSlashArray.metadata().dimensionSeparator);
478-
479-
// Test with DOT separator
480-
StoreHandle dotStoreHandle = new FilesystemStore(TESTOUTPUT).resolve("v2_separator_detection_dot");
481-
Array dotArray = Array.create(
482-
dotStoreHandle,
483-
Array.metadataBuilder()
484-
.withShape(10, 10)
485-
.withDataType(DataType.UINT8)
486-
.withChunks(5, 5)
487-
.withDimensionSeparator(dev.zarr.zarrjava.core.chunkkeyencoding.Separator.DOT)
488-
.build()
489-
);
490-
491-
// Write some data to create chunk files
492-
dotArray.write(new long[]{0, 0}, ucar.ma2.Array.factory(ucar.ma2.DataType.UBYTE, new int[]{5, 5}));
493-
494-
// Now open without specifying separator - it should auto-detect DOT
495-
Array reopenedDotArray = Array.open(dotStoreHandle);
496-
Assertions.assertEquals(dev.zarr.zarrjava.core.chunkkeyencoding.Separator.DOT,
497-
reopenedDotArray.metadata().dimensionSeparator);
498-
}
499-
500-
@Test
501-
public void testDimensionSeparatorDefaultFallback() throws IOException, ZarrException {
502-
// Test that when no chunks exist, the separator defaults to DOT (as per ArrayMetadata.chunkKeyEncoding())
503-
StoreHandle emptyStoreHandle = new FilesystemStore(TESTOUTPUT).resolve("v2_separator_detection_empty");
504-
Array emptyArray = Array.create(
505-
emptyStoreHandle,
506-
Array.metadataBuilder()
507-
.withShape(10, 10)
508-
.withDataType(DataType.UINT8)
509-
.withChunks(5, 5)
510-
.build()
511-
);
512-
513-
// Open without writing any chunks
514-
Array reopenedEmptyArray = Array.open(emptyStoreHandle);
515-
// Should use default DOT separator from ArrayMetadata.chunkKeyEncoding()
516-
// When dimensionSeparator is null, chunkKeyEncoding() defaults to DOT
517-
Assertions.assertEquals(dev.zarr.zarrjava.core.chunkkeyencoding.Separator.DOT,
518-
reopenedEmptyArray.metadata().chunkKeyEncoding().separator);
519-
}
520456
}

0 commit comments

Comments
 (0)