-
Notifications
You must be signed in to change notification settings - Fork 173
Description
What happened?
In FlightSqlStatement.executeFlightInfo for regular queries it will use the client to call execute. Because the client in FlightSqlStatement is a FlightSqlClientWithCallOptions it includes the rpc headers from previous calls as call options.
However, for a prepared statement it uses FlightSqlClient.PreparedStatement::execute which uses a regular FlientClient. It also doesn't pass the Call Options to FlightSqlClient.PreparedStatement::execute. Therefore the RPC Headers which are stored as Call Options are not included in the query execution.
For a Flight SQL Server that uses token-based authentication this will result in an unauthenticated exception like below
AdbcException{message=, status=UNAUTHENTICATED, sqlState='null', vendorCode=0, cause=null, details=1}
Stack Trace
No response
How can we reproduce the bug?
You need a Flight SQL Server that uses token-based authentication. Then you can use the code below to reproduce this issue.
String flightSqlUrl = "localhost:9090";
String token = "TEST";
Map<String, Object> parameters = new HashMap<>();
parameters.put(AdbcDriver.PARAM_URI.getKey(), "grpc://"+flightSqlUrl);
parameters.put(FlightSqlConnectionProperties.RPC_CALL_HEADER_PREFIX + "Authorization", "Bearer " + token);
BufferAllocator rootAllocator = new RootAllocator();
var adbcDatabase = new FlightSqlDriver(rootAllocator).open(parameters);
// connect(), createStatement() and prepare() all work as expected
try (
final AdbcConnection = adbcDatabase.connect();
final AdbcStatement statement = adbcConnection.createStatement()
) {
statement.setSqlQuery(query);
statement.prepare();
// statment.executeQuery() is where this will fail due lack of authentication
try (final AdbcStatement.QueryResult result = statement.executeQuery()) {
final ArrowReader reader = result.getReader();
final VectorSchemaRoot root = reader.getVectorSchemaRoot();
}
}Environment/Setup
This is using the following dependencies
"org.apache.arrow.adbc" % "adbc-driver-flight-sql" % "0.20.0",