diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLine.java b/beeline/src/java/org/apache/hive/beeline/BeeLine.java index 5773109..473670a 100644 --- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java +++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java @@ -940,7 +940,8 @@ boolean isComment(String line) { // SQL92 comment prefix is "--" // beeline also supports shell-style "#" prefix - return line.startsWith("#") || line.startsWith("--"); + String lineTrimmed = line.trim(); + return lineTrimmed.startsWith("#") || lineTrimmed.startsWith("--"); } /** diff --git a/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java b/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java index 741cc47..4d15e3c 100644 --- a/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java +++ b/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java @@ -191,6 +191,19 @@ } scriptFile.delete(); } + + /** + * Test that BeeLine will read comment lines that start with whitespace + * @throws Throwable + */ + @Test + public void testWhitespaceBeforeCommentScriptFile() throws Throwable { + final String TEST_NAME = "testWhitespaceBeforeCommentScriptFile"; + final String SCRIPT_TEXT = " -- comment has spaces and tabs before it\n # comment has spaces and tabs before it\n"; + final String EXPECTED_PATTERN = "cannot recognize input near ''"; + List argList = getBaseArgs(JDBC_URL); + testScriptFile(TEST_NAME, SCRIPT_TEXT, EXPECTED_PATTERN, false, argList); + } /** * Attempt to execute a simple script file with the -f option to BeeLine