davisusanibar commented on a change in pull request #138: URL: https://github.com/apache/arrow-cookbook/pull/138#discussion_r810302296
########## File path: java/source/dataset.rst ########## @@ -0,0 +1,300 @@ +.. _arrow-dataset: + +======= +Dataset +======= + +* `Arrow Java Dataset <https://arrow.apache.org/docs/dev/java/dataset.html>`_: Java implementation of Arrow Datasets library. + +.. contents:: + +Dataset +======= + +Let construct our dataset with auto-inferred schema. + +.. testcode:: + + import org.apache.arrow.dataset.file.FileFormat; + import org.apache.arrow.dataset.file.FileSystemDatasetFactory; + import org.apache.arrow.dataset.jni.NativeMemoryPool; + import org.apache.arrow.dataset.scanner.ScanOptions; + import org.apache.arrow.dataset.scanner.Scanner; + import org.apache.arrow.dataset.source.Dataset; + import org.apache.arrow.dataset.source.DatasetFactory; + import org.apache.arrow.memory.RootAllocator; + import java.util.stream.StreamSupport; + + try (RootAllocator rootAllocator = new RootAllocator(Long.MAX_VALUE)) { + String uri = "file:" + System.getProperty("user.dir") + "/thirdpartydeps/parquetfiles/data1.parquet"; + try (DatasetFactory datasetFactory = new FileSystemDatasetFactory(rootAllocator, NativeMemoryPool.getDefault(), FileFormat.PARQUET, uri)) { + try(Dataset dataset = datasetFactory.finish()){ + ScanOptions options = new ScanOptions(100); + try(Scanner scanner = dataset.newScan(options)){ + System.out.println(StreamSupport.stream(scanner.scan().spliterator(), false).count()); + } + } + } + } + +.. testoutput:: + + 1 + +Let construct our dataset with predefined schema. + +.. testcode:: + + import org.apache.arrow.dataset.file.FileFormat; + import org.apache.arrow.dataset.file.FileSystemDatasetFactory; + import org.apache.arrow.dataset.jni.NativeMemoryPool; + import org.apache.arrow.dataset.scanner.ScanOptions; + import org.apache.arrow.dataset.scanner.Scanner; + import org.apache.arrow.dataset.source.Dataset; + import org.apache.arrow.dataset.source.DatasetFactory; + import org.apache.arrow.memory.RootAllocator; + import java.util.stream.StreamSupport; + + String uri = "file:" + System.getProperty("user.dir") + "/thirdpartydeps/parquetfiles/data1.parquet"; + try (RootAllocator rootAllocator = new RootAllocator(Long.MAX_VALUE)) { + try (DatasetFactory datasetFactory = new FileSystemDatasetFactory(rootAllocator, NativeMemoryPool.getDefault(), FileFormat.PARQUET, uri)) { + try(Dataset dataset = datasetFactory.finish(datasetFactory.inspect())){ + ScanOptions options = new ScanOptions(100); + try(Scanner scanner = dataset.newScan(options)){ + System.out.println(StreamSupport.stream(scanner.scan().spliterator(), false).count()); + } + } + } + } + +.. testoutput:: + + 1 + +Getting the Schema of a Dataset Review comment: Updated -- 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]
