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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ArrowTypegetArrowTypeFromJdbcType(JdbcFieldInfo fieldInfo, Calendar calendar) Converts the provided JDBC type to its respectiveArrowTypecounterpart.static JdbcConsumergetConsumer(ArrowType arrowType, int columnIndex, boolean nullable, FieldVector vector, JdbcToArrowConfig config) Default function used for JdbcConsumerFactory.static CalendarReturns the instance of a {java.util.Calendar} with the UTC time zone and root locale.static SchemajdbcToArrowSchema(ParameterMetaData parameterMetaData, Calendar calendar) Create ArrowSchemaobject for the given JDBCResultSetMetaData.static SchemajdbcToArrowSchema(ResultSetMetaData rsmd, Calendar calendar) Create ArrowSchemaobject for the given JDBCResultSetMetaData.static SchemajdbcToArrowSchema(ResultSetMetaData rsmd, JdbcToArrowConfig config) Create ArrowSchemaobject for the given JDBCResultSetMetaData.static voidjdbcToArrowVectors(ResultSet rs, VectorSchemaRoot root, Calendar calendar) Iterate the given JDBCResultSetobject to fetch the data and transpose it to populate the given Arrow Vector objects.static voidjdbcToArrowVectors(ResultSet rs, VectorSchemaRoot root, JdbcToArrowConfig config) Iterate the given JDBCResultSetobject 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 thatUnsupportedOperationExceptionbecomesOpaqueType.
-
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 ArrowSchemaobject 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 ArrowSchemaobject 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 respectiveArrowTypecounterpart.- Parameters:
fieldInfo- theJdbcFieldInfowith information about the original JDBC type.calendar- theCalendarto 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 thatUnsupportedOperationExceptionbecomesOpaqueType.- 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 ArrowSchemaobject for the given JDBCResultSetMetaData.If
JdbcToArrowConfig.shouldIncludeMetadata()returnstrue, the following fields will be added to theFieldType.getMetadata():Constants.SQL_CATALOG_NAME_KEYrepresentingResultSetMetaData.getCatalogName(int)Constants.SQL_TABLE_NAME_KEYrepresentingResultSetMetaData.getTableName(int)Constants.SQL_COLUMN_NAME_KEYrepresentingResultSetMetaData.getColumnLabel(int)Constants.SQL_TYPE_KEYrepresentingResultSetMetaData.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- ifrsmdcontains anTypes.ARRAYbut theconfigdoes 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 JDBCResultSetobject 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- ArrowVectorSchemaRootobject to populatecalendar- The calendar to use when readingDate,Time, orTimestampdata types from theResultSet, ornullif not converting.- Throws:
SQLException- on errorIOException
-
jdbcToArrowVectors
public static void jdbcToArrowVectors(ResultSet rs, VectorSchemaRoot root, JdbcToArrowConfig config) throws SQLException, IOException Iterate the given JDBCResultSetobject 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- ArrowVectorSchemaRootobject 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
-