Github user mateiz commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1601#discussion_r15435519
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/SQLContext.scala ---
    @@ -357,16 +357,52 @@ class SQLContext(@transient val sparkContext: 
SparkContext)
           case c: java.util.Map[_, _] =>
             val (key, value) = c.head
             MapType(typeFor(key), typeFor(value))
    +      case c: java.util.Calendar => TimestampType
           case c if c.getClass.isArray =>
             val elem = c.asInstanceOf[Array[_]].head
             ArrayType(typeFor(elem))
           case c => throw new Exception(s"Object of type $c cannot be used")
         }
    -    val schema = rdd.first().map { case (fieldName, obj) =>
    +    val firstRow = rdd.first()
    +    val schema = firstRow.map { case (fieldName, obj) =>
           AttributeReference(fieldName, typeFor(obj), true)()
         }.toSeq
     
    -    val rowRdd = rdd.mapPartitions { iter =>
    +    def needTransform(obj: Any): Boolean = obj match {
    +      case c: java.util.List[_] => c.exists(needTransform)
    +      case c: java.util.Set[_] => c.exists(needTransform)
    +      case c: java.util.Map[_, _] => c.exists {
    +        case (key, value) => needTransform(key) || needTransform(value)
    +      }
    +      case c if c.getClass.isArray =>
    +        c.asInstanceOf[Array[_]].exists(needTransform)
    +      case c: java.util.Calendar => true
    +      case c => false
    +    }
    +
    +    def transform(obj: Any): Any = obj match {
    +      case c: java.util.List[_] => c.map(transform)
    +      case c: java.util.Set[_] => c.map(transform)
    +      case c: java.util.Map[_, _] => c.map {
    +        case (key, value) => (transform(key), transform(value))
    +      }
    --- End diff --
    
    FYI, this will return a Scala Map, not a Java one. Same with the maps on 
List, Set, etc. Will the rest of the code know how to deal with this?


---
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.
---

Reply via email to