davisusanibar commented on code in PR #229: URL: https://github.com/apache/arrow-cookbook/pull/229#discussion_r920558032
########## java/source/io.rst: ########## @@ -444,6 +444,176 @@ Reading Parquet File Please check :doc:`Dataset <./dataset>` +Reading JDBC ResultSets +*********************** + +The `Arrow Java JDBC module <https://arrow.apache.org/docs/java/jdbc.html>`_ +help us to convert JDBC ResultSets objects into columnar arrow format objects +through Arrow VectorSchemaRoots. + +ResultSet to VectorSchemaRoot Conversion +---------------------------------------- + +The main class to help us to convert ResultSet to VectorSchemaRoot is +`JdbcToArrow <https://arrow.apache.org/docs/java/reference/org/apache/arrow/adapter/jdbc/JdbcToArrow.html>`_ + +.. testcode:: + + import org.apache.arrow.adapter.jdbc.ArrowVectorIterator; + import org.apache.arrow.adapter.jdbc.JdbcToArrow; + import org.apache.arrow.memory.BufferAllocator; + import org.apache.arrow.memory.RootAllocator; + import org.apache.arrow.vector.VectorSchemaRoot; + import org.h2.jdbcx.JdbcConnectionPool; + + import java.io.IOException; + import java.sql.ResultSet; + import java.sql.SQLException; + + try (BufferAllocator allocator = new RootAllocator()) { + JdbcConnectionPool pool = JdbcConnectionPool.create( + "jdbc:h2:zip:./thirdpartydeps/database/jdbc-cookbook.zip!/test", + "sa", ""); + ResultSet resultSet = pool.getConnection().createStatement().executeQuery( + "SELECT int_field1, bool_field2, double_field7 FROM TABLE1"); + try (ArrowVectorIterator iterator = JdbcToArrow.sqlToArrowVectorIterator( + resultSet, allocator)) { + while (iterator.hasNext()) { + VectorSchemaRoot root = iterator.next(); + System.out.print(root.contentToTSVString()); + } + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + +.. testoutput:: + + INT_FIELD1 BOOL_FIELD2 DOUBLE_FIELD7 + 101 true 5.6478356785345E10 + 102 true 5.6478356785345E10 + 103 true 5.6478356785345E10 + +JdbcToArrow could be created also with a custom configurations needed with the +support of `JdbcToArrowConfig <https://arrow.apache.org/docs/java/reference/org/apache/arrow/adapter/jdbc/JdbcToArrowConfig.html>`_ +, it is useful at the moment to work with array columns. Review Comment: > We talk about arrays and row counts here, what about decimals and other things Todd added? I just read that, let me add that also -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org