[
https://issues.apache.org/jira/browse/SPARK-19017?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15785436#comment-15785436
]
Herman van Hovell commented on SPARK-19017:
-------------------------------------------
Ok, that is fair. Let me correct my mistake.
{{NOT IN}} can be rewritten into, in to a sequence of NOT equals statements.
Each statement contains one tuple of the subquery relation. So we would get
something like:
{noformat}
WHERE (NOT (a1 = a2(1) AND b1 = b2(1))) AND (NOT (a1 = a2(2) AND b1 = b2(2)))
AND ... AND (NOT (a1 = a2(n) AND b1 = b2(n)))
{noformat}
Which can be rewritten into:
{noformat}
WHERE (a1 <> a2(1) OR b1 <> b2(1)) AND (a1 <> a2(2) OR b1 <> b2(2)) AND ...
AND (a1 <> a2(n) OR b1 <> b2(n))
{noformat}
This would evaluate to null if one of the tuples in the subquery relation
contains a null.
> 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: [email protected]
For additional commands, e-mail: [email protected]