Skip to content

java: Flight SQL driver doesn't properly pass rpc headers when executing prepared statements #3582

@rnowacoski

Description

@rnowacoski

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",

Metadata

Metadata

Assignees

Labels

Type: bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions