FlightSqlClient Java Example
- 主要語言
- Java
- 星號
- 94
- 分支
- 152
- 平均合併
- 3 天 16 小時
- 30 天內合併 PR
- 11
描述
### 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
貢獻指南
研究方向
從 issue 中所示的 Java FlightClient.builder 用法開始,然後追蹤 FlightSqlClient 的建構方式,以及 execute(query, headerOption) 如何回傳 FlightInfo。在一個完整範例中驗證 allocator、location、headers 和 client 初始化,並確認它能夠連線、執行查詢並回傳結果。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- java
- 領域
- documentation
- Issue 類型
- 文件
- 難度
- 2/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 35/100