Skip to content

[SPARK-31372][SQL][TEST][FOLLOW-UP] Improve ExpressionsSchemaSuite so that easy to track the diff. #28430

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

Closed
Closed
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 @@ -136,38 +136,39 @@ class ExpressionsSchemaSuite extends QueryTest with SharedSparkSession {
}
}

val header = Seq(
s"<!-- Automatically generated by${getClass.getSimpleName} -->",
"## Summary",
s" - Number of queries: ${outputs.size}",
s" - Number of expressions that missing example: ${missingExamples.size}",
s" - Expressions missing examples: ${missingExamples.mkString(",")}",
"## Schema of Built-in Functions",
"| Class name | Function name or alias | Query example | Output schema |",
"| ---------- | ---------------------- | ------------- | ------------- |"
)

if (regenerateGoldenFiles) {
val missingExampleStr = missingExamples.mkString(",")
val goldenOutput = {
s"<!-- Automatically generated by${getClass.getSimpleName} -->\n" +
"## Summary\n" +
s" - Number of queries: ${outputs.size}\n" +
s" - Number of expressions that missing example: ${missingExamples.size}\n" +
s" - Expressions missing examples: $missingExampleStr\n" +
"## Schema of Built-in Functions\n" +
"| Class name | Function name or alias | Query example | Output schema |\n" +
"| ---------- | ---------------------- | ------------- | ------------- |\n" +
outputBuffer.mkString("\n")
}
val goldenOutput = (header ++ outputBuffer).mkString("\n")
val parent = resultFile.getParentFile
if (!parent.exists()) {
assert(parent.mkdirs(), "Could not create directory: " + parent)
}
stringToFile(resultFile, goldenOutput)
}

val outputSize = outputs.size
val headerSize = header.size
val expectedOutputs: Seq[QueryOutput] = {
val goldenOutput = fileToString(resultFile)
val lines = goldenOutput.split("\n")
val expectedGoldenOutput = fileToString(resultFile)
val lines = expectedGoldenOutput.split("\n")
val expectedSize = lines.size

// The header of golden file has one line, plus four lines of the summary and three
// lines of the header of schema table.
assert(lines.size == outputs.size + 8,
s"Expected ${outputs.size + 8} blocks in result file but got ${lines.size}. " +
s"Try regenerate the result files.")
assert(expectedSize == outputSize + headerSize,
s"Expected $expectedSize blocks in result file but got " +
s"${outputSize + headerSize}. Try regenerate the result files.")

Seq.tabulate(outputs.size) { i =>
val segments = lines(i + 8).split('|')
Seq.tabulate(outputSize) { i =>
val segments = lines(i + headerSize).split('|')
QueryOutput(
className = segments(1).trim,
funcName = segments(2).trim,
Expand All @@ -177,7 +178,8 @@ class ExpressionsSchemaSuite extends QueryTest with SharedSparkSession {
}

// Compare results.
assert(expectedOutputs.size == outputs.size, s"Number of queries not equals")
assert(expectedOutputs.size == outputSize,
"The number of queries not equals the number of expected queries.")

outputs.zip(expectedOutputs).foreach { case (output, expected) =>
assert(expected.sql == output.sql, "SQL query did not match")
Expand Down