spark-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nattavut Sutyanyong (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (SPARK-19017) NOT IN subquery with more than one column may return incorrect results
Date Wed, 04 Jan 2017 18:59:58 GMT

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

Nattavut Sutyanyong commented on SPARK-19017:
---------------------------------------------

I think we both agree that the result of the expression {{(2, 1) = (2, null)}} is unknown
(null). It is the negation of this expression that is the centre of this discussion.

If {{a = (2, 1)}} and {{b = (1, null)}}, what is the semantics of {{a <> b}}? You have
suggested two formulas

{{not(a.x1 = b.x1 and a.x2 = b.x2)}}

and

{{a.x1 <> b.x1 or a.x2 <> b.x2}}

Would you agree that these two formulas are equivalent? The second formula is just the result
of applying De Morgan's laws on the first formula, i.e., {{not (x and y) == (not x) or (not
y)}}.

How does Spark evaluate the formulas today? Here is my test:

{code}
scala> Seq(1).toDF("t1a").createOrReplaceTempView("t1")

scala> sql("select t1a from t1").show
+---+
|t1a|
+---+
|  1|
+---+

scala> sql("select t1a from t1 where not (2=1 and 1=null)").show
+---+
|t1a|
+---+
|  1|
+---+


scala> sql("select t1a from t1 where 2<>1 or 1<>null").show
+---+
|t1a|
+---+
|  1|
+---+
{code}


> NOT IN subquery with more than one column may return incorrect results
> ----------------------------------------------------------------------
>
>                 Key: SPARK-19017
>                 URL: https://issues.apache.org/jira/browse/SPARK-19017
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 2.0.0, 2.0.1, 2.0.2, 2.1.0
>            Reporter: Nattavut Sutyanyong
>
> When putting more than one column in the NOT IN, the query may not return correctly if
there is a null data. We can demonstrate the problem with the following data set and query:
> {code}
> Seq((2,1)).toDF("a1","b1").createOrReplaceTempView("t1")
> Seq[(java.lang.Integer,java.lang.Integer)]((1,null)).toDF("a2","b2").createOrReplaceTempView("t2")
> sql("select * from t1 where (a1,b1) not in (select a2,b2 from t2)").show
> +---+---+
> | a1| b1|
> +---+---+
> +---+---+
> {code}



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

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


Mime
View raw message