You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Sean Owen (JIRA)" <ji...@apache.org> on 2017/11/08 16:29:00 UTC

[jira] [Commented] (SPARK-22472) Datasets generate random values for null primitive types

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

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

Not sure it's random, but, somehow the value is being construed as -1 before being doubled. It's odd because {{s.as[Long].show(false)}} is fine. Try {{s.as[Long].map(_.toString).show(false)}} to see it more directly.

I admit I don't know much about the internals; is someone more informed able to weigh in on why null would become -1 here?

I think part of the issue is that you're converting null to a primitive long, but would expect 0 if anything, or an exception.

> 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