@@ -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 ,
0 commit comments