Add an assertColumnEquality method to allow for tests with less code#255
Closed
Add an assertColumnEquality method to allow for tests with less code#255
Conversation
|
@MrPowers, thanks! I am a bot who has found some folks who might be able to help with the review:@holdenk and @mahmoudhanafy |
Owner
|
I know this is from forever ago :p But the downside of the collect here is that then we can't assert equality on truly large dataframes. I think your very much onto something -- perhaps we could update the code to use collect() when running in local mode and the records therefor must clearly fit into memory. WDYT? |
Owner
|
So I think if we do the filter in advance then the collect it should be "fine" for column equality. |
holdenk
added a commit
that referenced
this pull request
Nov 16, 2025
Co-authored-by: MrPowers <matthewkevinpowers@gmail.com>
Owner
|
I've made an updated version in a new PR |
holdenk
added a commit
that referenced
this pull request
Nov 18, 2025
Co-authored-by: MrPowers <matthewkevinpowers@gmail.com>
holdenk
added a commit
that referenced
this pull request
Nov 20, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
assertColumnEqualityfor 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(usescreateDFfrom spark-daria):Here's the same test with
assertColumnEquality:assertColumnEqualitylets us reduce the test code from 25 lines to 15 lines.I think
assertColumnEqualityruns faster for the following reasons:collect()method runs faster thanzipWithIndex()expected.rdd.cacheandresult.rdd.cacheassertDataFrameEqualswill 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!