Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ object DecimalType extends AbstractDataType {
}

private[sql] def bounded(precision: Int, scale: Int): DecimalType = {
DecimalType(min(precision, MAX_PRECISION), min(scale, MAX_SCALE))
if (precision <= 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's risky to change this one, I'd only change the JDBCRDD

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will take your word for the risk involved, I am very new to this project.

From a layman's perspective, it seems that doing some basic checks when instantiating the type would make the type more robust. If I understand correctly a precision <= 0 is not allowed, so this patch returns a /default/ decimal. Similarly, a scale > precision is not allowed, so it returns a decimal with the scale truncated to the size of the precision. My thoughts are that this will catch unexpected inputs and still behave in an expected way. Users instantiating these decimals in the ways that are intended will still get the same type back.

DecimalType.SYSTEM_DEFAULT
else if (scale > precision)
DecimalType(min(precision, MAX_PRECISION), min(precision, MAX_SCALE))
else
DecimalType(min(precision, MAX_PRECISION), min(scale, MAX_SCALE))
}

override private[sql] def defaultConcreteType: DataType = SYSTEM_DEFAULT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ private[sql] object JDBCRDD extends Logging {
case java.sql.Types.CLOB => StringType
case java.sql.Types.DATALINK => null
case java.sql.Types.DATE => DateType
case java.sql.Types.DECIMAL
if precision != 0 || scale != 0 => DecimalType.bounded(precision, scale)
case java.sql.Types.DECIMAL => DecimalType.SYSTEM_DEFAULT
case java.sql.Types.DECIMAL => DecimalType.bounded(precision, scale)
case java.sql.Types.DISTINCT => null
Copy link
Contributor

Choose a reason for hiding this comment

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

How about change this to scale >= 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That wouldn't work as demonstrated earlier in the thread. A negative scale is legal to reduce precision to the 10s place, 100s place, etc...

case java.sql.Types.DOUBLE => DoubleType
case java.sql.Types.FLOAT => FloatType
Expand All @@ -80,9 +78,7 @@ private[sql] object JDBCRDD extends Logging {
case java.sql.Types.NCHAR => StringType
case java.sql.Types.NCLOB => StringType
case java.sql.Types.NULL => null
case java.sql.Types.NUMERIC
if precision != 0 || scale != 0 => DecimalType.bounded(precision, scale)
case java.sql.Types.NUMERIC => DecimalType.SYSTEM_DEFAULT
case java.sql.Types.NUMERIC => DecimalType.bounded(precision, scale)
case java.sql.Types.NVARCHAR => StringType
case java.sql.Types.OTHER => null
case java.sql.Types.REAL => DoubleType
Expand Down