You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Hyukjin Kwon (Jira)" <ji...@apache.org> on 2021/05/03 10:26:00 UTC

[jira] [Commented] (SPARK-35267) nullable field is set to false for integer type when using reflection to get StructType for a case class

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

Hyukjin Kwon commented on SPARK-35267:
--------------------------------------

It's because {{Int}} cannot be {{null}}, right?

{code}
scala> val a: Int = null.asInstanceOf[Int]
a: Int = 0
{code}

> nullable field is set to false for integer type when using reflection to get StructType for a case class
> --------------------------------------------------------------------------------------------------------
>
>                 Key: SPARK-35267
>                 URL: https://issues.apache.org/jira/browse/SPARK-35267
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 3.1.1
>         Environment: Scala version: 2.12.13
> sparkVersion = "3.1.1"
>            Reporter: Ganesh Chand
>            Priority: Major
>
> {code:java}
> // code placeholder
> object Util {
>   def toStructType[T](implicit typeTags: ScalaReflection.universe.TypeTag[T]): StructType =
>   ScalaReflection.schemaFor[T].dataType.asInstanceOf[StructType]
> }
> case class MyTable(val a: Int, val b: String)
> // The following test fails because schema returned using reflection sets nullable=false for integer column. The test passes if you set it to false
> it must "return a Spark Schema of type StructType for a case class" in {
>  val schemaFromCaseClass: StructType = Util.toStructType[MyTable]
>  val expectedSchema = new StructType().add(StructField("a", IntegerType, true)).add(StructField("b", StringType, true))
>  schemaFromCaseClass.size mustBe 2
>  schemaFromCaseClass mustBe expectedSchema
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

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