Skip to content

Commit 471fd40

Browse files
committed
[SPARK-10648] Oracle dialect to handle nonspecific numeric types #9495
Squashed commit of the following: commit a1370a7 Author: Travis Hegner <[email protected]> Date: Thu Nov 5 11:10:35 2015 -0500 style cleanup commit 839bcb5 Author: Travis Hegner <[email protected]> Date: Thu Nov 5 10:06:19 2015 -0500 more attribution commit 3157ed5 Author: Travis Hegner <[email protected]> Date: Thu Nov 5 10:04:09 2015 -0500 adding canHandle override, and registration of OracleDialect commit cc764d4 Author: Travis Hegner <[email protected]> Date: Thu Nov 5 09:53:43 2015 -0500 initial attempt Conflicts: sql/core/src/main/scala/org/apache/spark/sql/jdbc/JdbcDialects.scala
1 parent 00efa3c commit 471fd40

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

sql/core/src/main/scala/org/apache/spark/sql/jdbc/JdbcDialects.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ object JdbcDialects {
125125

126126
registerDialect(MySQLDialect)
127127
registerDialect(PostgresDialect)
128+
registerDialect(OracleDialect)
128129

129130
/**
130131
* Fetch the JdbcDialect class corresponding to a given database url.
@@ -222,3 +223,25 @@ case object MySQLDialect extends JdbcDialect {
222223
s"`$colName`"
223224
}
224225
}
226+
227+
/**
228+
* :: DeveloperApi ::
229+
* Default Oracle dialect, mapping a nonspecific
230+
* numeric type to a general decimal type.
231+
*/
232+
@DeveloperApi
233+
case object OracleDialect extends JdbcDialect {
234+
override def canHandle(url: String): Boolean = url.startsWith("jdbc:oracle")
235+
override def getCatalystType(
236+
sqlType: Int, typeName: String, size: Int, md: MetadataBuilder): Option[DataType] = {
237+
// Handle NUMBER fields that have no precision/scale in special way
238+
// because JDBC ResultSetMetaData converts this to 0 precision and -127 scale
239+
if (sqlType == Types.NUMERIC && size == 0) {
240+
// This is sub-optimal as we have to pick a precision/scale in advance whereas the data
241+
// in Oracle is allowed to have different precision/scale for each value.
242+
Some(DecimalType(38, 10))
243+
} else {
244+
None
245+
}
246+
}
247+
}

0 commit comments

Comments
 (0)