java.lang.Object
org.apache.arrow.adapter.jdbc.JdbcToArrowUtils
Class that does most of the work to convert JDBC ResultSet data into Arrow columnar format Vector
objects.
- Since:
- 0.10.0
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic ArrowType
getArrowTypeFromJdbcType
(JdbcFieldInfo fieldInfo, Calendar calendar) Converts the provided JDBC type to its respectiveArrowType
counterpart.static JdbcConsumer
getConsumer
(ArrowType arrowType, int columnIndex, boolean nullable, FieldVector vector, JdbcToArrowConfig config) Default function used for JdbcConsumerFactory.static Calendar
Returns the instance of a {java.util.Calendar} with the UTC time zone and root locale.static Schema
jdbcToArrowSchema
(ParameterMetaData parameterMetaData, Calendar calendar) Create ArrowSchema
object for the given JDBCResultSetMetaData
.static Schema
jdbcToArrowSchema
(ResultSetMetaData rsmd, Calendar calendar) Create ArrowSchema
object for the given JDBCResultSetMetaData
.static Schema
jdbcToArrowSchema
(ResultSetMetaData rsmd, JdbcToArrowConfig config) Create ArrowSchema
object for the given JDBCResultSetMetaData
.static void
jdbcToArrowVectors
(ResultSet rs, VectorSchemaRoot root, Calendar calendar) Iterate the given JDBCResultSet
object to fetch the data and transpose it to populate the given Arrow Vector objects.static void
jdbcToArrowVectors
(ResultSet rs, VectorSchemaRoot root, JdbcToArrowConfig config) Iterate the given JDBCResultSet
object to fetch the data and transpose it to populate the given Arrow Vector objects.static Function<JdbcFieldInfo,
ArrowType> reportUnsupportedTypesAsOpaque
(Function<JdbcFieldInfo, ArrowType> typeConverter, String vendorName) Wrap a JDBC to Arrow type converter such thatUnsupportedOperationException
becomesOpaqueType
.
-
Constructor Details
-
JdbcToArrowUtils
public JdbcToArrowUtils()
-
-
Method Details
-
getUtcCalendar
Returns the instance of a {java.util.Calendar} with the UTC time zone and root locale. -
jdbcToArrowSchema
public static Schema jdbcToArrowSchema(ResultSetMetaData rsmd, Calendar calendar) throws SQLException Create ArrowSchema
object for the given JDBCResultSetMetaData
.- Parameters:
rsmd
- The ResultSetMetaData containing the results, to read the JDBC metadata from.calendar
- The calendar to use the time zone field of, to construct Timestamp fields from.- Returns:
Schema
- Throws:
SQLException
- on error
-
jdbcToArrowSchema
public static Schema jdbcToArrowSchema(ParameterMetaData parameterMetaData, Calendar calendar) throws SQLException Create ArrowSchema
object for the given JDBCResultSetMetaData
.- Parameters:
parameterMetaData
- The ResultSetMetaData containing the results, to read the JDBC metadata from.calendar
- The calendar to use the time zone field of, to construct Timestamp fields from.- Returns:
Schema
- Throws:
SQLException
- on error
-
getArrowTypeFromJdbcType
Converts the provided JDBC type to its respectiveArrowType
counterpart.- Parameters:
fieldInfo
- theJdbcFieldInfo
with information about the original JDBC type.calendar
- theCalendar
to use for datetime data types.- Returns:
- a new
ArrowType
.
-
reportUnsupportedTypesAsOpaque
public static Function<JdbcFieldInfo,ArrowType> reportUnsupportedTypesAsOpaque(Function<JdbcFieldInfo, ArrowType> typeConverter, String vendorName) Wrap a JDBC to Arrow type converter such thatUnsupportedOperationException
becomesOpaqueType
.- Parameters:
typeConverter
- The type converter to wrap.vendorName
- The database name to report as the Opaque type's vendor name.
-
jdbcToArrowSchema
public static Schema jdbcToArrowSchema(ResultSetMetaData rsmd, JdbcToArrowConfig config) throws SQLException Create ArrowSchema
object for the given JDBCResultSetMetaData
.If
JdbcToArrowConfig.shouldIncludeMetadata()
returnstrue
, the following fields will be added to theFieldType.getMetadata()
:Constants.SQL_CATALOG_NAME_KEY
representingResultSetMetaData.getCatalogName(int)
Constants.SQL_TABLE_NAME_KEY
representingResultSetMetaData.getTableName(int)
Constants.SQL_COLUMN_NAME_KEY
representingResultSetMetaData.getColumnLabel(int)
Constants.SQL_TYPE_KEY
representingResultSetMetaData.getColumnTypeName(int)
If any columns are of type
Types.ARRAY
, the configuration object will be used to look up the array sub-type field. TheJdbcToArrowConfig.getArraySubTypeByColumnIndex(int)
method will be checked first, followed by theJdbcToArrowConfig.getArraySubTypeByColumnName(String)
method.- Parameters:
rsmd
- The ResultSetMetaData containing the results, to read the JDBC metadata from.config
- The configuration to use when constructing the schema.- Returns:
Schema
- Throws:
SQLException
- on errorIllegalArgumentException
- ifrsmd
contains anTypes.ARRAY
but theconfig
does not have a sub-type definition for it.
-
jdbcToArrowVectors
public static void jdbcToArrowVectors(ResultSet rs, VectorSchemaRoot root, Calendar calendar) throws SQLException, IOException Iterate the given JDBCResultSet
object to fetch the data and transpose it to populate the given Arrow Vector objects.- Parameters:
rs
- ResultSet to use to fetch the data from underlying databaseroot
- ArrowVectorSchemaRoot
object to populatecalendar
- The calendar to use when readingDate
,Time
, orTimestamp
data types from theResultSet
, ornull
if not converting.- Throws:
SQLException
- on errorIOException
-
jdbcToArrowVectors
public static void jdbcToArrowVectors(ResultSet rs, VectorSchemaRoot root, JdbcToArrowConfig config) throws SQLException, IOException Iterate the given JDBCResultSet
object to fetch the data and transpose it to populate the given Arrow Vector objects.- Parameters:
rs
- ResultSet to use to fetch the data from underlying databaseroot
- ArrowVectorSchemaRoot
object to populateconfig
- The configuration to use when reading the data.- Throws:
SQLException
- on errorJdbcConsumerException
- on error from VectorConsumerIOException
-
getConsumer
public static JdbcConsumer getConsumer(ArrowType arrowType, int columnIndex, boolean nullable, FieldVector vector, JdbcToArrowConfig config) Default function used for JdbcConsumerFactory. This function gets a JdbcConsumer for the given column based on the Arrow type and provided vector.- Parameters:
arrowType
- Arrow type for the column.columnIndex
- Column index to fetch from the ResultSetnullable
- Whether the value is nullable or notvector
- Vector to store the consumed valueconfig
- Associated JdbcToArrowConfig, used mainly for the Calendar.- Returns:
JdbcConsumer
-