Skip to content

Commit

Permalink
Handle Oracle NUMBER correctly by letting JdbcArrowTypeConverter hand…
Browse files Browse the repository at this point in the history
…le 0 precision
  • Loading branch information
ejeffrli committed Feb 5, 2025
1 parent 3afa6ab commit 626bf45
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,29 +361,32 @@ private Schema getSchema(Connection jdbcConnection, TableName tableName, Schema

String columnName = resultSet.getString(COLUMN_NAME);
int jdbcColumnType = resultSet.getInt("DATA_TYPE");
int scale = resultSet.getInt("COLUMN_SIZE");
int precision = resultSet.getInt("COLUMN_SIZE");
int scale = resultSet.getInt("DECIMAL_DIGITS");

LOGGER.debug("columnName: {}", columnName);
LOGGER.debug("arrowColumnType: {}", arrowColumnType);
LOGGER.debug("jdbcColumnType: {}", jdbcColumnType);
LOGGER.debug("precision: {}", precision);
LOGGER.debug("scale: {}", scale);
LOGGER.debug("arrowColumnType: {}", arrowColumnType);

/**
* below data type conversion doing since a framework not giving appropriate
* data types for oracle data types.
*/

/** Handling TIMESTAMP, DATE, 0 Precision **/
/** Convert 0 scale Decimals to integer **/
if (arrowColumnType != null && arrowColumnType.getTypeID().equals(ArrowType.ArrowTypeID.Decimal)) {
String[] data = arrowColumnType.toString().split(",");
if (scale == 0 || Integer.parseInt(data[1].trim()) < 0) {
if (Integer.parseInt(data[1].trim()) <= 0) {
arrowColumnType = Types.MinorType.BIGINT.getType();
}
}

/**
* Converting an Oracle date data type into DATEDAY MinorType
*/
if (jdbcColumnType == java.sql.Types.TIMESTAMP && scale == 7) {
if (jdbcColumnType == java.sql.Types.TIMESTAMP && precision == 7) {
arrowColumnType = Types.MinorType.DATEDAY.getType();
}

Expand All @@ -403,6 +406,9 @@ private Schema getSchema(Connection jdbcConnection, TableName tableName, Schema
LOGGER.warn("getSchema: column[{}] type is null setting it to varchar | JDBC Type is [{}]", columnName, jdbcColumnType);
arrowColumnType = Types.MinorType.VARCHAR.getType();
}

LOGGER.debug("new arrowColumnType: {}", arrowColumnType);

schemaBuilder.addField(FieldBuilder.newBuilder(columnName, arrowColumnType).build());
}

Expand Down

0 comments on commit 626bf45

Please sign in to comment.