Skip to content

Commit

Permalink
apacheGH-41947: [Java] Support catalog in JDBC driver with session op…
Browse files Browse the repository at this point in the history
…tions

Spotless update
  • Loading branch information
stevelorddremio committed Jun 11, 2024
1 parent e6a0b63 commit 8c30b1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ static ArrowFlightSqlClientHandler createNewHandler(
final Builder builder,
final Collection<CallOption> options,
final Optional<String> 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;
}
Expand Down Expand Up @@ -272,29 +273,27 @@ 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.<String, SessionOptionValue>builder()
.put(CATALOG, SessionOptionValueFactory.makeSessionOptionValue(catalog.get()))
.build());
new SetSessionOptionsRequest(
ImmutableMap.<String, SessionOptionValue>builder()
.put(CATALOG, SessionOptionValueFactory.makeSessionOptionValue(catalog.get()))
.build());
final SetSessionOptionsResult result =
sqlClient.setSessionOptions(setSessionOptionRequest, getOptions());
sqlClient.setSessionOptions(setSessionOptionRequest, getOptions());

if (result.hasErrors()) {
Map<String, SetSessionOptionsResult.Error> errors = result.getErrors();
for (Map.Entry<String, SetSessionOptionsResult.Error> error : errors.entrySet()) {
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();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 8c30b1a

Please sign in to comment.