apache / apache/arrow-java

FlightSqlClient Java Example

オープン
#204 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
Type: usage
主要言語
Java
スター
94
フォーク
152
平均マージ
3日 16時間
マージ済み PR(30日)
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

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。