6868 */
6969public class JdbcToArrow {
7070
71+ public static final String SQL_CATALOG_NAME_KEY = "SQL_CATALOG_NAME" ;
72+ public static final String SQL_TABLE_NAME_KEY = "SQL_TABLE_NAME" ;
73+ public static final String SQL_COLUMN_NAME_KEY = "SQL_COLUMN_NAME" ;
74+ public static final String SQL_TYPE_KEY = "SQL_TYPE" ;
75+
7176 /**
7277 * For the given SQL query, execute and fetch the data from Relational DB and convert it to Arrow objects.
7378 * This method uses the default Calendar instance with default TimeZone and Locale as returned by the JVM.
@@ -89,7 +94,8 @@ public static VectorSchemaRoot sqlToArrow(Connection connection, String query, B
8994 Preconditions .checkArgument (query != null && query .length () > 0 , "SQL query can not be null or empty" );
9095 Preconditions .checkNotNull (allocator , "Memory allocator object can not be null" );
9196
92- return sqlToArrow (connection , query , allocator , Calendar .getInstance (TimeZone .getTimeZone ("UTC" ), Locale .ROOT ));
97+ return sqlToArrow (connection , query , allocator ,
98+ Calendar .getInstance (TimeZone .getTimeZone ("UTC" ), Locale .ROOT ), false );
9399 }
94100
95101 /**
@@ -110,13 +116,42 @@ public static VectorSchemaRoot sqlToArrow(
110116 String query ,
111117 BaseAllocator allocator ,
112118 Calendar calendar ) throws SQLException , IOException {
119+
120+ Preconditions .checkNotNull (connection , "JDBC connection object can not be null" );
121+ Preconditions .checkArgument (query != null && query .length () > 0 , "SQL query can not be null or empty" );
122+ Preconditions .checkNotNull (allocator , "Memory allocator object can not be null" );
123+ Preconditions .checkNotNull (calendar , "Calendar object can not be null" );
124+
125+ return sqlToArrow (connection , query , allocator , calendar , false );
126+ }
127+
128+ /**
129+ * For the given SQL query, execute and fetch the data from Relational DB and convert it to Arrow objects.
130+ *
131+ * @param connection Database connection to be used. This method will not close the passed connection object.
132+ * Since the caller has passed the connection object it's the responsibility of the caller
133+ * to close or return the connection to the pool.
134+ * @param query The DB Query to fetch the data.
135+ * @param allocator Memory allocator
136+ * @param calendar Calendar object to use to handle Date, Time and Timestamp datasets.
137+ * @param includeMetadata Whether to include column information in the schema field metadata.
138+ * @return Arrow Data Objects {@link VectorSchemaRoot}
139+ * @throws SQLException Propagate any SQL Exceptions to the caller after closing any resources opened such as
140+ * ResultSet and Statement objects.
141+ */
142+ public static VectorSchemaRoot sqlToArrow (
143+ Connection connection ,
144+ String query ,
145+ BaseAllocator allocator ,
146+ Calendar calendar ,
147+ boolean includeMetadata ) throws SQLException , IOException {
113148 Preconditions .checkNotNull (connection , "JDBC connection object can not be null" );
114149 Preconditions .checkArgument (query != null && query .length () > 0 , "SQL query can not be null or empty" );
115150 Preconditions .checkNotNull (allocator , "Memory allocator object can not be null" );
116151 Preconditions .checkNotNull (calendar , "Calendar object can not be null" );
117152
118153 try (Statement stmt = connection .createStatement ()) {
119- return sqlToArrow (stmt .executeQuery (query ), allocator , calendar );
154+ return sqlToArrow (stmt .executeQuery (query ), allocator , calendar , includeMetadata );
120155 }
121156 }
122157
@@ -163,7 +198,7 @@ public static VectorSchemaRoot sqlToArrow(ResultSet resultSet, Calendar calendar
163198 Preconditions .checkNotNull (calendar , "Calendar object can not be null" );
164199
165200 RootAllocator rootAllocator = new RootAllocator (Integer .MAX_VALUE );
166- VectorSchemaRoot root = sqlToArrow (resultSet , rootAllocator , calendar );
201+ VectorSchemaRoot root = sqlToArrow (resultSet , rootAllocator , calendar , false );
167202
168203 return root ;
169204 }
@@ -177,14 +212,40 @@ public static VectorSchemaRoot sqlToArrow(ResultSet resultSet, Calendar calendar
177212 * @return Arrow Data Objects {@link VectorSchemaRoot}
178213 * @throws SQLException on error
179214 */
180- public static VectorSchemaRoot sqlToArrow (ResultSet resultSet , BaseAllocator allocator , Calendar calendar )
215+ public static VectorSchemaRoot sqlToArrow (
216+ ResultSet resultSet ,
217+ BaseAllocator allocator ,
218+ Calendar calendar )
219+ throws SQLException , IOException {
220+ Preconditions .checkNotNull (resultSet , "JDBC ResultSet object can not be null" );
221+ Preconditions .checkNotNull (allocator , "Memory Allocator object can not be null" );
222+ Preconditions .checkNotNull (calendar , "Calendar object can not be null" );
223+
224+ return sqlToArrow (resultSet , allocator , calendar , false );
225+ }
226+
227+ /**
228+ * For the given JDBC {@link ResultSet}, fetch the data from Relational DB and convert it to Arrow objects.
229+ *
230+ * @param resultSet ResultSet to use to fetch the data from underlying database
231+ * @param allocator Memory allocator to use.
232+ * @param calendar Calendar instance to use for Date, Time and Timestamp datasets.
233+ * @param metadata Whether to include column information in the schema field metadata.
234+ * @return Arrow Data Objects {@link VectorSchemaRoot}
235+ * @throws SQLException on error
236+ */
237+ public static VectorSchemaRoot sqlToArrow (
238+ ResultSet resultSet ,
239+ BaseAllocator allocator ,
240+ Calendar calendar ,
241+ boolean includeMetadata )
181242 throws SQLException , IOException {
182243 Preconditions .checkNotNull (resultSet , "JDBC ResultSet object can not be null" );
183244 Preconditions .checkNotNull (allocator , "Memory Allocator object can not be null" );
184245 Preconditions .checkNotNull (calendar , "Calendar object can not be null" );
185246
186247 VectorSchemaRoot root = VectorSchemaRoot .create (
187- JdbcToArrowUtils .jdbcToArrowSchema (resultSet .getMetaData (), calendar ), allocator );
248+ JdbcToArrowUtils .jdbcToArrowSchema (resultSet .getMetaData (), calendar , includeMetadata ), allocator );
188249 JdbcToArrowUtils .jdbcToArrowVectors (resultSet , root , calendar );
189250 return root ;
190251 }
0 commit comments