Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-21204

RuntimeException with Set and Case Class in Spark 2.1.1

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.1
    • Fix Version/s: 2.3.0
    • Component/s: Optimizer, SQL
    • Labels:
      None

      Description

      When attempting to produce a Dataset containing a Set, such as with:

      dbData
        .groupBy("userId")
        .agg(functions.collect_set("friendId") as "friendIds")
        .as[(Int, Set[Int])]
      

      An exception occurs. This can be avoided by casting to a Seq, but sometimes it makes more logical sense have a Set, especially when using the collect_set aggregation operation. Additionally, I am unable to write this Dataset to a Cassandra table containing a Set column without first converting to an RDD.

      [error] Exception in thread "main" java.lang.UnsupportedOperationException: No Encoder found for Set[Int]
      [error] - field (class: "scala.collection.immutable.Set", name: "_2")
      [error] - root class: "scala.Tuple2"
      [error] 	at org.apache.spark.sql.catalyst.ScalaReflection$.org$apache$spark$sql$catalyst$ScalaReflection$$serializerFor(ScalaReflection.scala:602)
      [error] 	at org.apache.spark.sql.catalyst.ScalaReflection$$anonfun$9.apply(ScalaReflection.scala:596)
      [error] 	at org.apache.spark.sql.catalyst.ScalaReflection$$anonfun$9.apply(ScalaReflection.scala:587)
      [error] 	at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:252)
      [error] 	at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:252)
      [error] 	at scala.collection.immutable.List.foreach(List.scala:381)
      [error] 	at scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:252)
      [error] 	at scala.collection.immutable.List.flatMap(List.scala:344)
      [error] 	at org.apache.spark.sql.catalyst.ScalaReflection$.org$apache$spark$sql$catalyst$ScalaReflection$$serializerFor(ScalaReflection.scala:587)
      [error] 	at org.apache.spark.sql.catalyst.ScalaReflection$.serializerFor(ScalaReflection.scala:425)
      [error] 	at org.apache.spark.sql.catalyst.encoders.ExpressionEncoder$.apply(ExpressionEncoder.scala:71)
      [error] 	at org.apache.spark.sql.Encoders$.product(Encoders.scala:275)
      [error] 	at org.apache.spark.sql.SQLImplicits.newProductEncoder(SQLImplicits.scala:49)
      

      I think the resolution to this might be similar to adding the Map type - https://github.com/apache/spark/pull/16986

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                viirya Liang-Chi Hsieh
                Reporter:
                leoromanovsky Leo Romanovsky
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: