Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions docs/api/java/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Loading