apache / apache/arrow-java

FlightSqlClient Java Example

Ouverte
#204 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
Type: usage
Langage dominant
Java
Étoiles
94
Forks
152
Merge moyen
3 j 16 h
PR mergées (30 j)
11

Description

### Describe the usage question you have. Please include as many useful details as possible.

Hello,
I am trying to increase adoption of the Java FlightSqlClient by providing examples of how to connect to a server with it, execute a query, and return the result.
I’ve tried the following:

package com.example.helloworld;

// Import Apache Arrow Flight SQL classes
import org.apache.arrow.flight.*;
import org.apache.arrow.flight.sql.FlightSqlClient;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.VectorSchemaRoot;
import io.grpc.Metadata;
import java.net.URI;

public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
String host = "us-east-1-1.aws.cloud2.influxdata.com";
String query = "SELECT * FROM \"airSensors\"";
Location location = Location.forGrpcInsecure(host, 443).forGrpcTls(host, 0);

// BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE);

// FlightClient flightClient = FlightClient.builder().build();

CallHeaders headers = new FlightCallHeaders();
headers.insert("token", "xxx==");
headers.insert("bucket-name", "anais-iox");
HeaderCallOption headerOption = new HeaderCallOption(headers);
BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE);

try {
client = FlightClient.builder()
.location(location)
.build();
System.out.println(client);
FlightSqlClient sqlClient = new FlightSqlClient(client);
System.out.println(sqlClient);
FlightInfo flightInfo = sqlClient.execute(query, headerOption);
FlightEndpoint endpoint = flightInfo.getEndpoints().get(0);
Ticket ticket = endpoint.getTicket();
System.out.println("Hello, World!");
} catch (Exception e) {
System.out.println("Error creating FlightClient: " + e.getMessage());
}

}
}
But I get Client cannot be null!

Additionally I’ve tried to pass in the allocator into the build method:

FlightClient client = FlightClient.builder(allocator, location).build();
But I’m not having success with that either.
Does anyone here have an example of how to use the FlightSqlClient? Or can identify what I’m doing wrong here? Thank you in advance for any pointers or help. I greatly appreciate it.

### Component(s)

Java

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Commencez par l’utilisation de Java FlightClient.builder présentée dans l’issue, puis suivez la manière dont FlightSqlClient est construit et dont execute(query, headerOption) renvoie FlightInfo. Vérifiez l’allocator, l’emplacement, les en-têtes et l’initialisation du client dans un exemple complet, puis confirmez qu’il se connecte, exécute la requête et renvoie le résultat.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
java
Domaine
documentation
Type d'issue
Documentation
Difficulté
2/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.