Skip to content

Commit

Permalink
[SPARK-10648][SQL][BRANCH-1.4] Oracle dialect to handle nonspecific n…
Browse files Browse the repository at this point in the history
…umeric types

This backports apache#9495 to branch-1.4 (in case anyone needs this).

Author: Yin Huai <[email protected]>

Closes apache#9498 from yhuai/OracleDialect-1.4.
  • Loading branch information
yhuai committed Nov 5, 2015
1 parent 00efa3c commit 6c5e9a3
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ object JdbcDialects {

registerDialect(MySQLDialect)
registerDialect(PostgresDialect)
registerDialect(OracleDialect)

/**
* Fetch the JdbcDialect class corresponding to a given database url.
Expand Down Expand Up @@ -222,3 +223,28 @@ case object MySQLDialect extends JdbcDialect {
s"`$colName`"
}
}

/**
* :: 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 precision 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(38, 10))
} else {
None
}
}
}

0 comments on commit 6c5e9a3

Please sign in to comment.