Github user chenghao-intel commented on a diff in the pull request:
https://github.com/apache/spark/pull/3708#discussion_r21945992
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/json/JsonRDD.scala
---
@@ -263,6 +263,8 @@ private[sql] object JsonRDD extends Logging {
val elementType = typeOfArray(array)
buildKeyPathForInnerStructs(array, elementType) :+ (key,
elementType)
}
+ // we couldn't tell what the type is if the value is null or empty
string
+ case (key: String, value) if value == "" || value == null => (key,
NullType) :: Nil
--- End diff --
I've updated the unit test, which probably make more sense.
In some cases (as shown in the unit test), `""` is equivalent to `null` for
struct type, so we'd better not to say "it's MUST be `StringType` if we meet an
empty string".
In the meantime, the `NullType` is the `minimum` data type, and it can be
promoted to any other data type in `JsonRDD` (e.g. promote to StructType),
however, it's impossible to promote a `StringType` to `StructType`.
It's safe to make it as `NullType` here, as we can promote it as
`StringType` in the last promote rules, see
https://github.com/chenghao-intel/spark/blob/json/sql/core/src/main/scala/org/apache/spark/sql/SQLContext.scala#L231
---
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]