diff --git a/docs/api/java/index.rst b/docs/api/java/index.rst index 9cb815a0aba..9d19f16d7e7 100644 --- a/docs/api/java/index.rst +++ b/docs/api/java/index.rst @@ -46,14 +46,31 @@ Here's a basic example of using the Vortex Java API to read a Vortex file: .. code-block:: java - import dev.vortex.api.File; - import dev.vortex.api.Array; - - // Open a Vortex file - File vortexFile = File.open("path/to/file.vortex"); - - // Read arrays from the file - Array array = vortexFile.readArray(); - - // Work with the array data - System.out.println("Array length: " + array.getLength()); + import dev.vortex.api.DataSource; + import dev.vortex.api.Partition; + import dev.vortex.api.Scan; + import dev.vortex.api.ScanOptions; + import dev.vortex.api.Session; + import dev.vortex.arrow.ArrowAllocation; + import org.apache.arrow.memory.BufferAllocator; + import org.apache.arrow.vector.VectorSchemaRoot; + import org.apache.arrow.vector.ipc.ArrowReader; + + BufferAllocator allocator = ArrowAllocation.rootAllocator(); + Session session = Session.create(); + DataSource source = DataSource.open(session, "path/to/file.vortex"); + + // A scan yields one partition per chunk of the file. + Scan scan = source.scan(ScanOptions.of()); + while (scan.hasNext()) { + Partition partition = scan.next(); + try (ArrowReader reader = partition.scanArrow(allocator)) { + while (reader.loadNextBatch()) { + VectorSchemaRoot batch = reader.getVectorSchemaRoot(); + System.out.println("read " + batch.getRowCount() + " rows"); + } + } + } + +Data crosses the JNI boundary as Arrow record batches, so the buffers stay in native memory and +are read from Java through the Arrow C Data Interface.