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

Niek Bartholomeus commented on SPARK-17809:
-------------------------------------------

Oh didn't notice 2.0.1 is already out (although it doesn't appear yet on maven).

Tested again on 2.0.1 and works correctly now.

Thanks for the help!

> scala.MatchError: BooleanType when casting a struct
> ---------------------------------------------------
>
>                 Key: SPARK-17809
>                 URL: https://issues.apache.org/jira/browse/SPARK-17809
>             Project: Spark
>          Issue Type: Bug
>    Affects Versions: 2.0.0
>            Reporter: Niek Bartholomeus
>             Fix For: 2.0.1
>
>
> I have a Dataframe with a struct and I need to rename some fields to lower 
> case before saving it to cassandra.
> It turns out that it's not possible to cast a boolean field of a struct to 
> another boolean field in the renamed struct:
> {quote}
> case class ClassWithBoolean(flag: Boolean)
> case class Parent(cwb: ClassWithBoolean)
> val structCwb: DataType = StructType(Seq(
>   StructField("flag", BooleanType, true)
> ))
> Seq(Parent(ClassWithBoolean(true)))
>     .toDF
>     .withColumn("cwb", $"cwb".cast(structCwb))
>     .collect 
> scala.MatchError: BooleanType (of class 
> org.apache.spark.sql.types.BooleanType$)
> {quote}
> A workaround is to temporarily cast the field to an Integer and back:
> {quote}
> val structCwbTmp: DataType = StructType(Seq(
>   StructField("flag", IntegerType, true)
> ))
> Seq(Parent(ClassWithBoolean(true)))
>     .toDF
>     .withColumn("cwb", $"cwb".cast(structCwbTmp))
>     .withColumn("cwb", $"cwb".cast(structCwb))
>     .collect 
> {quote}



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

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to