pan3793 commented on code in PR #53977:
URL: https://github.com/apache/spark/pull/53977#discussion_r2727350295


##########
sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLCLIDriver.scala:
##########
@@ -529,6 +531,22 @@ private[hive] class SparkSQLCLIDriver extends CliDriver 
with Logging {
     }
   }
 
+  // Adapted processLine from Hive 2.3's CliDriver.processReader.
+  // SPARK-55198: call line.trim to also skip comment line with leading 
whitespaces,
+  // this keeps the spark-sql's behavior align with beeline.
+  override def processReader(r: BufferedReader): Int = {
+    val qsb = new StringBuilder
+    var line = r.readLine
+    while (line != null) {
+      // Skipping through comments
+      if (!line.trim.startsWith("--")) {

Review Comment:
   ```
   $ cat > test.sql <<EOF
   SET x=
    -- comment
   1;
   SET x;
   EOF
   ```
   
   in Hive 2.3 codebase, `trim` is not called, so `hive` commands have a 
different behavior on
   ```
   $ hive -f test.sql
   x=-- comment
   1
   
   $ hive < test.sql
   hive> SET x=
       >  -- comment
       > 1;
   hive> SET x;
   x=1
   ```
   but `beeline` has consistent behavior
   ```
   $ beeline -u 'jdbc:hive2://localhost:10000/default' -f test.sql
   0: jdbc:hive2://localhost:10000/default> SET x;
   +------+
   | set  |
   +------+
   | x=1  |
   +------+
   1 row selected (0.021 seconds)
   
   $ beeline -u 'jdbc:hive2://localhost:10000/default' < test.sql
   0: jdbc:hive2://localhost:10000/default> SET x=
   . . . . . . . . . . . . . . . . . . . .>  -- comment
   . . . . . . . . . . . . . . . . . . . .> 1;
   No rows affected (0.022 seconds)
   0: jdbc:hive2://localhost:10000/default> SET x;
   +------+
   | set  |
   +------+
   | x=1  |
   +------+
   1 row selected (0.02 seconds)
   ```
   in Hive 4.x, the legacy Hive CLI was removed and replaced by `beeline`, 
which has the same behavior as Hive 2.3's `beeline`



-- 
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]

Reply via email to