@@ -456,46 +456,36 @@ public static void create(
456456 */
457457 public HashMap <String , Pair > nonEmptyDomain () throws TileDBError {
458458 checkIsOpen ();
459- HashMap <String , Pair > ret = new HashMap <String , Pair >();
460- try (Domain domain = schema .getDomain ();
461- NativeArray domainArray =
462- new NativeArray (ctx , 2 * (int ) domain .getRank (), domain .getType ())) {
463- SWIGTYPE_p_int emptyp = tiledb .new_intp ();
464- try {
465- ctx .handleError (
466- tiledb .tiledb_array_get_non_empty_domain (
467- ctx .getCtxp (), arrayp , domainArray .toVoidPointer (), emptyp ));
468- if (tiledb .intp_value (emptyp ) == 1 ) {
469- return ret ;
470- }
471- } finally {
472- tiledb .delete_intp (emptyp );
473- }
474- for (int i = 0 ; i < domain .getRank (); i ++) {
475- try (Dimension d = domain .getDimension (i )) {
476- ret .put (
477- d .getName (),
478- new Pair (domainArray .getItem ((2 * i ) + 0 ), domainArray .getItem ((2 * i ) + 1 )));
479- }
459+ HashMap <String , Pair > ret = new HashMap <>();
460+ try (Domain domain = schema .getDomain ()) {
461+ long numDims = domain .getNDim ();
462+ for (long dimIdx = 0 ; dimIdx < numDims ; ++dimIdx ) {
463+ Dimension dimension = domain .getDimension (dimIdx );
464+ Pair p = getNonEmptyDomainFromIndex (dimIdx );
465+ ret .put (dimension .getName (), p );
480466 }
467+ } catch (TileDBError error ) {
468+ throw error ;
481469 }
482470 return ret ;
483471 }
484472
485473 /**
486- * Given a dimension's index, return the bounding coordinates for that dimension.
474+ * Given a dimension's index, return the bounding coordinates for that dimension. The method
475+ * checks if the dimension is var-sized or not, and it works for both cases.
487476 *
488477 * @param index THe dimension's index
489478 * @return A Pair that contains the dimension's bounds
490479 * @exception TileDBError A TileDB exception
491480 */
492481 public Pair getNonEmptyDomainFromIndex (long index ) throws TileDBError {
493482 checkIsOpen ();
494- Pair p ;
495483 try (Domain domain = schema .getDomain ();
496484 NativeArray domainArray =
497485 new NativeArray (ctx , 2 * (int ) domain .getRank (), domain .getType ())) {
498486
487+ if (domain .getDimension (index ).isVar ()) return getNonEmptyDomainVarFromIndex (index );
488+
499489 SWIGTYPE_p_int emptyp = tiledb .new_intp ();
500490 try {
501491 ctx .handleError (
@@ -514,7 +504,8 @@ public Pair getNonEmptyDomainFromIndex(long index) throws TileDBError {
514504 }
515505
516506 /**
517- * Given a dimension's name, return the bounding coordinates for that dimension.
507+ * Given a dimension's name, return the bounding coordinates for that dimension. The method checks
508+ * if the dimension is var-sized or not, and it works for both cases.
518509 *
519510 * @param name THe dimension's name
520511 * @return A Pair that contains the dimension's bounds
@@ -525,6 +516,9 @@ public Pair getNonEmptyDomainFromName(String name) throws TileDBError {
525516 try (Domain domain = schema .getDomain ();
526517 NativeArray domainArray =
527518 new NativeArray (ctx , 2 * (int ) domain .getRank (), domain .getType ())) {
519+
520+ if (domain .getDimension (name ).isVar ()) return this .getNonEmptyDomainVarFromName (name );
521+
528522 SWIGTYPE_p_int emptyp = tiledb .new_intp ();
529523 try {
530524 ctx .handleError (
@@ -540,6 +534,111 @@ public Pair getNonEmptyDomainFromName(String name) throws TileDBError {
540534 }
541535 }
542536
537+ /**
538+ * Retrieves the non-empty domain range sizes from an array for a given dimension index. This is
539+ * the union of the non-empty domains of the array fragments on the given dimension. Applicable
540+ * only to var-sized dimensions.
541+ *
542+ * @param index The dimension index
543+ * @return The non-empty domain range sizes
544+ * @throws TileDBError A TileDB exception
545+ */
546+ public Pair <BigInteger , BigInteger > getNonEmptyDomainVarSizeFromIndex (long index )
547+ throws TileDBError {
548+ SWIGTYPE_p_int emptyp = tiledb .new_intp ();
549+ SWIGTYPE_p_unsigned_long_long startSize = tiledb .new_ullp ();
550+ SWIGTYPE_p_unsigned_long_long endSize = tiledb .new_ullp ();
551+
552+ ctx .handleError (
553+ tiledb .tiledb_array_get_non_empty_domain_var_size_from_index (
554+ ctx .getCtxp (), arrayp , index , startSize , endSize , emptyp ));
555+
556+ return new Pair (tiledb .ullp_value (startSize ), tiledb .ullp_value (endSize ));
557+ }
558+
559+ /**
560+ * Retrieves the non-empty domain range sizes from an array for a given dimension name. This is
561+ * the union of the non-empty domains of the array fragments on the given dimension. Applicable
562+ * only to var-sized dimensions.
563+ *
564+ * @param name The dimension name
565+ * @return The non-empty domain range sizes
566+ * @throws TileDBError A TileDB exception
567+ */
568+ public Pair <BigInteger , BigInteger > getNonEmptyDomainVarSizeFromName (String name )
569+ throws TileDBError {
570+ SWIGTYPE_p_int emptyp = tiledb .new_intp ();
571+ SWIGTYPE_p_unsigned_long_long startSize = tiledb .new_ullp ();
572+ SWIGTYPE_p_unsigned_long_long endSize = tiledb .new_ullp ();
573+
574+ ctx .handleError (
575+ tiledb .tiledb_array_get_non_empty_domain_var_size_from_name (
576+ ctx .getCtxp (), arrayp , name , startSize , endSize , emptyp ));
577+
578+ return new Pair (tiledb .ullp_value (startSize ), tiledb .ullp_value (endSize ));
579+ }
580+
581+ /**
582+ * Retrieves the non-empty domain from an array for a given dimension index. This is the union of
583+ * the non-empty domains of the array fragments on the given dimension. Applicable only to
584+ * var-sized dimensions.
585+ *
586+ * @param index The dimension index
587+ * @return The non-empty domain
588+ * @throws TileDBError A TileDB exception
589+ */
590+ public Pair <String , String > getNonEmptyDomainVarFromIndex (long index ) throws TileDBError {
591+ SWIGTYPE_p_int emptyp = tiledb .new_intp ();
592+
593+ Dimension dim = this .schema .getDomain ().getDimension (index );
594+ Pair <BigInteger , BigInteger > size = this .getNonEmptyDomainVarSizeFromIndex (index );
595+
596+ Datatype dimType = dim .getType ();
597+ int startSize = size .getFirst ().intValue ();
598+ int endSize = size .getSecond ().intValue ();
599+
600+ NativeArray start = new NativeArray (ctx , startSize , dimType );
601+ NativeArray end = new NativeArray (ctx , endSize , dimType );
602+
603+ ctx .handleError (
604+ tiledb .tiledb_array_get_non_empty_domain_var_from_index (
605+ ctx .getCtxp (), arrayp , index , start .toVoidPointer (), end .toVoidPointer (), emptyp ));
606+
607+ return new Pair (
608+ new String ((byte []) start .toJavaArray ()), new String ((byte []) end .toJavaArray ()));
609+ }
610+
611+ /**
612+ * Retrieves the non-empty domain from an array for a given dimension name. This is the union of
613+ * the non-empty domains of the array fragments on the given dimension. Applicable only to
614+ * var-sized dimensions.
615+ *
616+ * @param name The dimension name
617+ * @return The non-empty domain
618+ * @throws TileDBError A TileDB exception
619+ */
620+ public Pair <String , String > getNonEmptyDomainVarFromName (String name ) throws TileDBError {
621+ SWIGTYPE_p_int emptyp = tiledb .new_intp ();
622+
623+ Dimension dim = this .schema .getDomain ().getDimension (name );
624+
625+ Pair <BigInteger , BigInteger > size = this .getNonEmptyDomainVarSizeFromName (name );
626+
627+ Datatype dimType = dim .getType ();
628+ int startSize = size .getFirst ().intValue ();
629+ int endSize = size .getSecond ().intValue ();
630+
631+ NativeArray start = new NativeArray (ctx , startSize , dimType );
632+ NativeArray end = new NativeArray (ctx , endSize , dimType );
633+
634+ ctx .handleError (
635+ tiledb .tiledb_array_get_non_empty_domain_var_from_name (
636+ ctx .getCtxp (), arrayp , name , start .toVoidPointer (), end .toVoidPointer (), emptyp ));
637+
638+ return new Pair (
639+ new String ((byte []) start .toJavaArray ()), new String ((byte []) end .toJavaArray ()));
640+ }
641+
543642 /**
544643 * Compute an upper bound on the buffer elements needed to read a subarray.
545644 *
0 commit comments