GitHub user maropu opened a pull request:

    https://github.com/apache/spark/pull/21148

    [SPARK-24079][SQL] Update the nullability of Join output based on inferred 
predicates

    ## What changes were proposed in this pull request?
    This pr added code to update the nullability of `Join.output` based on 
inferred predicates in `InferFiltersFromConstraints`. In the master, a logical 
`Join` node does not respect the nullability that the optimizer rule 
`InferFiltersFromConstraints` might change when inferred predicates have 
`IsNotNull`,
    e.g.,
    
    ```
    scala> val df1 = Seq((Some(1), Some(2))).toDF("k", "v0")
    scala> val df2 = Seq((Some(1), Some(3))).toDF("k", "v1")
    scala> val joinedDf = df1.join(df2, df1("k") === df2("k"), "inner")
    scala> joinedDf.explain
    == Physical Plan ==
    *(2) BroadcastHashJoin [k#83], [k#92], Inner, BuildRight
    :- *(2) Project [_1#80 AS k#83, _2#81 AS v0#84]
    :  +- *(2) Filter isnotnull(_1#80)
    :     +- LocalTableScan [_1#80, _2#81]
    +- BroadcastExchange HashedRelationBroadcastMode(List(cast(input[0, int, 
true] as bigint)))
       +- *(1) Project [_1#89 AS k#92, _2#90 AS v1#93]
          +- *(1) Filter isnotnull(_1#89)
             +- LocalTableScan [_1#89, _2#90]
    
    scala> joinedDf.queryExecution.optimizedPlan.output.map(_.nullable)
    res15: Seq[Boolean] = List(true, true, true, true)
    ```
    
    But, these `nullable` values should be:
    
    ```
    scala> joinedDf.queryExecution.optimizedPlan.output.map(_.nullable)
    res15: Seq[Boolean] = List(false, true, false, true)
    ```
    
    This ticket comes from the previous discussion: 
https://github.com/apache/spark/pull/18576#pullrequestreview-107585997
    
    ## How was this patch tested?
    Added tests in `UpdateNullabilityInAttributeReferencesSuite`.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/maropu/spark UpdateJoinNullability

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/21148.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #21148
    
----
commit 240ae7a976f03ce58bcdeed34f8022ebfea23a4c
Author: Takeshi Yamamuro <yamamuro@...>
Date:   2018-04-02T08:07:52Z

    Fix

----


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to