Skip to content

Conversation

@cloud-fan
Copy link
Contributor

@cloud-fan cloud-fan commented Aug 20, 2020

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.GetArrayStructFields to 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 ComplexTypeSuite can catch the bug.

@cloud-fan
Copy link
Contributor Author

cc @maropu @viirya @dongjoon-hyun @HyukjinKwon

@SparkQA
Copy link

SparkQA commented Aug 20, 2020

Test build #127695 has finished for PR 29493 at commit 440a599.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@dongjoon-hyun
Copy link
Member

Thank you for pinging me, @cloud-fan . The two failures look relevant. Could you check them, please?
Screen Shot 2020-08-20 at 1 15 36 PM


protected def checkEvaluation(
expression: => Expression, expected: Any, inputRow: InternalRow = EmptyRow): Unit = {
checkNullability(expression.dataType, expression.nullable, expected)
Copy link
Member

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.

@HyukjinKwon HyukjinKwon changed the title [SPARK-32669][SQL][TEST] test expression nullability when checking result [SPARK-32669][SQL][TEST] Test expression nullability when checking result Aug 21, 2020
@HyukjinKwon
Copy link
Member

Nice, looks good. The test failures indeed look related.

Copy link
Member

@viirya viirya left a 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add error message?

@cloud-fan cloud-fan changed the title [SPARK-32669][SQL][TEST] Test expression nullability when checking result [SPARK-32669][SQL][TEST] expression unit tests should explore all cases that can lead to null result Aug 21, 2020
@cloud-fan
Copy link
Contributor Author

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.

@SparkQA
Copy link

SparkQA commented Aug 21, 2020

Test build #127724 has finished for PR 29493 at commit 9686eeb.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor Author

retest this please

@HyukjinKwon HyukjinKwon changed the title [SPARK-32669][SQL][TEST] expression unit tests should explore all cases that can lead to null result [SPARK-32669][SQL][TEST] Expression unit tests should explore all cases that can lead to null result Aug 21, 2020
@SparkQA
Copy link

SparkQA commented Aug 21, 2020

Test build #127731 has finished for PR 29493 at commit 9686eeb.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@maropu maropu closed this in 3dca81e Aug 21, 2020
@maropu
Copy link
Member

maropu commented Aug 21, 2020

Thanks! Merged to master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants