Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2030,7 +2030,10 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession {
def verifyCallCount(df: DataFrame, expectedResult: Row, expectedCount: Int): Unit = {
countAcc.setValue(0)
QueryTest.checkAnswer(
df, Seq(expectedResult), checkToRDD = false /* avoid duplicate exec */)
df, Seq(expectedResult), checkToRDD = false /* avoid duplicate exec */) match {
Copy link
Contributor

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 QueryTest object to let it call fail instead? The pattern is simply duplicated across changes, and even QueryTest.checkAnswer (protected method), which warrants enough reason to have another method.

e.g. checkAnswer(df: DataFrame, expectedAnswer: java.util.List[Row]): String

Copy link
Contributor

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.

case Some(errorMessage) => fail(errorMessage)
case None =>
}
assert(countAcc.value == expectedCount)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ class SessionStateSuite extends SparkFunSuite {
|FROM df x JOIN df y ON x.str = y.str
|GROUP BY x.str
""".stripMargin),
Row("1", 1) :: Row("2", 1) :: Row("3", 1) :: Nil)
Row("1", 1) :: Row("2", 1) :: Row("3", 1) :: Nil) match {
case Some(errorMessage) => fail(errorMessage)
case None =>
}
}

val spark = activeSession
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

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

Can we ..

  1. make QueryTest.checkAnswer private so that it can only be called in its companion class QueryTest
  2. and avoid to call checkAnswer in the QueryTest object in the tests

?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, basically similar comment with @HeartSaVioR's.

Copy link
Contributor

Choose a reason for hiding this comment

The 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 QueryTest.checkAnswer from outside of QueryTest. (I guess it might have been misused like this PR fixes...)

case Some(errorMessage) => fail(errorMessage)
case None =>
}
}
}
assert(caught.getMessage.contains("exceeds the max length allowed"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
}
Copy link
Member

@dongjoon-hyun dongjoon-hyun Dec 5, 2019

Choose a reason for hiding this comment

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

This seems to fail like the following at schema comparison.

!== Correct Answer - 9 ==   == Spark Answer - 9 ==
!struct<>                   struct<value:int,count(1):bigint>
 [1,1]                      [1,1]
 [2,1]                      [2,1]
 [3,2]                      [3,2]
 [4,2]                      [4,2]
 [5,2]                      [5,2]
 [6,2]                      [6,2]
 [7,1]                      [7,1]
 [8,1]                      [8,1]
 [9,1]                      [9,1]

Copy link
Member Author

Choose a reason for hiding this comment

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

This is because expectedAnswer's data type do not match. 61eacc9 fix this issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

Before this PR. it will not fail.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

} finally {
if (streamingQuery ne null) {
streamingQuery.stop()
Expand Down