Skip to content

Commit

Permalink
Merge pull request apache#88 from rafael-telles/make-flight-sql-close…
Browse files Browse the repository at this point in the history
…-resources

Make FlightSqlClient AutoCloseable
  • Loading branch information
Abner Eduardo Ferreira authored Aug 23, 2021
2 parents 1d2699e + 0f19a60 commit 65204f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.apache.arrow.flight.sql.impl.FlightSql.ActionCreatePreparedStatementResult;
import org.apache.arrow.flight.sql.impl.FlightSql.CommandPreparedStatementQuery;
import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.util.AutoCloseables;
import org.apache.arrow.util.Preconditions;
import org.apache.arrow.vector.VectorSchemaRoot;
import org.apache.arrow.vector.types.pojo.Schema;
Expand All @@ -68,7 +69,7 @@
/**
* Flight client with Flight SQL semantics.
*/
public class FlightSqlClient {
public class FlightSqlClient implements AutoCloseable {
private final FlightClient client;

public FlightSqlClient(final FlightClient client) {
Expand Down Expand Up @@ -353,6 +354,11 @@ public PreparedStatement prepare(final String query, final CallOption... options
return new PreparedStatement(client, query, options);
}

@Override
public void close() throws Exception {
AutoCloseables.close(client);
}

/**
* Helper class to encapsulate Flight SQL prepared statement logic.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public class TestFlightSql {
private static int port;
private static BufferAllocator allocator;
private static FlightServer server;
private static FlightClient client;
private static FlightSqlClient sqlClient;
@Rule
public final ErrorCollector collector = new ErrorCollector();
Expand All @@ -121,8 +120,7 @@ public static void setUp() throws Exception {
.start();

final Location clientLocation = Location.forGrpcInsecure(LOCALHOST, server.getPort());
client = FlightClient.builder(allocator, clientLocation).build();
sqlClient = new FlightSqlClient(client);
sqlClient = new FlightSqlClient(FlightClient.builder(allocator, clientLocation).build());

GET_SQL_INFO_EXPECTED_RESULTS_MAP
.put(Integer.toString(ALL_SQL_INFO_ARGS[0]), "Apache Derby");
Expand All @@ -148,7 +146,7 @@ public static void setUp() throws Exception {

@AfterClass
public static void tearDown() throws Exception {
close(client, server, allocator);
close(sqlClient, server, allocator);
}

private static List<List<String>> getNonConformingResultsForGetSqlInfo(final List<? extends List<String>> results) {
Expand Down

0 comments on commit 65204f1

Please sign in to comment.