spark-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sean Owen (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (SPARK-22472) Datasets generate random values for null primitive types
Date Wed, 08 Nov 2017 18:20:00 GMT

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

Sean Owen commented on SPARK-22472:
-----------------------------------

This doesn't look right ...

https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala#L596

{code}
  def defaultValue(jt: String): String = jt match {
    case JAVA_BOOLEAN => "false"
    case JAVA_BYTE => "(byte)-1"
    case JAVA_SHORT => "(short)-1"
    case JAVA_INT => "-1"
    case JAVA_LONG => "-1L"
    case JAVA_FLOAT => "-1.0f"
    case JAVA_DOUBLE => "-1.0"
    case _ => "null"
  }
{code}

The default for any uninitialized primitive type is 0 in the JVM.

[~cloud_fan] I think you were the last to touch this, but didn't write it. Is this really
-1 on purpose for another reason?

> Datasets generate random values for null primitive types
> --------------------------------------------------------
>
>                 Key: SPARK-22472
>                 URL: https://issues.apache.org/jira/browse/SPARK-22472
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 2.1.1, 2.2.0
>            Reporter: Vladislav Kuzemchik
>
> Not sure if it ever were reported.
> {code}
> scala> val s = sc.parallelize(Seq[Option[Long]](None,Some(1L),Some(5))).toDF("v")
> s: org.apache.spark.sql.DataFrame = [v: bigint]
> scala> s.show(false)
> +----+
> |v   |
> +----+
> |null|
> |1   |
> |5   |
> +----+
> scala> s.as[Long].map(v => v*2).show(false)
> +-----+
> |value|
> +-----+
> |-2   |
> |2    |
> |10   |
> +-----+
> scala> s.select($"v"*2).show(false)
> +-------+
> |(v * 2)|
> +-------+
> |null   |
> |2      |
> |10     |
> +-------+
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

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


Mime
View raw message