Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -253,26 +253,37 @@ ArrowFlightPreparedStatement build() throws SQLException {
} catch (final FlightRuntimeException e) {
throw new SQLException(e.getMessage(), e);
}
final Signature signature =
ArrowFlightMetaImpl.buildSignature(
query,
preparedStatement.getDataSetSchema(),
preparedStatement.getParameterSchema(),
preparedStatement.isUpdate());
try {
final Signature signature =
ArrowFlightMetaImpl.buildSignature(
query,
preparedStatement.getDataSetSchema(),
preparedStatement.getParameterSchema(),
preparedStatement.isUpdate());

final ArrowFlightPreparedStatement statement =
new ArrowFlightPreparedStatement(
connection,
generateHandle ? null : handle,
signature,
preparedStatement,
resultSetType,
resultSetConcurrency,
resultSetHoldability);
if (generateHandle) {
connection.registerStatementOwner(statement);
final ArrowFlightPreparedStatement statement =
new ArrowFlightPreparedStatement(
connection,
generateHandle ? null : handle,
signature,
preparedStatement,
resultSetType,
resultSetConcurrency,
resultSetHoldability);
if (generateHandle) {
connection.registerStatementOwner(statement);
}
return statement;
} catch (final SQLException | RuntimeException | Error buildFailure) {
try {
preparedStatement.close();
} catch (final RuntimeException | Error closeFailure) {
if (closeFailure != buildFailure) {
buildFailure.addSuppressed(closeFailure);
}
}
throw buildFailure;
}
return statement;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.TimeZone;
import org.apache.arrow.driver.jdbc.utils.CoreMockedSqlProducers;
import org.apache.arrow.driver.jdbc.utils.MockFlightSqlProducer;
import org.apache.arrow.flight.CallStatus;
import org.apache.arrow.flight.FlightRuntimeException;
import org.apache.arrow.flight.sql.FlightSqlUtils;
import org.apache.arrow.memory.BufferAllocator;
Expand Down Expand Up @@ -174,6 +175,42 @@ public void testPrepareFailureIsReportedAsSQLException() {
assertThat(exception.getCause(), instanceOf(FlightRuntimeException.class));
}

@Test
public void testPreparedStatementIsClosedWhenSignatureBuildingFails() {
final String query = "UPDATE unsupported_parameter_type";
final Schema parameterSchema =
new Schema(Collections.singletonList(Field.nullable("", ArrowType.ListView.INSTANCE)));
PRODUCER.addUpdateQuery(query, 1);
PRODUCER.addExpectedParameters(query, parameterSchema, Collections.emptyList());
PRODUCER.setClosePreparedStatementFailure(CallStatus.INTERNAL.withDescription("Close failed"));

try {
final SQLException exception =
assertThrows(SQLException.class, () -> connection.prepareStatement(query));
Throwable buildFailure = exception;
while (buildFailure != null && !(buildFailure instanceof UnsupportedOperationException)) {
buildFailure = buildFailure.getCause();
}

assertThat(buildFailure, instanceOf(UnsupportedOperationException.class));
assertEquals(1, buildFailure.getSuppressed().length);
assertThat(buildFailure.getSuppressed()[0], instanceOf(FlightRuntimeException.class));
assertTrue(buildFailure.getSuppressed()[0].getMessage().contains("Close failed"));
assertEquals(
1,
PRODUCER
.getActionTypeCounter()
.getOrDefault(FlightSqlUtils.FLIGHT_SQL_CREATE_PREPARED_STATEMENT.getType(), 0));
assertEquals(
1,
PRODUCER
.getActionTypeCounter()
.getOrDefault(FlightSqlUtils.FLIGHT_SQL_CLOSE_PREPARED_STATEMENT.getType(), 0));
} finally {
PRODUCER.setClosePreparedStatementFailure(null);
}
}

@Test
public void testNullQueryIsReportedAsSQLException() {
assertThrows(SQLException.class, () -> connection.prepareStatement(null));
Expand Down
Loading