aiguofer commented on code in PR #38404:
URL: https://github.com/apache/arrow/pull/38404#discussion_r1369218006


##########
java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/ArrowToJdbcUtils.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.arrow.driver.jdbc.utils;
+
+import java.math.BigDecimal;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.apache.arrow.vector.types.pojo.ArrowType;
+
+/**
+ * Helper class to convert Arrow types to JDBC required values.
+ */
+class ArrowToJdbcUtils {
+  static boolean isSigned(ArrowType.ArrowTypeID type) {
+    switch (type) {
+      case Int:
+      case FloatingPoint:
+      case Decimal:
+      case Interval:
+      case Duration:
+        return true;
+      default:
+        return false;
+    }
+  }
+
+  static int toJdbcType(ArrowType type) {
+    switch (type.getTypeID()) {
+      case Null:
+        return Types.NULL;
+      case Struct:
+        return Types.STRUCT;
+      case List:
+      case LargeList:
+      case FixedSizeList:
+        return Types.ARRAY;
+      case Int:
+        return ((ArrowType.Int) type).getBitWidth() == 64 ? Types.BIGINT : 
Types.INTEGER;
+      case FloatingPoint:
+        return Types.FLOAT;
+      case Utf8:
+      case LargeUtf8:
+        return Types.VARCHAR;
+      case Binary:
+      case LargeBinary:
+        return Types.VARBINARY;
+      case FixedSizeBinary:
+        return Types.BINARY;
+      case Bool:
+        return Types.BOOLEAN;
+      case Decimal:
+        return Types.DECIMAL;
+      case Date:
+        return Types.DATE;
+      case Time:
+        return Types.TIME;
+      case Timestamp:
+      case Interval:
+      case Duration:
+        return Types.TIMESTAMP;
+      default:
+        return Types.OTHER;
+    }
+
+  }
+
+  static String getClassName(ArrowType type) {
+    switch (type.getTypeID()) {
+      case List:
+      case LargeList:
+      case FixedSizeList:
+        return ArrayList.class.getCanonicalName();
+      case Map:
+        return HashMap.class.getCanonicalName();
+      case Int:
+        return ((ArrowType.Int) type).getBitWidth() == 64 ?
+                long.class.getCanonicalName() : int.class.getCanonicalName();
+      case FloatingPoint:
+        return float.class.getCanonicalName();
+      case Utf8:
+      case LargeUtf8:
+        return String.class.getCanonicalName();
+      case Binary:
+      case LargeBinary:
+      case FixedSizeBinary:
+        return byte[].class.getCanonicalName();
+      case Bool:
+        return boolean.class.getCanonicalName();
+      case Decimal:
+        return BigDecimal.class.getCanonicalName();
+      case Date:
+        return Date.class.getCanonicalName();
+      case Time:
+        return Time.class.getCanonicalName();
+      case Timestamp:
+      case Interval:
+      case Duration:
+        return Timestamp.class.getCanonicalName();
+      default:
+        return null;

Review Comment:
   Should I error instead?



##########
java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightPreparedStatement.java:
##########
@@ -50,36 +47,6 @@ private ArrowFlightPreparedStatement(final 
ArrowFlightConnection connection,
     this.preparedStatement = Preconditions.checkNotNull(preparedStatement);
   }
 
-  /**
-   * Creates a new {@link ArrowFlightPreparedStatement} from the provided 
information.
-   *
-   * @param connection           the {@link Connection} to use.
-   * @param statementHandle      the {@link StatementHandle} to use.
-   * @param signature            the {@link Signature} to use.
-   * @param resultSetType        the ResultSet type.
-   * @param resultSetConcurrency the ResultSet concurrency.
-   * @param resultSetHoldability the ResultSet holdability.
-   * @return a new {@link PreparedStatement}.
-   * @throws SQLException on error.
-   */
-  static ArrowFlightPreparedStatement createNewPreparedStatement(
-      final ArrowFlightConnection connection,
-      final StatementHandle statementHandle,
-      final Signature signature,
-      final int resultSetType,
-      final int resultSetConcurrency,
-      final int resultSetHoldability) throws SQLException {
-
-    final ArrowFlightSqlClientHandler.PreparedStatement prepare = 
connection.getClientHandler().prepare(signature.sql);
-    final Schema resultSetSchema = prepare.getDataSetSchema();
-
-    
signature.columns.addAll(ConvertUtils.convertArrowFieldsToColumnMetaDataList(resultSetSchema.getFields()));
-
-    return new ArrowFlightPreparedStatement(
-        connection, prepare, statementHandle,
-        signature, resultSetType, resultSetConcurrency, resultSetHoldability);
-  }
-

Review Comment:
   Unused method.



##########
java/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcFactory.java:
##########
@@ -89,12 +86,6 @@ public ArrowFlightPreparedStatement newPreparedStatement(
     ArrowFlightSqlClientHandler.PreparedStatement preparedStatement =
         flightConnection.getMeta().getPreparedStatement(statementHandle);
 
-    if (preparedStatement == null) {
-      preparedStatement = 
flightConnection.getClientHandler().prepare(signature.sql);
-    }
-    final Schema resultSetSchema = preparedStatement.getDataSetSchema();
-    
signature.columns.addAll(convertArrowFieldsToColumnMetaDataList(resultSetSchema.getFields()));
-

Review Comment:
   `newPreparedStatement` only gets called by 
`AvaticaConnection.newPreparedStatement`:
   
   ```
     public PreparedStatement prepareStatement(
         String sql,
         int resultSetType,
         int resultSetConcurrency,
         int resultSetHoldability) throws SQLException {
       checkOpen();
       try {
         final Meta.StatementHandle h = meta.prepare(handle, sql, -1);
         return factory.newPreparedStatement(this, h, h.signature, 
resultSetType,
             resultSetConcurrency, resultSetHoldability);
       } catch (RuntimeException e) {
         throw HELPER.createException("while preparing SQL: " + sql, e);
       }
     }
   ```
   
   The `columnMetaData` and `parameters` are already set up in 
`ArrowFlightMetaImpl.prepare` so there doesn't seem to be a reason to do this 
check again here.



-- 
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