GitHub user JoshRosen opened a pull request:

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

    [SPARK-17618] Fix invalid comparisons between UnsafeRow and other row 
formats

    ## What changes were proposed in this pull request?
    
    This patch addresses a correctness bug in Spark 1.6.x in where `coalesce()` 
declares that it can process `UnsafeRows` but mis-declares that it always 
outputs safe rows. If UnsafeRow and other Row types are compared for equality 
then we will get spurious `false` comparisons, leading to wrong answers in 
operators which perform whole-row comparison (such as `distinct()` or 
`except()`). An example of a query impacted by this bug is given in the [JIRA 
ticket](https://issues.apache.org/jira/browse/SPARK-17618).
    
    The problem is that the validity of our row format conversion rules depends 
on operators which handle `unsafeRows` (signalled by overriding 
`canProcessUnsafeRows`) correctly reporting their output row format (which is 
done by overriding `outputsUnsafeRows`). In #9024, we overrode 
`canProcessUnsafeRows` but forgot to override `outputsUnsafeRows`, leading to 
the incorrect `equals()` comparison.
    
    Our interface design is flawed because correctness depends on operators 
correctly overriding multiple methods this problem could have been prevented by 
a design which coupled row format methods / metadata into a single method / 
class so that all three methods had to be overridden at the same time.
    
    This patch addresses this issue by adding missing `outputsUnsafeRows` 
overrides. In order to ensure that bugs in this logic are uncovered sooner, I 
have modified `UnsafeRow.equals()` to throw an `IllegalArgumentException` if it 
is called with an object that is not an `UnsafeRow`.
    
    ## How was this patch tested?
    
    I believe that the stronger misuse-checking in `UnsafeRow.equals()` is 
sufficient to detect and prevent this class of bug.

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

    $ git pull https://github.com/JoshRosen/spark SPARK-17618

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

    https://github.com/apache/spark/pull/15185.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 #15185
    
----
commit d09a81e79cf4febc35b42fb0ff57d772f70b8e49
Author: Josh Rosen <joshro...@databricks.com>
Date:   2016-09-21T19:56:25Z

    Override outputsUnsafeRows when overriding canProcessUnsafeRows

commit 9d4cf441a8d7d0af8eba3d473e996e0b39fd5560
Author: Josh Rosen <joshro...@databricks.com>
Date:   2016-09-21T19:57:40Z

    Throw IllegalArgumentException when performing illegal UnsafeRow equals 
comparison.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to