spark-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Herman van Hovell (JIRA)" <>
Subject [jira] [Commented] (SPARK-19017) NOT IN subquery with more than one column may return incorrect results
Date Wed, 04 Jan 2017 17:09:58 GMT


Herman van Hovell commented on SPARK-19017:

Ok, my bad. Lets try this again.

If I follow the NAAJ explanation in the section 6.1 of the Enhanced Subquery Optimizations
in Oracle paper ( Then I can rewrite
the following query {{select * from tbl_a where a not in (select b from tbl_b)}} into the
following (given that tbl_b has n elements):
WHERE  a <> b1 AND a <> b2 AND ... AND a <> bn

My basic thought here is that if we are comparing a complete tuple, for instance (2, 1), to
an incomplete tuple, for instance (2, null), then the result should be unknown (null). Following
this it would be obvious that a conjunctive predicate containing such an incomplete comparison
should also evaluate to unknown.

It now boils down to how we should compare the tuples; i.e. how is {{a <> b}} evaluated.
Note that I do not have an answer here. The following two things could apply:
* {{not(a.x1 = b.x1 and a.x2 = b.x2 and ... and a.xn = b.xn)}}  - I would lean towards this
* {{a.x1 <> b.x1 or a.x2 <> b.x2 or ... or a.xn <> b.xn)}} - Spark currently
implements this option if you compare structs.

> NOT IN subquery with more than one column may return incorrect results
> ----------------------------------------------------------------------
>                 Key: SPARK-19017
>                 URL:
>             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

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message