Java SDK
Java SDK for Spice.ai​
https://github.com/spiceai/spice-java
Installation​
- Maven
- Gradle
Add the following dependency:
<dependency>
    <groupId>ai.spice</groupId>
    <artifactId>spiceai</artifactId>
    <version>0.1.0</version>
    <scope>compile</scope>
</dependency>
Add the following dependency:
implementation 'ai.spice:spiceai:0.1.0'
Connect to Spice runtime​
Create a SpiceClient using default configuration.
Requires local Spice OSS running: follow the quickstart
import org.apache.arrow.flight.FlightStream;
import ai.spice.SpiceClient;
public class App 
{
    public static void main( String[] args )
    {
        try {
            SpiceClient client = SpiceClient.builder()
                    .build();
            FlightStream res = client.query("SELECT \"VendorID\", \"tpep_pickup_datetime\", \"fare_amount\" FROM taxi_trips LIMIT 10");
            while (res.next()) {
                System.out.println(res.getRoot().contentToTSVString());
            }
        } catch (Exception e) {
            System.err.println("An unexpected error occurred: " + e.getMessage());
        }
    }
}
Or pass custom flight address:
SpiceClient client = SpiceClient.builder()
    .withFlightAddress(new URI("grpc://my_remote_spice_instance:50051"))
    .build();
Connection retry​
The SpiceClient implements connection retry mechanism (3 attempts by default).
The number of attempts can be configured with withMaxRetries:
SpiceClient client = SpiceClient.builder()
    .withMaxRetries(5) // Setting to 0 will disable retries
    .build();
Retries are performed for connection and system internal errors. It is the SDK user's responsibility to properly handle other errors, for example RESOURCE_EXHAUSTED (HTTP 429).
