Github user marmbrus commented on a diff in the pull request: https://github.com/apache/spark/pull/1601#discussion_r15440847 --- 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 -- Spark SQL expects Scala Maps and Seqs internally.
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---