[ 
https://issues.apache.org/jira/browse/ARROW-1780?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16434155#comment-16434155
 ] 

ASF GitHub Bot commented on ARROW-1780:
---------------------------------------

laurentgo commented on a change in pull request #1759: ARROW-1780 - [WIP] JDBC 
Adapter to convert Relational Data objects to Arrow Data Format Vector Objects
URL: https://github.com/apache/arrow/pull/1759#discussion_r180249672
 
 

 ##########
 File path: 
java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrow.java
 ##########
 @@ -64,53 +68,48 @@
      * @param connection Database connection to be used. This method will not 
close the passed connection object. Since hte caller has passed
      *                   the connection object it's the responsibility of the 
caller to close or return the connection to the pool.
      * @param query The DB Query to fetch the data.
-     * @return
-     * @throws SQLException Propagate any SQL Exceptions to the caller after 
closing any resources opened such as ResultSet and Statment objects.
+     * @return Arrow Data Objects {@link VectorSchemaRoot}
+     * @throws SQLException Propagate any SQL Exceptions to the caller after 
closing any resources opened such as ResultSet and Statement objects.
      */
-    public static VectorSchemaRoot sqlToArrow(Connection connection, String 
query) throws Exception {
-
-        assert connection != null: "JDBC conncetion object can not be null";
-        assert query != null && query.length() > 0: "SQL query can not be null 
or empty";
-
-        RootAllocator rootAllocator = new RootAllocator(Integer.MAX_VALUE);
+    public static VectorSchemaRoot sqlToArrow(Connection connection, String 
query, RootAllocator rootAllocator) throws SQLException {
+        Preconditions.checkNotNull(connection, "JDBC connection object can not 
be null");
+        Preconditions.checkArgument(query != null && query.length() > 0, "SQL 
query can not be null or empty");
 
-        Statement stmt = null;
-        ResultSet rs = null;
-        try {
-            stmt = connection.createStatement();
-            rs = stmt.executeQuery(query);
-            ResultSetMetaData rsmd = rs.getMetaData();
-            VectorSchemaRoot root = VectorSchemaRoot.create(
-                    JdbcToArrowUtils.jdbcToArrowSchema(rsmd), rootAllocator);
-            JdbcToArrowUtils.jdbcToArrowVectors(rs, root);
-            return root;
-        } catch (Exception exc) {
-            // just throw it out after logging
-            throw exc;
-        } finally {
-            if (rs != null) {
-                rs.close();
-            }
-            if (stmt != null) {
-                stmt.close(); // test
-            }
+        try (Statement stmt = connection.createStatement()) {
+            return sqlToArrow(stmt.executeQuery(query), rootAllocator);
         }
     }
 
     /**
-     * This method returns ArrowDataFetcher Object that can be used to fetch 
and iterate on the data in the given
-     * database table.
-     *
-     * @param connection - Database connection Object
-     * @param tableName - Table name from which records will be fetched
+     * For the given JDBC {@link ResultSet}, fetch the data from Relational DB 
and convert it to Arrow objects.
      *
-     * @return ArrowDataFetcher - Instance of ArrowDataFetcher which can be 
used to get Arrow Vector obejcts by calling its functionality
+     * @param resultSet
+     * @return Arrow Data Objects {@link VectorSchemaRoot}
+     * @throws Exception
      */
-    public static ArrowDataFetcher jdbcArrowDataFetcher(Connection connection, 
String tableName) {
-        assert connection != null: "JDBC conncetion object can not be null";
-        assert tableName != null && tableName.length() > 0: "Table name can 
not be null or empty";
+    public static VectorSchemaRoot sqlToArrow(ResultSet resultSet) throws 
SQLException {
+        Preconditions.checkNotNull(resultSet, "JDBC ResultSet object can not 
be null");
 
-        return new ArrowDataFetcher(connection, tableName);
+        RootAllocator rootAllocator = new RootAllocator(Integer.MAX_VALUE);
+        VectorSchemaRoot root = sqlToArrow(resultSet, rootAllocator);
+        rootAllocator.close();
+        return root;
     }
 
+    /**
+     * For the given JDBC {@link ResultSet}, fetch the data from Relational DB 
and convert it to Arrow objects.
+     *
+     * @param resultSet
+     * @return Arrow Data Objects {@link VectorSchemaRoot}
+     * @throws Exception
+     */
+    public static VectorSchemaRoot sqlToArrow(ResultSet resultSet, 
RootAllocator rootAllocator) throws SQLException {
 
 Review comment:
   I know I mentioned RootAllocator, but I guess BufferAllocator (which is the 
base interface) would work as well?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> JDBC Adapter for Apache Arrow
> -----------------------------
>
>                 Key: ARROW-1780
>                 URL: https://issues.apache.org/jira/browse/ARROW-1780
>             Project: Apache Arrow
>          Issue Type: New Feature
>            Reporter: Atul Dambalkar
>            Assignee: Atul Dambalkar
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 0.10.0
>
>
> At a high level the JDBC Adapter will allow upstream apps to query RDBMS data 
> over JDBC and get the JDBC objects converted to Arrow objects/structures. The 
> upstream utility can then work with Arrow objects/structures with usual 
> performance benefits. The utility will be very much similar to C++ 
> implementation of "Convert a vector of row-wise data into an Arrow table" as 
> described here - 
> https://arrow.apache.org/docs/cpp/md_tutorials_row_wise_conversion.html
> The utility will read data from RDBMS and covert the data into Arrow 
> objects/structures. So from that perspective this will Read data from RDBMS, 
> If the utility can push Arrow objects to RDBMS is something need to be 
> discussed and will be out of scope for this utility for now. 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to