@@ -231,6 +231,22 @@ public static void exportArrayStream(
231
231
new ArrayStreamExporter (allocator ).export (out , reader );
232
232
}
233
233
234
+ /**
235
+ * Equivalent to calling {@link #importField(BufferAllocator, ArrowSchema,
236
+ * CDataDictionaryProvider, boolean) importField(allocator, schema, provider, true)}.
237
+ *
238
+ * @param allocator Buffer allocator for allocating dictionary vectors
239
+ * @param schema C data interface struct representing the field [inout]
240
+ * @param provider A dictionary provider will be initialized with empty dictionary vectors
241
+ * (optional)
242
+ * @return Imported field object
243
+ * @see #importField(BufferAllocator, ArrowSchema, CDataDictionaryProvider, boolean)
244
+ */
245
+ public static Field importField (
246
+ BufferAllocator allocator , ArrowSchema schema , CDataDictionaryProvider provider ) {
247
+ return importField (allocator , schema , provider , true );
248
+ }
249
+
234
250
/**
235
251
* Import Java Field from the C data interface.
236
252
*
@@ -241,19 +257,42 @@ public static void exportArrayStream(
241
257
* @param schema C data interface struct representing the field [inout]
242
258
* @param provider A dictionary provider will be initialized with empty dictionary vectors
243
259
* (optional)
260
+ * @param closeImportedStructs if true, the ArrowSchema struct will be closed when this method
261
+ * completes.
244
262
* @return Imported field object
245
263
*/
246
264
public static Field importField (
247
- BufferAllocator allocator , ArrowSchema schema , CDataDictionaryProvider provider ) {
265
+ BufferAllocator allocator ,
266
+ ArrowSchema schema ,
267
+ CDataDictionaryProvider provider ,
268
+ boolean closeImportedStructs ) {
248
269
try {
249
270
SchemaImporter importer = new SchemaImporter (allocator );
250
271
return importer .importField (schema , provider );
251
272
} finally {
252
273
schema .release ();
253
- schema .close ();
274
+ if (closeImportedStructs ) {
275
+ schema .close ();
276
+ }
254
277
}
255
278
}
256
279
280
+ /**
281
+ * Equivalent to calling {@link #importSchema(BufferAllocator, ArrowSchema,
282
+ * CDataDictionaryProvider, boolean) importSchema(allocator, schema, provider, true)}.
283
+ *
284
+ * @param allocator Buffer allocator for allocating dictionary vectors
285
+ * @param schema C data interface struct representing the field
286
+ * @param provider A dictionary provider will be initialized with empty dictionary vectors
287
+ * (optional)
288
+ * @return Imported schema object
289
+ * @see #importSchema(BufferAllocator, ArrowSchema, CDataDictionaryProvider, boolean)
290
+ */
291
+ public static Schema importSchema (
292
+ BufferAllocator allocator , ArrowSchema schema , CDataDictionaryProvider provider ) {
293
+ return importSchema (allocator , schema , provider , true );
294
+ }
295
+
257
296
/**
258
297
* Import Java Schema from the C data interface.
259
298
*
@@ -264,36 +303,84 @@ public static Field importField(
264
303
* @param schema C data interface struct representing the field
265
304
* @param provider A dictionary provider will be initialized with empty dictionary vectors
266
305
* (optional)
306
+ * @param closeImportedStructs if true, the ArrowSchema struct will be closed when this method
307
+ * completes.
267
308
* @return Imported schema object
268
309
*/
269
310
public static Schema importSchema (
270
- BufferAllocator allocator , ArrowSchema schema , CDataDictionaryProvider provider ) {
271
- Field structField = importField (allocator , schema , provider );
311
+ BufferAllocator allocator ,
312
+ ArrowSchema schema ,
313
+ CDataDictionaryProvider provider ,
314
+ boolean closeImportedStructs ) {
315
+ Field structField = importField (allocator , schema , provider , closeImportedStructs );
272
316
if (structField .getType ().getTypeID () != ArrowTypeID .Struct ) {
273
317
throw new IllegalArgumentException (
274
318
"Cannot import schema: ArrowSchema describes non-struct type" );
275
319
}
276
320
return new Schema (structField .getChildren (), structField .getMetadata ());
277
321
}
278
322
323
+ /**
324
+ * Equivalent to calling {@link #importIntoVector(BufferAllocator, ArrowArray, FieldVector,
325
+ * DictionaryProvider, boolean)} importIntoVector(allocator, array, vector, provider, true)}.
326
+ *
327
+ * @param allocator Buffer allocator
328
+ * @param array C data interface struct holding the array data
329
+ * @param vector Imported vector object [out]
330
+ * @param provider Dictionary provider to load dictionary vectors to (optional)
331
+ * @see #importIntoVector(BufferAllocator, ArrowArray, FieldVector, DictionaryProvider, boolean)
332
+ */
333
+ public static void importIntoVector (
334
+ BufferAllocator allocator ,
335
+ ArrowArray array ,
336
+ FieldVector vector ,
337
+ DictionaryProvider provider ) {
338
+ importIntoVector (allocator , array , vector , provider , true );
339
+ }
340
+
279
341
/**
280
342
* Import Java vector from the C data interface.
281
343
*
282
- * <p>The ArrowArray struct has its contents moved (as per the C data interface specification) to
283
- * a private object held alive by the resulting array.
344
+ * <p>On successful completion, the ArrowArray struct will have been moved (as per the C data
345
+ * interface specification) to a private object held alive by the resulting array.
284
346
*
285
347
* @param allocator Buffer allocator
286
348
* @param array C data interface struct holding the array data
287
349
* @param vector Imported vector object [out]
288
350
* @param provider Dictionary provider to load dictionary vectors to (optional)
351
+ * @param closeImportedStructs if true, the ArrowArray struct will be closed when this method
352
+ * completes successfully.
289
353
*/
290
354
public static void importIntoVector (
291
355
BufferAllocator allocator ,
292
356
ArrowArray array ,
293
357
FieldVector vector ,
294
- DictionaryProvider provider ) {
358
+ DictionaryProvider provider ,
359
+ boolean closeImportedStructs ) {
295
360
ArrayImporter importer = new ArrayImporter (allocator , vector , provider );
296
361
importer .importArray (array );
362
+ if (closeImportedStructs ) {
363
+ array .close ();
364
+ }
365
+ }
366
+
367
+ /**
368
+ * Equivalent to calling {@link #importVector(BufferAllocator, ArrowArray, ArrowSchema,
369
+ * CDataDictionaryProvider, boolean) importVector(allocator, array, schema, provider, true)}.
370
+ *
371
+ * @param allocator Buffer allocator for allocating the output FieldVector
372
+ * @param array C data interface struct holding the array data
373
+ * @param schema C data interface struct holding the array type
374
+ * @param provider Dictionary provider to load dictionary vectors to (optional)
375
+ * @return Imported vector object
376
+ * @see #importVector(BufferAllocator, ArrowArray, ArrowSchema, CDataDictionaryProvider, boolean)
377
+ */
378
+ public static FieldVector importVector (
379
+ BufferAllocator allocator ,
380
+ ArrowArray array ,
381
+ ArrowSchema schema ,
382
+ CDataDictionaryProvider provider ) {
383
+ return importVector (allocator , array , schema , provider , true );
297
384
}
298
385
299
386
/**
@@ -307,19 +394,42 @@ public static void importIntoVector(
307
394
* @param array C data interface struct holding the array data
308
395
* @param schema C data interface struct holding the array type
309
396
* @param provider Dictionary provider to load dictionary vectors to (optional)
397
+ * @param closeImportedStructs if true, the ArrowArray struct will be closed when this method
398
+ * completes successfully and the ArrowSchema struct will be always be closed.
310
399
* @return Imported vector object
311
400
*/
312
401
public static FieldVector importVector (
313
402
BufferAllocator allocator ,
314
403
ArrowArray array ,
315
404
ArrowSchema schema ,
316
- CDataDictionaryProvider provider ) {
317
- Field field = importField (allocator , schema , provider );
405
+ CDataDictionaryProvider provider ,
406
+ boolean closeImportedStructs ) {
407
+ Field field = importField (allocator , schema , provider , closeImportedStructs );
318
408
FieldVector vector = field .createVector (allocator );
319
- importIntoVector (allocator , array , vector , provider );
409
+ importIntoVector (allocator , array , vector , provider , closeImportedStructs );
320
410
return vector ;
321
411
}
322
412
413
+ /**
414
+ * Equivalent to calling {@link #importIntoVectorSchemaRoot(BufferAllocator, ArrowArray,
415
+ * VectorSchemaRoot, DictionaryProvider, boolean) importIntoVectorSchemaRoot(allocator, array,
416
+ * root, provider, true)}.
417
+ *
418
+ * @param allocator Buffer allocator
419
+ * @param array C data interface struct holding the record batch data
420
+ * @param root vector schema root to load into
421
+ * @param provider Dictionary provider to load dictionary vectors to (optional)
422
+ * @see #importIntoVectorSchemaRoot(BufferAllocator, ArrowArray, VectorSchemaRoot,
423
+ * DictionaryProvider, boolean)
424
+ */
425
+ public static void importIntoVectorSchemaRoot (
426
+ BufferAllocator allocator ,
427
+ ArrowArray array ,
428
+ VectorSchemaRoot root ,
429
+ DictionaryProvider provider ) {
430
+ importIntoVectorSchemaRoot (allocator , array , root , provider , true );
431
+ }
432
+
323
433
/**
324
434
* Import record batch from the C data interface into vector schema root.
325
435
*
@@ -333,15 +443,18 @@ public static FieldVector importVector(
333
443
* @param array C data interface struct holding the record batch data
334
444
* @param root vector schema root to load into
335
445
* @param provider Dictionary provider to load dictionary vectors to (optional)
446
+ * @param closeImportedStructs if true, the ArrowArray struct will be closed when this method
447
+ * completes successfully
336
448
*/
337
449
public static void importIntoVectorSchemaRoot (
338
450
BufferAllocator allocator ,
339
451
ArrowArray array ,
340
452
VectorSchemaRoot root ,
341
- DictionaryProvider provider ) {
453
+ DictionaryProvider provider ,
454
+ boolean closeImportedStructs ) {
342
455
try (StructVector structVector = StructVector .emptyWithDuplicates ("" , allocator )) {
343
456
structVector .initializeChildrenFromFields (root .getSchema ().getFields ());
344
- importIntoVector (allocator , array , structVector , provider );
457
+ importIntoVector (allocator , array , structVector , provider , closeImportedStructs );
345
458
StructVectorUnloader unloader = new StructVectorUnloader (structVector );
346
459
VectorLoader loader = new VectorLoader (root );
347
460
try (ArrowRecordBatch recordBatch = unloader .getRecordBatch ()) {
@@ -350,6 +463,21 @@ public static void importIntoVectorSchemaRoot(
350
463
}
351
464
}
352
465
466
+ /**
467
+ * Equivalent to calling {@link #importVectorSchemaRoot(BufferAllocator, ArrowSchema,
468
+ * CDataDictionaryProvider, boolean) importVectorSchemaRoot(allocator, schema, provider, true)}.
469
+ *
470
+ * @param allocator Buffer allocator for allocating the output VectorSchemaRoot
471
+ * @param schema C data interface struct holding the record batch schema
472
+ * @param provider Dictionary provider to load dictionary vectors to (optional)
473
+ * @return Imported vector schema root
474
+ * @see #importVectorSchemaRoot(BufferAllocator, ArrowSchema, CDataDictionaryProvider, boolean)
475
+ */
476
+ public static VectorSchemaRoot importVectorSchemaRoot (
477
+ BufferAllocator allocator , ArrowSchema schema , CDataDictionaryProvider provider ) {
478
+ return importVectorSchemaRoot (allocator , schema , provider , true );
479
+ }
480
+
353
481
/**
354
482
* Import Java vector schema root from a C data interface Schema.
355
483
*
@@ -360,11 +488,37 @@ public static void importIntoVectorSchemaRoot(
360
488
* @param allocator Buffer allocator for allocating the output VectorSchemaRoot
361
489
* @param schema C data interface struct holding the record batch schema
362
490
* @param provider Dictionary provider to load dictionary vectors to (optional)
491
+ * @param closeImportedStructs if true, the ArrowSchema struct will be closed when this method
492
+ * completes
363
493
* @return Imported vector schema root
364
494
*/
365
495
public static VectorSchemaRoot importVectorSchemaRoot (
366
- BufferAllocator allocator , ArrowSchema schema , CDataDictionaryProvider provider ) {
367
- return importVectorSchemaRoot (allocator , null , schema , provider );
496
+ BufferAllocator allocator ,
497
+ ArrowSchema schema ,
498
+ CDataDictionaryProvider provider ,
499
+ boolean closeImportedStructs ) {
500
+ return importVectorSchemaRoot (allocator , null , schema , provider , closeImportedStructs );
501
+ }
502
+
503
+ /**
504
+ * Equivalent to calling {@link #importVectorSchemaRoot(BufferAllocator, ArrowArray, ArrowSchema,
505
+ * CDataDictionaryProvider, boolean) importVectorSchemaRoot(allocator, array, schema, provider,
506
+ * true)}.
507
+ *
508
+ * @param allocator Buffer allocator for allocating the output VectorSchemaRoot
509
+ * @param array C data interface struct holding the record batch data (optional)
510
+ * @param schema C data interface struct holding the record batch schema
511
+ * @param provider Dictionary provider to load dictionary vectors to (optional)
512
+ * @return Imported vector schema root
513
+ * @see #importVectorSchemaRoot(BufferAllocator, ArrowArray, ArrowSchema, CDataDictionaryProvider,
514
+ * boolean)
515
+ */
516
+ public static VectorSchemaRoot importVectorSchemaRoot (
517
+ BufferAllocator allocator ,
518
+ ArrowArray array ,
519
+ ArrowSchema schema ,
520
+ CDataDictionaryProvider provider ) {
521
+ return importVectorSchemaRoot (allocator , array , schema , provider , true );
368
522
}
369
523
370
524
/**
@@ -383,29 +537,56 @@ public static VectorSchemaRoot importVectorSchemaRoot(
383
537
* @param array C data interface struct holding the record batch data (optional)
384
538
* @param schema C data interface struct holding the record batch schema
385
539
* @param provider Dictionary provider to load dictionary vectors to (optional)
540
+ * @param closeImportedStructs if true, the ArrowArray struct will be closed when this method
541
+ * completes successfully and the ArrowSchema struct will be always be closed.
386
542
* @return Imported vector schema root
387
543
*/
388
544
public static VectorSchemaRoot importVectorSchemaRoot (
389
545
BufferAllocator allocator ,
390
546
ArrowArray array ,
391
547
ArrowSchema schema ,
392
- CDataDictionaryProvider provider ) {
548
+ CDataDictionaryProvider provider ,
549
+ boolean closeImportedStructs ) {
393
550
VectorSchemaRoot vsr =
394
- VectorSchemaRoot .create (importSchema (allocator , schema , provider ), allocator );
551
+ VectorSchemaRoot .create (
552
+ importSchema (allocator , schema , provider , closeImportedStructs ), allocator );
395
553
if (array != null ) {
396
- importIntoVectorSchemaRoot (allocator , array , vsr , provider );
554
+ importIntoVectorSchemaRoot (allocator , array , vsr , provider , closeImportedStructs );
397
555
}
398
556
return vsr ;
399
557
}
400
558
401
559
/**
402
- * Import an ArrowArrayStream as an {@link ArrowReader}.
560
+ * Equivalent to calling {@link #importArrayStream(BufferAllocator, ArrowArrayStream, boolean)
561
+ * importArrayStream(allocator, stream, true)}.
403
562
*
404
563
* @param allocator Buffer allocator for allocating the output data.
405
564
* @param stream C stream interface struct to import.
406
565
* @return Imported reader
566
+ * @see #importArrayStream(BufferAllocator, ArrowArrayStream, boolean)
407
567
*/
408
568
public static ArrowReader importArrayStream (BufferAllocator allocator , ArrowArrayStream stream ) {
409
- return new ArrowArrayStreamReader (allocator , stream );
569
+ return importArrayStream (allocator , stream , true );
570
+ }
571
+
572
+ /**
573
+ * Import an ArrowArrayStream as an {@link ArrowReader}.
574
+ *
575
+ * <p>On successful completion, the ArrowArrayStream struct will have been moved (as per the C
576
+ * data interface specification) to a private object held alive by the resulting ArrowReader.
577
+ *
578
+ * @param allocator Buffer allocator for allocating the output data.
579
+ * @param stream C stream interface struct to import.
580
+ * @param closeImportedStructs if true, the ArrowArrayStream struct will be closed when this
581
+ * method completes successfully
582
+ * @return Imported reader
583
+ */
584
+ public static ArrowReader importArrayStream (
585
+ BufferAllocator allocator , ArrowArrayStream stream , boolean closeImportedStructs ) {
586
+ ArrowArrayStreamReader reader = new ArrowArrayStreamReader (allocator , stream );
587
+ if (closeImportedStructs ) {
588
+ stream .close ();
589
+ }
590
+ return reader ;
410
591
}
411
592
}
0 commit comments