[ 
https://issues.apache.org/jira/browse/SPARK-7701?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14550098#comment-14550098
 ] 

bogdan baraila commented on SPARK-7701:
---------------------------------------

I've already made my ExamplePoint a case class and the error remains. Here is 
the code:

{code}

@SQLUserDefinedType(udt = classOf[ExamplePointUDT])
case class ExamplePoint(val x: Double, val y: Double)

/**
 * User-defined type for [[ExamplePoint]].
 */
private class ExamplePointUDT extends UserDefinedType[ExamplePoint] {

  override def sqlType: DataType = ArrayType(DoubleType, false)

  override def pyUDT: String = "pyspark.sql.tests.ExamplePointUDT"

  override def serialize(obj: Any): Seq[Double] = {
    obj match {
      case p: ExamplePoint =>
        Seq(p.x, p.y)
    }
  }

  override def deserialize(datum: Any): ExamplePoint = {
    datum match {
      case values: Seq[_] =>
        val xy = values.asInstanceOf[Seq[Double]]
        assert(xy.length == 2)
        new ExamplePoint(xy(0), xy(1))
      case values: util.ArrayList[_] =>
        val xy = values.asInstanceOf[util.ArrayList[Double]].asScala
        new ExamplePoint(xy(0), xy(1))
    }
  }

  override def userClass: Class[ExamplePoint] = classOf[ExamplePoint]

}

{code}

> UDT not working
> ---------------
>
>                 Key: SPARK-7701
>                 URL: https://issues.apache.org/jira/browse/SPARK-7701
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 1.3.0, 1.3.1
>            Reporter: bogdan baraila
>
> Using a UserDefinedType fails with the next exception: 
> {code}
> ExamplePointUDT cannot be cast to org.apache.spark.sql.types.StructType
> java.lang.ClassCastException: 
> ExamplePointUDT cannot be cast to org.apache.spark.sql.types.StructType
>       at org.apache.spark.sql.SQLContext.createDataFrame(SQLContext.scala:316)
> {code}
> I'm using a basic example with the ExamplePointUdt from spark framework:
> {code}
>   test("udt serialisation") {
>     val points = Seq(new ExamplePoint(1.3, 1.6), new ExamplePoint(1.3, 1.8))
>     val df = SparkContextForStdout.context.parallelize(points).toDF()
>   }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org
For additional commands, e-mail: issues-h...@spark.apache.org

Reply via email to