-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-32669][SQL][TEST] Expression unit tests should explore all cases that can lead to null result #29493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Test build #127695 has finished for PR 29493 at commit
|
|
Thank you for pinging me, @cloud-fan . The two failures look relevant. Could you check them, please? |
|
|
||
| protected def checkEvaluation( | ||
| expression: => Expression, expected: Any, inputRow: InternalRow = EmptyRow): Unit = { | ||
| checkNullability(expression.dataType, expression.nullable, expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice update! I think this can make our tests more robust.
|
Nice, looks good. The test failures indeed look related. |
viirya
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea looks also good to me.
|
|
||
| private def checkNullability(dt: DataType, nullable: Boolean, expected: Any): Unit = { | ||
| expected match { | ||
| case null => assert(nullable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error message?
|
Sorry guys, I just realized that we already did it 2 years ago: #22375 I've changed this PR to add document about it, and ask people to explore all the null cases when writing tests. |
|
Test build #127724 has finished for PR 29493 at commit
|
|
retest this please |
|
Test build #127731 has finished for PR 29493 at commit
|
|
Thanks! Merged to master. |

What changes were proposed in this pull request?
Add document to
ExpressionEvalHelper, and ask people to explore all the cases that can lead to null results (including null in struct fields, array elements and map values).This PR also fixes
ComplexTypeSuite.GetArrayStructFieldsto explore all the null cases.Why are the changes needed?
It happened several times that we hit correctness bugs caused by wrong expression nullability. When writing unit tests, we usually don't test the nullability flag directly, and it's too late to add such tests for all expressions.
In #22375, we extended the expression test framework, which checks the nullability flag when the expected result/field/element is null.
This requires the test cases to explore all the cases that can lead to null results
Does this PR introduce any user-facing change?
no
How was this patch tested?
I reverted 5d296ed locally, and
ComplexTypeSuitecan catch the bug.