Skip to content

Commit e4f76b3

Browse files
committed
Reuse updated handle
1 parent 331e9ee commit e4f76b3

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/FlightSqlClient.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,7 @@ protected void updateCommandBuilder(CommandStatementIngest.Builder builder) {
12171217
public static class PreparedStatement implements AutoCloseable {
12181218
private final FlightClient client;
12191219
private final ActionCreatePreparedStatementResult preparedStatementResult;
1220+
private ByteString handle;
12201221
private VectorSchemaRoot parameterBindingRoot;
12211222
private boolean isClosed;
12221223
private Schema resultSetSchema;
@@ -1229,6 +1230,7 @@ public static class PreparedStatement implements AutoCloseable {
12291230
preparedStatementResult =
12301231
FlightSqlUtils.unpackAndParseOrThrow(
12311232
preparedStatementResults.next().getBody(), ActionCreatePreparedStatementResult.class);
1233+
handle = preparedStatementResult.getPreparedStatementHandle();
12321234
isClosed = false;
12331235
}
12341236

@@ -1292,8 +1294,7 @@ public SchemaResult fetchSchema(CallOption... options) {
12921294
FlightDescriptor.command(
12931295
Any.pack(
12941296
CommandPreparedStatementQuery.newBuilder()
1295-
.setPreparedStatementHandle(
1296-
preparedStatementResult.getPreparedStatementHandle())
1297+
.setPreparedStatementHandle(handle)
12971298
.build())
12981299
.toByteArray());
12991300
return client.getSchema(descriptor, options);
@@ -1324,8 +1325,7 @@ public FlightInfo execute(final CallOption... options) {
13241325
FlightDescriptor.command(
13251326
Any.pack(
13261327
CommandPreparedStatementQuery.newBuilder()
1327-
.setPreparedStatementHandle(
1328-
preparedStatementResult.getPreparedStatementHandle())
1328+
.setPreparedStatementHandle(handle)
13291329
.build())
13301330
.toByteArray());
13311331

@@ -1339,12 +1339,16 @@ public FlightInfo execute(final CallOption... options) {
13391339
try (final ArrowBuf metadata = read.getApplicationMetadata()) {
13401340
final FlightSql.DoPutPreparedStatementResult doPutPreparedStatementResult =
13411341
FlightSql.DoPutPreparedStatementResult.parseFrom(metadata.nioBuffer());
1342+
final ByteString updatedHandle =
1343+
doPutPreparedStatementResult.getPreparedStatementHandle();
1344+
if (!updatedHandle.isEmpty()) {
1345+
handle = updatedHandle;
1346+
}
13421347
descriptor =
13431348
FlightDescriptor.command(
13441349
Any.pack(
13451350
CommandPreparedStatementQuery.newBuilder()
1346-
.setPreparedStatementHandle(
1347-
doPutPreparedStatementResult.getPreparedStatementHandle())
1351+
.setPreparedStatementHandle(handle)
13481352
.build())
13491353
.toByteArray());
13501354
}
@@ -1396,8 +1400,7 @@ public long executeUpdate(final CallOption... options) {
13961400
FlightDescriptor.command(
13971401
Any.pack(
13981402
CommandPreparedStatementUpdate.newBuilder()
1399-
.setPreparedStatementHandle(
1400-
preparedStatementResult.getPreparedStatementHandle())
1403+
.setPreparedStatementHandle(handle)
14011404
.build())
14021405
.toByteArray());
14031406
setParameters(parameterBindingRoot == null ? VectorSchemaRoot.of() : parameterBindingRoot);
@@ -1434,8 +1437,7 @@ public void close(final CallOption... options) {
14341437
FlightSqlUtils.FLIGHT_SQL_CLOSE_PREPARED_STATEMENT.getType(),
14351438
Any.pack(
14361439
ActionClosePreparedStatementRequest.newBuilder()
1437-
.setPreparedStatementHandle(
1438-
preparedStatementResult.getPreparedStatementHandle())
1440+
.setPreparedStatementHandle(handle)
14391441
.build())
14401442
.toByteArray());
14411443
final Iterator<Result> closePreparedStatementResults = client.doAction(action, options);

0 commit comments

Comments
 (0)