forked from dremio-hub/arrow-flight-client-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Dremio's Flight SQL Client Demo App #2
Open
vfraga
wants to merge
7
commits into
main
Choose a base branch
from
added-flight-sql-demo-app
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a777c0e
Added Dremios Flight SQL Client Demo App
vfraga bde1586
NIT
vfraga 705429e
Adapt changes from base FlightSqlClient
vfraga 4581299
Added changes from base FlightSqlClientDemoApp
vfraga 1e1d6c0
Apply changes from FlightSqlClientDemoApp
vfraga 59d6606
Remove redundant code
vfraga 7723c62
NIT: Add slightly more info to Javadoc
vfraga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
java/src/main/java/com/adhoc/flight/sql/DremioFlightSqlClientDemoApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.adhoc.flight.sql; | ||
|
||
import org.apache.arrow.flight.CallOption; | ||
import org.apache.arrow.flight.FlightClient; | ||
import org.apache.arrow.flight.Location; | ||
import org.apache.arrow.flight.auth2.BasicAuthCredentialWriter; | ||
import org.apache.arrow.flight.auth2.ClientBearerHeaderHandler; | ||
import org.apache.arrow.flight.auth2.ClientIncomingAuthHeaderMiddleware; | ||
import org.apache.arrow.flight.grpc.CredentialCallOption; | ||
import org.apache.arrow.flight.sql.FlightSqlClient; | ||
import org.apache.arrow.flight.sql.example.FlightSqlClientDemoApp; | ||
import org.apache.arrow.memory.BufferAllocator; | ||
import org.apache.arrow.memory.RootAllocator; | ||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.CommandLineParser; | ||
import org.apache.commons.cli.DefaultParser; | ||
import org.apache.commons.cli.HelpFormatter; | ||
import org.apache.commons.cli.Options; | ||
import org.apache.commons.cli.ParseException; | ||
|
||
/** | ||
* Dremio's Flight SQL Client Demo CLI Application. | ||
*/ | ||
public class DremioFlightSqlClientDemoApp extends FlightSqlClientDemoApp { | ||
|
||
public DremioFlightSqlClientDemoApp(BufferAllocator bufferAllocator) { | ||
super(bufferAllocator); | ||
} | ||
|
||
public static void main(final String[] args) throws Exception { | ||
final Options options = new Options(); | ||
|
||
options.addRequiredOption("host", "host", true, "Host to connect to"); | ||
options.addRequiredOption("port", "port", true, "Port to connect to"); | ||
options.addRequiredOption("command", "command", true, "Method to run"); | ||
options.addRequiredOption("username", "username", true, "Auth username"); | ||
options.addRequiredOption("password", "password", true, "Auth password"); | ||
|
||
options.addOption("query", "query", true, "Query"); | ||
options.addOption("catalog", "catalog", true, "Catalog"); | ||
options.addOption("schema", "schema", true, "Schema"); | ||
options.addOption("table", "table", true, "Table"); | ||
|
||
CommandLineParser parser = new DefaultParser(); | ||
HelpFormatter formatter = new HelpFormatter(); | ||
CommandLine cmd; | ||
|
||
try { | ||
cmd = parser.parse(options, args); | ||
try (final DremioFlightSqlClientDemoApp thisApp = new DremioFlightSqlClientDemoApp( | ||
new RootAllocator(Integer.MAX_VALUE))) { | ||
thisApp.executeApp(cmd); | ||
} | ||
|
||
} catch (final ParseException e) { | ||
System.out.println(e.getMessage()); | ||
formatter.printHelp("DremioFlightSqlClientDemoApp -host localhost -port 32010 ...", options); | ||
throw e; | ||
} | ||
} | ||
|
||
/** | ||
* Adds a {@link CallOption} to the current {@code callOptions} array. | ||
*/ | ||
public void addCallOption(final CallOption optionToAdd) { | ||
callOptions.add(optionToAdd); | ||
} | ||
|
||
/** | ||
* Calls {@link DremioFlightSqlClientDemoApp#createFlightSqlClient(String, String, String, String)} | ||
* in order to create a {@link FlightSqlClient} to be used in future calls, | ||
* and then calls {@link DremioFlightSqlClientDemoApp#executeCommand(CommandLine)} | ||
* to execute the command parsed at execution. | ||
* | ||
* @param cmd Parsed {@link CommandLine}; often the result of {@link DefaultParser#parse(Options, String[])}. | ||
*/ | ||
public void executeApp(CommandLine cmd) throws Exception { | ||
createFlightSqlClient( | ||
cmd.getOptionValue("host").trim(), cmd.getOptionValue("port").trim(), | ||
cmd.getOptionValue("username").trim(), cmd.getOptionValue("password").trim()); | ||
executeCommand(cmd); | ||
} | ||
|
||
/** | ||
* Creates a {@link FlightSqlClient} to be used with the example methods. | ||
* | ||
* @param host client's hostname. | ||
* @param port client's port. | ||
* @param user client's username auth. | ||
* @param pass client's password auth. | ||
*/ | ||
public void createFlightSqlClient(final String host, final String port, final String user, final String pass) { | ||
final ClientIncomingAuthHeaderMiddleware.Factory factory = | ||
new ClientIncomingAuthHeaderMiddleware.Factory(new ClientBearerHeaderHandler()); | ||
final FlightClient client = FlightClient.builder() | ||
.allocator(allocator) | ||
.location(Location.forGrpcInsecure(host, Integer.parseInt(port))) | ||
.intercept(factory) | ||
.build(); | ||
client.handshake(new CredentialCallOption(new BasicAuthCredentialWriter(user, pass))); | ||
addCallOption(factory.getCredentialCallOption()); | ||
flightSqlClient = new FlightSqlClient(client); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this have feature parity with the existing Flight demo app? I don't see options relating to SSL, or the ability to choose to output between CSV and to a binary file.