Skip to content
Snippets Groups Projects
Commit 14ee0f57 authored by Travis Hegner's avatar Travis Hegner Committed by Yin Huai
Browse files

[SPARK-10648] Oracle dialect to handle nonspecific numeric types

This is the alternative/agreed upon solution to PR #8780.

Creating an OracleDialect to handle the nonspecific numeric types that can be defined in oracle.

Author: Travis Hegner <thegner@trilliumit.com>

Closes #9495 from travishegner/OracleDialect.
parent f80f7b69
No related branches found
No related tags found
No related merge requests found
......@@ -139,6 +139,7 @@ object JdbcDialects {
registerDialect(DB2Dialect)
registerDialect(MsSqlServerDialect)
registerDialect(DerbyDialect)
registerDialect(OracleDialect)
/**
......@@ -315,3 +316,27 @@ case object DerbyDialect extends JdbcDialect {
}
/**
* :: DeveloperApi ::
* Default Oracle dialect, mapping a nonspecific numeric type to a general decimal type.
*/
@DeveloperApi
case object OracleDialect extends JdbcDialect {
override def canHandle(url: String): Boolean = url.startsWith("jdbc:oracle")
override def getCatalystType(
sqlType: Int, typeName: String, size: Int, md: MetadataBuilder): Option[DataType] = {
// Handle NUMBER fields that have no precision/scale in special way
// because JDBC ResultSetMetaData converts this to 0 procision and -127 scale
// For more details, please see
// https://github.com/apache/spark/pull/8780#issuecomment-145598968
// and
// https://github.com/apache/spark/pull/8780#issuecomment-144541760
if (sqlType == Types.NUMERIC && size == 0) {
// This is sub-optimal as we have to pick a precision/scale in advance whereas the data
// in Oracle is allowed to have different precision/scale for each value.
Some(DecimalType(DecimalType.MAX_PRECISION, 10))
} else {
None
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment