-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-30758][SQL][TESTS] Improve bracketed comments tests. #27481
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 4 commits
2f3a54c
4619ac7
c743bf3
7f21b1b
71e4c43
5a70f00
3f8497f
a512664
38005e8
fa8397e
900cc73
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 |
|---|---|---|
|
|
@@ -19,7 +19,9 @@ package org.apache.spark.sql | |
|
|
||
| import java.io.File | ||
| import java.util.{Locale, TimeZone} | ||
| import java.util.regex.Pattern | ||
|
|
||
| import scala.collection.mutable.{ArrayBuffer, HashMap} | ||
| import scala.util.control.NonFatal | ||
|
|
||
| import org.apache.spark.{SparkConf, SparkException} | ||
|
|
@@ -248,7 +250,10 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession { | |
| protected def runTest(testCase: TestCase): Unit = { | ||
| val input = fileToString(new File(testCase.inputFile)) | ||
|
|
||
| val (comments, code) = input.split("\n").partition(_.trim.startsWith("--")) | ||
| val (comments, code) = input.split("\n").partition { line => | ||
| val newLine = line.trim | ||
| newLine.startsWith("--") && !newLine.startsWith("--QUERY-DELIMITER") | ||
| } | ||
|
|
||
| // If `--IMPORT` found, load code from another test case file, then insert them | ||
| // into the head in this test. | ||
|
|
@@ -261,10 +266,37 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession { | |
| } | ||
| }.flatten | ||
|
|
||
| val tempQueries = if (code.exists(_.trim.startsWith("--QUERY-DELIMITER"))) { | ||
| // Although the loop is heavy, only used for comments test. | ||
| val querys = new ArrayBuffer[String] | ||
| val otherCodes = new ArrayBuffer[String] | ||
| var tempStr = "" | ||
| var start = false | ||
| for (c <- code) { | ||
|
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.
Contributor
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. OK. Thanks for your remind. |
||
| if (c.trim.startsWith("--QUERY-DELIMITER-START")) { | ||
| start = true | ||
| querys ++= otherCodes.toSeq.mkString("\n").split("(?<=[^\\\\]);") | ||
|
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. This (
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. +1
Contributor
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. OK |
||
| otherCodes.clear() | ||
| } else if (c.trim.startsWith("--QUERY-DELIMITER-END")) { | ||
| start = false | ||
| if (tempStr.endsWith(";")) { | ||
| tempStr = tempStr.substring(0, tempStr.length - 1) | ||
| } | ||
| querys += s"\n$tempStr" | ||
|
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. this can be
Contributor
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. OK. Good idea. |
||
| tempStr = "" | ||
| } else if (start) { | ||
| tempStr += s"\n$c" | ||
| } else { | ||
| otherCodes += c | ||
| } | ||
| } | ||
| querys.toSeq | ||
|
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. After the lookp ends, it's possible that
Contributor
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. OK. I forgot it. |
||
| } else { | ||
| (importedCode ++ code).mkString("\n").split("(?<=[^\\\\]);").toSeq | ||
| } | ||
|
|
||
| // List of SQL queries to run | ||
| // note: this is not a robust way to split queries using semicolon, but works for now. | ||
| val queries = (importedCode ++ code).mkString("\n").split("(?<=[^\\\\]);") | ||
|
cloud-fan marked this conversation as resolved.
|
||
| .map(_.trim).filter(_ != "").toSeq | ||
| val queries = tempQueries.map(_.trim).filter(_ != "").toSeq | ||
| // Fix misplacement when comment is at the end of the query. | ||
| .map(_.split("\n").filterNot(_.startsWith("--")).mkString("\n")).map(_.trim).filter(_ != "") | ||
|
|
||
|
|
||
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.
Oh, the output is pretty nice.