Skip to content
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
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<arrow.version>3.0.0</arrow.version>
<arrow.snapshot.version>6.0.0-SNAPSHOT</arrow.snapshot.version>
<dep.guava.version>20.0</dep.guava.version>
<checkstyle.failOnViolation>true</checkstyle.failOnViolation>
</properties>
Expand All @@ -27,7 +28,7 @@
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>flight-core</artifactId>
<version>${arrow.version}</version>
<version>${arrow.snapshot.version}</version>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
Expand All @@ -46,7 +47,12 @@
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>flight-grpc</artifactId>
<version>${arrow.version}</version>
<version>${arrow.snapshot.version}</version>
</dependency>
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>flight-sql</artifactId>
<version>${arrow.snapshot.version}</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
Expand Down
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");
Copy link

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.

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);
}
}