Repository: spark Updated Branches: refs/heads/branch-1.4 00efa3ced -> 6c5e9a3a0
[SPARK-10648][SQL][BRANCH-1.4] Oracle dialect to handle nonspecific numeric types This backports https://github.com/apache/spark/pull/9495 to branch-1.4 (in case anyone needs this). Author: Yin Huai <yh...@databricks.com> Closes #9498 from yhuai/OracleDialect-1.4. Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/6c5e9a3a Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/6c5e9a3a Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/6c5e9a3a Branch: refs/heads/branch-1.4 Commit: 6c5e9a3a056cc8ee660a2b22a0a5ff17d674b68d Parents: 00efa3c Author: Yin Huai <yh...@databricks.com> Authored: Thu Nov 5 11:44:34 2015 -0800 Committer: Yin Huai <yh...@databricks.com> Committed: Thu Nov 5 11:46:07 2015 -0800 ---------------------------------------------------------------------- .../apache/spark/sql/jdbc/JdbcDialects.scala | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/spark/blob/6c5e9a3a/sql/core/src/main/scala/org/apache/spark/sql/jdbc/JdbcDialects.scala ---------------------------------------------------------------------- diff --git a/sql/core/src/main/scala/org/apache/spark/sql/jdbc/JdbcDialects.scala b/sql/core/src/main/scala/org/apache/spark/sql/jdbc/JdbcDialects.scala index 8849fc2..8ae87d8 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/jdbc/JdbcDialects.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/jdbc/JdbcDialects.scala @@ -125,6 +125,7 @@ object JdbcDialects { registerDialect(MySQLDialect) registerDialect(PostgresDialect) + registerDialect(OracleDialect) /** * Fetch the JdbcDialect class corresponding to a given database url. @@ -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 + } + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org