Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Beautify code
  • Loading branch information
wangyum committed Aug 3, 2016
commit 88e5d2eaf497d131b355ed545793ac9de43e2110
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,32 @@ private 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] = sqlType match {
// 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
case Types.NUMERIC if size == 0 => Option(DecimalType(DecimalType.MAX_PRECISION, 10))
// Handle FLOAT fields in a special way because JDBC ResultSetMetaData converts
// this to NUMERIC with -127 scale
// Not sure if there is a more robust way to identify the field as a float (or other
// numeric types that do not specify a scale.
case Types.NUMERIC if md.build().getLong("scale") == -127 =>
Option(DecimalType(DecimalType.MAX_PRECISION, 10))
case Types.NUMERIC if size == 1 => Option(BooleanType)
case Types.NUMERIC if size == 3 || size == 5 || size == 10 => Option(IntegerType)
case Types.NUMERIC if size == 19 && md.build().getLong("scale") == 0L => Option(LongType)
case Types.NUMERIC if size == 19 && md.build().getLong("scale") == 4L => Option(FloatType)
case _ => None
override def getCatalystType(
sqlType: Int, typeName: String, size: Int, md: MetadataBuilder): Option[DataType] = {
if (sqlType == Types.NUMERIC) {
val scale = md.build().getLong("scale")
size match {
// 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
case 0 => Option(DecimalType(DecimalType.MAX_PRECISION, 10))
// Handle FLOAT fields in a special way because JDBC ResultSetMetaData converts
// this to NUMERIC with -127 scale
// Not sure if there is a more robust way to identify the field as a float (or other
// numeric types that do not specify a scale.
case -127 => Option(DecimalType(DecimalType.MAX_PRECISION, 10))
case 1 => Option(BooleanType)
case 3 | 5 | 10 => Option(IntegerType)
case 19 if scale == 0L => Option(LongType)
case 19 if scale == 4L => Option(FloatType)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not change the read path. The bug we need to resolve is just the write path.

case _ => None
}
} else {
None
}
}

override def getJDBCType(dt: DataType): Option[JdbcType] = dt match {
Expand Down