Github user HyukjinKwon commented on a diff in the pull request:
https://github.com/apache/spark/pull/14947#discussion_r77581016
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/PartitioningUtils.scala
---
@@ -314,13 +315,30 @@ object PartitioningUtils {
raw: String,
defaultPartitionName: String,
typeInference: Boolean): Literal = {
+ val decimalTry = Try {
+ // `BigDecimal` conversion can fail when the `field` is not a form
of number.
+ val bigDecimal = new JBigDecimal(raw)
+ // It reduces the cases for decimals by disallowing values having
scale (eg. `1.1`).
+ if (bigDecimal.scale <= 0) {
+ // `DecimalType` conversion can fail when
+ // 1. The precision is bigger than 38.
+ // 2. scale is bigger than precision.
+ Literal(bigDecimal)
+ } else {
+ throw new RuntimeException
+ }
+ }
+
if (typeInference) {
// First tries integral types
Try(Literal.create(Integer.parseInt(raw), IntegerType))
.orElse(Try(Literal.create(JLong.parseLong(raw), LongType)))
+ .orElse(decimalTry)
// Then falls back to fractional types
.orElse(Try(Literal.create(JDouble.parseDouble(raw), DoubleType)))
- .orElse(Try(Literal(new JBigDecimal(raw))))
--- End diff --
IIUC, this was never being used before.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]