Repository: spark
Updated Branches:
  refs/heads/branch-1.5 8e1bd6089 -> 0eb233507


[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.

(cherry picked from commit 6c5e9a3a056cc8ee660a2b22a0a5ff17d674b68d)
Signed-off-by: Yin Huai <yh...@databricks.com>


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/0eb23350
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/0eb23350
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/0eb23350

Branch: refs/heads/branch-1.5
Commit: 0eb2335071b216b13ef68ac92d6898490331c758
Parents: 8e1bd60
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:39 2015 -0800

----------------------------------------------------------------------
 .../apache/spark/sql/jdbc/JdbcDialects.scala    | 26 ++++++++++++++++++++
 1 file changed, 26 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/0eb23350/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

Reply via email to