cloud-fan commented on code in PR #54946:
URL: https://github.com/apache/spark/pull/54946#discussion_r3548159950
##########
sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLCLIDriver.scala:
##########
@@ -255,30 +262,57 @@ private[hive] object SparkSQLCLIDriver extends Logging {
def continuedPromptWithDBSpaces: String = continuedPrompt +
ReflectionUtils.invokeStatic(
classOf[CliDriver], "spacesForString", classOf[String] -> currentDB)
+ val sqlParser = SparkSQLEnv.sparkSession.sessionState.sqlParser
var currentPrompt = promptWithCurrentDB
var line = reader.readLine(currentPrompt + "> ")
while (line != null) {
// SPARK-55198: call line.trim to also skip comment line with leading
whitespaces,
// this keeps the behavior align with HIVE-8396
if (!line.trim.startsWith("--")) {
- if (prefix.nonEmpty) {
- prefix += '\n'
- }
-
- if (line.trim().endsWith(";") && !line.trim().endsWith("\\;")) {
- line = prefix + line
- ret = cli.processLine(line, true)
- prefix = ""
- currentPrompt = promptWithCurrentDB
+ val trimmed = line.trim
+ if (trimmed.endsWith(";") && !trimmed.endsWith("\\;")) {
+ // The line ends with `;` (and not the Hive-compat `\;` continuation
+ // escape) -- the user signaled end of statement. Ask the splitter
+ // to split the accumulated buffer into statements. The splitter
+ // correctly handles `;` inside quoted strings, comments, and SQL
+ // scripting compound blocks (`BEGIN ... END`).
+ val candidate = if (buffer.isEmpty) line else buffer + "\n" + line
Review Comment:
The headline user-facing change is that interactive `spark-sql> BEGIN ...
END;` now buffers across the continuation prompt instead of firing early, but
no `CliSuite` test drives this path. Every scripting/comment test uses
`-e`/`-f` batch mode or single-line input, and `SqlStatementSplitterSuite`
exercises the splitter in isolation — so this loop (`:268-308`), which consumes
`splitResult.partialStatement` and decides continue-prompt vs. flush, is only
covered end-to-end for the `\;` case. The `WHILE ... END WHILE` session in the
PR description is exactly what has no regression test.
Consider a `runCliWithin` case feeding a multi-line block line-by-line (like
the existing SPARK-33100/37471 multi-line comment tests) and asserting the
block executes as one statement rather than firing at an internal `;`.
Non-blocking.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]