From 8c30b1a4ab0387a4cba5a9c6a3bb2f61e0f56fc5 Mon Sep 17 00:00:00 2001 From: Steve Lord Date: Tue, 11 Jun 2024 14:51:50 -0700 Subject: [PATCH] GH-41947: [Java] Support catalog in JDBC driver with session options Spotless update --- .../client/ArrowFlightSqlClientHandler.java | 25 +++++++++---------- ...rrowFlightSqlClientHandlerBuilderTest.java | 4 +-- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandler.java b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandler.java index 122be08deae0b..1ae4ed17887d7 100644 --- a/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandler.java +++ b/java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandler.java @@ -99,7 +99,8 @@ static ArrowFlightSqlClientHandler createNewHandler( final Builder builder, final Collection options, final Optional catalog) { - final ArrowFlightSqlClientHandler handler = new ArrowFlightSqlClientHandler(new FlightSqlClient(client), builder, options, catalog); + final ArrowFlightSqlClientHandler handler = + new ArrowFlightSqlClientHandler(new FlightSqlClient(client), builder, options, catalog); handler.setSetCatalogInSessionIfPresent(); return handler; } @@ -272,18 +273,16 @@ public interface PreparedStatement extends AutoCloseable { void close(); } - /** - * A connection is created with catalog set as a session option. - */ + /** A connection is created with catalog set as a session option. */ private void setSetCatalogInSessionIfPresent() { if (catalog.isPresent()) { final SetSessionOptionsRequest setSessionOptionRequest = - new SetSessionOptionsRequest( - ImmutableMap.builder() - .put(CATALOG, SessionOptionValueFactory.makeSessionOptionValue(catalog.get())) - .build()); + new SetSessionOptionsRequest( + ImmutableMap.builder() + .put(CATALOG, SessionOptionValueFactory.makeSessionOptionValue(catalog.get())) + .build()); final SetSessionOptionsResult result = - sqlClient.setSessionOptions(setSessionOptionRequest, getOptions()); + sqlClient.setSessionOptions(setSessionOptionRequest, getOptions()); if (result.hasErrors()) { Map errors = result.getErrors(); @@ -291,10 +290,10 @@ private void setSetCatalogInSessionIfPresent() { LOGGER.warn(error.toString()); } throw CallStatus.INVALID_ARGUMENT - .withDescription( - String.format( - "Cannot set session option for catalog = %s. Check log for details.", catalog)) - .toRuntimeException(); + .withDescription( + String.format( + "Cannot set session option for catalog = %s. Check log for details.", catalog)) + .toRuntimeException(); } } } diff --git a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandlerBuilderTest.java b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandlerBuilderTest.java index a65117f8ea375..011fb475cfc0e 100644 --- a/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandlerBuilderTest.java +++ b/java/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandlerBuilderTest.java @@ -24,7 +24,6 @@ import static org.junit.Assert.assertTrue; import java.util.Optional; - import org.apache.arrow.driver.jdbc.FlightServerTestRule; import org.apache.arrow.driver.jdbc.utils.CoreMockedSqlProducers; import org.apache.arrow.memory.BufferAllocator; @@ -150,8 +149,7 @@ public void testDefaults() { @Test public void testCatalog() { - ArrowFlightSqlClientHandler.Builder rootBuilder = - new ArrowFlightSqlClientHandler.Builder(); + ArrowFlightSqlClientHandler.Builder rootBuilder = new ArrowFlightSqlClientHandler.Builder(); rootBuilder.withCatalog(null); assertFalse(rootBuilder.catalog.isPresent());