davisusanibar commented on code in PR #14382:
URL: https://github.com/apache/arrow/pull/14382#discussion_r993988938
##########
docs/source/java/dataset.rst:
##########
@@ -213,18 +235,51 @@ be thrown during scanning.
Native Object Resource Management
=================================
As another result of relying on JNI, all components related to
-``FileSystemDataset`` should be closed manually to release the corresponding
-native objects after using. For example:
+``FileSystemDataset`` should be closed manually or use try-with-resources to
+release the corresponding native objects after using. For example:
.. code-block:: Java
- DatasetFactory factory = new FileSystemDatasetFactory(allocator,
- NativeMemoryPool.getDefault(), FileFormat.PARQUET, uri);
- Dataset dataset = factory.finish();
- Scanner scanner = dataset.newScan(new ScanOptions(100));
+ String uri = "file:/opt/example.parquet";
+ ScanOptions options = new ScanOptions(/*batchSize*/ 32768);
+ try (
+ BufferAllocator allocator = new RootAllocator();
+ DatasetFactory factory = new FileSystemDatasetFactory(
+ allocator, NativeMemoryPool.getDefault(),
+ FileFormat.PARQUET, uri);
+ Dataset dataset = factory.finish();
+ Scanner scanner = dataset.newScan(options)
+ ) {
+
+ // do something
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
- // do something
+If user forgets to close them then native object leakage might be caused.
- AutoCloseables.close(factory, dataset, scanner);
+Development Guidelines
Review Comment:
Make sense, changed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]