@@ -62,6 +62,7 @@ public class Query implements AutoCloseable {
6262 private Map <String , Pair <NativeArray , NativeArray >> buffers_ ;
6363 private Map <String , Pair <uint64_tArray , uint64_tArray >> buffer_sizes_ ;
6464 private Map <String , NativeArray > validityByteMaps_ ;
65+ private Map <String , ByteBuffer > validityByteMapsByteBuffers_ ;
6566
6667 public Query (Array array , QueryType type ) throws TileDBError {
6768 Context _ctx = array .getCtx ();
@@ -83,6 +84,7 @@ public Query(Array array, QueryType type) throws TileDBError {
8384 this .byteBuffers_ = Collections .synchronizedMap (new HashMap <>());
8485 this .buffer_sizes_ = Collections .synchronizedMap (new HashMap <>());
8586 this .validityByteMaps_ = Collections .synchronizedMap (new HashMap <>());
87+ this .validityByteMapsByteBuffers_ = Collections .synchronizedMap (new HashMap <>());
8688 }
8789
8890 public Query (Array array ) throws TileDBError {
@@ -604,6 +606,67 @@ public synchronized Query setBufferNullable(
604606 return this ;
605607 }
606608
609+ /**
610+ * Sets a nullable buffer for a fixed-sized attribute.
611+ *
612+ * @param attr The attribute name.
613+ * @param buffer NativeBuffer to be used for the attribute values.
614+ * @param bytemap The byte-map
615+ * @exception TileDBError A TileDB exception
616+ */
617+ public synchronized Query setBufferNullableNIO (String attr , ByteBuffer buffer , ByteBuffer bytemap )
618+ throws TileDBError {
619+
620+ if (buffer .capacity () <= 0 ) {
621+ throw new TileDBError ("Number of buffer elements must be >= 1" );
622+ }
623+
624+ if (!buffer .isDirect ()) {
625+ throw new TileDBError (
626+ "The ByteBuffer provided is not direct. Please provide a direct buffer (ByteBuffer.allocateDirect(...))" );
627+ }
628+
629+ if (!buffer .order ().equals (ByteOrder .nativeOrder ())) {
630+ throw new TileDBError (
631+ "The order of the data ByteBuffer should be the same as the native order (ByteOrder.nativeOrder())." );
632+ }
633+
634+ this .byteBuffers_ .put (attr , new Pair <>(null , buffer ));
635+
636+ uint64_tArray offsets_array_size = new uint64_tArray (1 );
637+ uint64_tArray values_array_size = new uint64_tArray (1 );
638+ uint64_tArray buffer_validity_bytemap_size = new uint64_tArray (1 );
639+
640+ offsets_array_size .setitem (0 , BigInteger .valueOf (0 ));
641+ values_array_size .setitem (0 , BigInteger .valueOf (buffer .capacity ()));
642+ buffer_validity_bytemap_size .setitem (0 , BigInteger .valueOf (bytemap .capacity ()));
643+
644+ buffer_sizes_ .put (attr , new Pair <>(offsets_array_size , values_array_size ));
645+
646+ Pair <uint64_tArray , uint64_tArray > buffer_sizes =
647+ new Pair <>(offsets_array_size , values_array_size );
648+
649+ this .byteBuffers_ .put (attr , new Pair <>(null , buffer ));
650+
651+ buffer_sizes_ .put (attr , buffer_sizes );
652+ validityByteMapsByteBuffers_ .put (attr , bytemap );
653+
654+ // Set the actual TileDB buffer
655+ uint64_tArray buffer_size = buffer_sizes .getSecond ();
656+
657+ ctx .handleError (
658+ Utils .tiledb_query_set_buffer_nullable_nio (
659+ ctx .getCtxp (),
660+ queryp ,
661+ attr ,
662+ buffer ,
663+ buffer_size .cast (),
664+ bytemap ,
665+ buffer_validity_bytemap_size .cast ()));
666+
667+ return this ;
668+ }
669+
607670 /**
608671 * Sets a nullable buffer for a variable-sized getAttribute.
609672 *
@@ -681,6 +744,70 @@ public synchronized Query setBufferNullable(
681744 return this ;
682745 }
683746
747+ /**
748+ * Sets a ByteBuffer buffer for a variable-sized getAttribute.
749+ *
750+ * @param attr Attribute name
751+ * @param offsets Offsets where a new element begins in the data buffer.
752+ * @param buffer Buffer vector with elements of the attribute type.
753+ * @exception TileDBError A TileDB exception
754+ */
755+ public synchronized Query setBufferNullableNIO (
756+ String attr , ByteBuffer offsets , ByteBuffer buffer , ByteBuffer bytemap ) throws TileDBError {
757+
758+ if (attr .equals (tiledb .tiledb_coords ())) {
759+ throw new TileDBError ("Cannot set coordinate buffer as variable sized." );
760+ }
761+
762+ if (!offsets .order ().equals (ByteOrder .nativeOrder ()) && offsets .position () > 0 ) {
763+ throw new TileDBError (
764+ "The order of the offsets ByteBuffer should be the same as the native order (ByteOrder.nativeOrder()) before values are inserted." );
765+ }
766+
767+ if (!buffer .order ().equals (ByteOrder .nativeOrder ()) && buffer .position () > 0 ) {
768+ throw new TileDBError (
769+ "The order of the data ByteBuffer should be the same as the native order (ByteOrder.nativeOrder()) before values are inserted." );
770+ }
771+
772+ offsets .order (ByteOrder .nativeOrder ());
773+ buffer .order (ByteOrder .nativeOrder ());
774+
775+ uint64_tArray offsets_array_size = new uint64_tArray (0 );
776+ uint64_tArray values_array_size = new uint64_tArray (0 );
777+ uint64_tArray buffer_validity_bytemap_size = new uint64_tArray (0 );
778+
779+ offsets_array_size .setitem (0 , BigInteger .valueOf (offsets .capacity ()));
780+ values_array_size .setitem (0 , BigInteger .valueOf (buffer .capacity ()));
781+ buffer_validity_bytemap_size .setitem (0 , BigInteger .valueOf (bytemap .capacity ()));
782+
783+ Pair <uint64_tArray , uint64_tArray > buffer_sizes =
784+ new Pair <>(offsets_array_size , values_array_size );
785+
786+ // Close previous buffers if they exist for this attribute
787+ if (buffers_ .containsKey (attr )) {
788+ Pair <NativeArray , NativeArray > prev_buffers = buffers_ .get (attr );
789+ prev_buffers .getFirst ().close ();
790+ prev_buffers .getSecond ().close ();
791+ }
792+
793+ buffer_sizes_ .put (attr , buffer_sizes );
794+ this .byteBuffers_ .put (attr , new Pair (offsets , buffer ));
795+
796+ ctx .handleError (
797+ Utils .tiledb_query_set_buffer_var_nullable_nio (
798+ ctx .getCtxp (),
799+ queryp ,
800+ attr ,
801+ offsets ,
802+ offsets_array_size .cast (),
803+ buffer ,
804+ values_array_size .cast (),
805+ bytemap ,
806+ buffer_validity_bytemap_size .cast ()));
807+
808+ return this ;
809+ }
810+
684811 /**
685812 * * Sets a NIO ByteBuffer
686813 *
@@ -699,7 +826,6 @@ public synchronized Query setBuffer(String attr, long bufferElements) throws Til
699826 int size = Util .castLongToInt (bufferElements * dt .getNativeSize ());
700827
701828 ByteBuffer buffer = ByteBuffer .allocateDirect (size ).order (ByteOrder .nativeOrder ());
702- ;
703829
704830 this .setBuffer (attr , buffer );
705831
0 commit comments