Skip to content

Commit 951bf24

Browse files
committed
Optimize code
1 parent bf7f621 commit 951bf24

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

sql/core/src/test/scala/org/apache/spark/sql/ExpressionsSchemaSuite.scala

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,19 @@ class ExpressionsSchemaSuite extends QueryTest with SharedSparkSession {
136136
}
137137
}
138138

139+
val header = Seq(
140+
s"<!-- Automatically generated by${getClass.getSimpleName} -->",
141+
"## Summary",
142+
s" - Number of queries: ${outputs.size}",
143+
s" - Number of expressions that missing example: ${missingExamples.size}",
144+
s" - Expressions missing examples: ${missingExamples.mkString(",")}",
145+
"## Schema of Built-in Functions",
146+
"| Class name | Function name or alias | Query example | Output schema |",
147+
"| ---------- | ---------------------- | ------------- | ------------- |"
148+
)
149+
139150
if (regenerateGoldenFiles) {
140-
val missingExampleStr = missingExamples.mkString(",")
141-
val goldenOutput = {
142-
s"<!-- Automatically generated by${getClass.getSimpleName} -->\n" +
143-
"## Summary\n" +
144-
s" - Number of queries: ${outputs.size}\n" +
145-
s" - Number of expressions that missing example: ${missingExamples.size}\n" +
146-
s" - Expressions missing examples: $missingExampleStr\n" +
147-
"## Schema of Built-in Functions\n" +
148-
"| Class name | Function name or alias | Query example | Output schema |\n" +
149-
"| ---------- | ---------------------- | ------------- | ------------- |\n" +
150-
outputBuffer.mkString("\n")
151-
}
151+
val goldenOutput = (header ++ outputBuffer).mkString("\n")
152152
val parent = resultFile.getParentFile
153153
if (!parent.exists()) {
154154
assert(parent.mkdirs(), "Could not create directory: " + parent)
@@ -157,19 +157,18 @@ class ExpressionsSchemaSuite extends QueryTest with SharedSparkSession {
157157
}
158158

159159
val outputSize = outputs.size
160+
val headerSize = header.size
160161
val expectedOutputs: Seq[QueryOutput] = {
161162
val expectedGoldenOutput = fileToString(resultFile)
162163
val lines = expectedGoldenOutput.split("\n")
163164
val expectedSize = lines.size
164165

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

171-
Seq.tabulate(outputs.size) { i =>
172-
val segments = lines(i + 8).split('|')
170+
Seq.tabulate(outputSize) { i =>
171+
val segments = lines(i + headerSize).split('|')
173172
QueryOutput(
174173
className = segments(1).trim,
175174
funcName = segments(2).trim,

0 commit comments

Comments
 (0)