lidavidm commented on code in PR #42035:
URL: https://github.com/apache/arrow/pull/42035#discussion_r1632453636


##########
java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandler.java:
##########
@@ -254,6 +276,21 @@ public interface PreparedStatement extends AutoCloseable {
    * @return a new prepared statement.
    */
   public PreparedStatement prepare(final String query) {
+    if (hasCatalog()) {
+      final SetSessionOptionsRequest setSessionOptionRequest =
+              new SetSessionOptionsRequest(ImmutableMap.<String, 
SessionOptionValue>builder()
+                      .put(CATALOG, 
SessionOptionValueFactory.makeSessionOptionValue(catalog))
+                      .build());
+      final SetSessionOptionsResult result = 
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 new RuntimeException(String.format("Cannot set session option 
for catalog = %s", catalog));

Review Comment:
   Preferably throw a more specific exception?



##########
java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandler.java:
##########
@@ -254,6 +276,21 @@ public interface PreparedStatement extends AutoCloseable {
    * @return a new prepared statement.
    */
   public PreparedStatement prepare(final String query) {
+    if (hasCatalog()) {

Review Comment:
   Would we really do this every time we execute a query? Shouldn't it be set 
once up front?



##########
java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandler.java:
##########
@@ -194,13 +209,20 @@ public FlightInfo getInfo(final String query) {
 
   @Override
   public void close() throws SQLException {
+    if (hasCatalog()) {
+      sqlClient.closeSession(new CloseSessionRequest(), getOptions());
+    }
     try {
       AutoCloseables.close(sqlClient);
     } catch (final Exception e) {
       throw new SQLException("Failed to clean up client resources.", e);
     }
   }
 
+  private boolean hasCatalog() {
+    return !Strings.isNullOrEmpty(catalog);

Review Comment:
   Might prefer `Optional<String>` 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to