Add an assertColumnEquality method to allow for tests with less code #255
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi @holdenk 😄
I've been using the
assertColumnEquality
for most of my Spark testing needs and have found that it allows for tests that require less code and run faster. I'd like to add this function to spark-testing-base, so more Spark users have a better testing experience!Here's an example test with
assertDataFrameEquals
(usescreateDF
from spark-daria):Here's the same test with
assertColumnEquality
:assertColumnEquality
lets us reduce the test code from 25 lines to 15 lines.I think
assertColumnEquality
runs faster for the following reasons:collect()
method runs faster thanzipWithIndex()
expected.rdd.cache
andresult.rdd.cache
assertDataFrameEquals
will still be better for large DataFrame comparisons or multi-column comparisons.This PR just contains an initial implementation. If you like this idea, we can merge it in and then work on making the error message pretty. It's hard to spot the row differences in the following error message:
We will be able to add a pretty error message like this so it's easy for users to spot the rows that are causing their tests to fail:
Thanks!