-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-30141][SQL][TESTS] Fix QueryTest.checkAnswer usage #26768
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -352,15 +352,24 @@ class BinaryFileFormatSuite extends QueryTest with SharedSparkSession { | |
| .select(CONTENT) | ||
| } | ||
| val expected = Seq(Row(content)) | ||
| QueryTest.checkAnswer(readContent(), expected) | ||
| QueryTest.checkAnswer(readContent(), expected) match { | ||
| case Some(errorMessage) => fail(errorMessage) | ||
| case None => | ||
| } | ||
| withSQLConf(SOURCES_BINARY_FILE_MAX_LENGTH.key -> content.length.toString) { | ||
| QueryTest.checkAnswer(readContent(), expected) | ||
| QueryTest.checkAnswer(readContent(), expected) match { | ||
| case Some(errorMessage) => fail(errorMessage) | ||
| case None => | ||
| } | ||
| } | ||
| // Disable read. If the implementation attempts to read, the exception would be different. | ||
| file.setReadable(false) | ||
| val caught = intercept[SparkException] { | ||
| withSQLConf(SOURCES_BINARY_FILE_MAX_LENGTH.key -> (content.length - 1).toString) { | ||
| QueryTest.checkAnswer(readContent(), expected) | ||
| QueryTest.checkAnswer(readContent(), expected) match { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we ..
?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, basically similar comment with @HeartSaVioR's.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think @HyukjinKwon's suggestion would be better for future modification in point of preventing the cause, if there's no actual usage of |
||
| case Some(errorMessage) => fail(errorMessage) | ||
| case None => | ||
| } | ||
| } | ||
| } | ||
| assert(caught.getMessage.contains("exceeds the max length allowed")) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -756,8 +756,11 @@ class StreamSuite extends StreamTest { | |
| streamingQuery.processAllAvailable() | ||
|
|
||
| QueryTest.checkAnswer(spark.table("counts").toDF(), | ||
| Row("1", 1) :: Row("2", 1) :: Row("3", 2) :: Row("4", 2) :: | ||
| Row("5", 2) :: Row("6", 2) :: Row("7", 1) :: Row("8", 1) :: Row("9", 1) :: Nil) | ||
| Row(1, 1L) :: Row(2, 1L) :: Row(3, 2L) :: Row(4, 2L) :: | ||
| Row(5, 2L) :: Row(6, 2L) :: Row(7, 1L) :: Row(8, 1L) :: Row(9, 1L) :: Nil) match { | ||
| case Some(errorMessage) => fail(errorMessage) | ||
| case None => | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to fail like the following at
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is because
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before this PR. it will not fail.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
| } finally { | ||
| if (streamingQuery ne null) { | ||
| streamingQuery.stop() | ||
|
|
||
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.
Why not adding a new method in
QueryTestobject to let it callfailinstead? The pattern is simply duplicated across changes, and evenQueryTest.checkAnswer(protected method), which warrants enough reason to have another method.e.g.
checkAnswer(df: DataFrame, expectedAnswer: java.util.List[Row]): StringThere 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.
Otherwise, maybe simply call checkAnswer (without QueryTest) - other places in this suite already called like this. Same applies for other suites as well.