-
Notifications
You must be signed in to change notification settings - Fork 28.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-20143][SQL] DataType.fromJson should throw an exception with better message #17468
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,7 +115,10 @@ object DataType { | |
name match { | ||
case "decimal" => DecimalType.USER_DEFAULT | ||
case FIXED_DECIMAL(precision, scale) => DecimalType(precision.toInt, scale.toInt) | ||
case other => nonDecimalNameToType(other) | ||
case other => nonDecimalNameToType.getOrElse(other, { | ||
throw new IllegalArgumentException( | ||
s"Failed to convert the JSON string '$name' to a data type.") | ||
}) | ||
} | ||
} | ||
|
||
|
@@ -164,6 +167,10 @@ object DataType { | |
("sqlType", v: JValue), | ||
("type", JString("udt"))) => | ||
new PythonUserDefinedType(parseDataType(v), pyClass, serialized) | ||
|
||
case other: JValue => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
throw new IllegalArgumentException( | ||
s"Failed to convert the JSON string '${compact(render(other))}' to a data type.") | ||
} | ||
|
||
private def parseStructField(json: JValue): StructField = json match { | ||
|
@@ -179,6 +186,9 @@ object DataType { | |
("nullable", JBool(nullable)), | ||
("type", dataType: JValue)) => | ||
StructField(name, parseDataType(dataType), nullable) | ||
case other: JValue => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or |
||
throw new IllegalArgumentException( | ||
s"Failed to convert the JSON string '${compact(render(other))}' to a field.") | ||
} | ||
|
||
protected[types] def buildFormattedString( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{
and}
are not needed