diff --git beeline/src/java/org/apache/hive/beeline/Commands.java beeline/src/java/org/apache/hive/beeline/Commands.java index 3b2d72ed79..fac979ac1a 100644 --- beeline/src/java/org/apache/hive/beeline/Commands.java +++ beeline/src/java/org/apache/hive/beeline/Commands.java @@ -1076,9 +1076,12 @@ String removeComments(String line, int[] startQuote) { if (line == null || line.isEmpty()) return line; if (startQuote[0] == -1 && beeLine.isComment(line)) return ""; //assume # can only be used at the beginning of line. StringBuilder builder = new StringBuilder(); - for (int index = 0; index < line.length(); index++) { + for (int index = 0; index < line.length(); ){ if (startQuote[0] == -1 && index < line.length() - 1 && line.charAt(index) == '-' && line.charAt(index + 1) =='-') { - return builder.toString().trim(); + // Jump to the end of current line. When a multiple line query is executed with -e parameter, + // it is passed in as one line string separated with '\n' + for (; index < line.length() && line.charAt(index) != '\n'; ++index); + continue; } char letter = line.charAt(index); @@ -1089,6 +1092,7 @@ String removeComments(String line, int[] startQuote) { } builder.append(letter); + index++; } return builder.toString().trim(); diff --git beeline/src/test/org/apache/hive/beeline/TestCommands.java beeline/src/test/org/apache/hive/beeline/TestCommands.java index 04c939a04c..d805a35a1f 100644 --- beeline/src/test/org/apache/hive/beeline/TestCommands.java +++ beeline/src/test/org/apache/hive/beeline/TestCommands.java @@ -43,6 +43,9 @@ public void testLinesEndingWithComments() { assertEquals("\"'show --comments' tables\"", commands.removeComments("\"'show --comments' tables\" --comments",escape)); assertEquals("'show --comments tables'", commands.removeComments("'show --comments tables' --comments",escape)); assertEquals("'\"show --comments tables\"'", commands.removeComments("'\"show --comments tables\"' --comments",escape)); + + assertEquals("select 1, \n2", commands.removeComments("select 1, --comments\n2 --comments",escape)); + assertEquals("select 1 '--comments', \n2", commands.removeComments("select 1 '--comments', --comments\n2 --comments",escape)); } } diff --git ql/src/test/queries/clientpositive/cmdwithcomments.q ql/src/test/queries/clientpositive/cmdwithcomments.q index e9c0d434c6..4c2963e067 100644 --- ql/src/test/queries/clientpositive/cmdwithcomments.q +++ ql/src/test/queries/clientpositive/cmdwithcomments.q @@ -10,4 +10,6 @@ limit 1; --comment7 select "this is another --string value" from numt where idx =2; --comment8 +select 1, --comment +2; drop table numt; diff --git ql/src/test/results/clientpositive/cmdwithcomments.q.out ql/src/test/results/clientpositive/cmdwithcomments.q.out index 93c9431334..151a82c206 100644 --- ql/src/test/results/clientpositive/cmdwithcomments.q.out +++ ql/src/test/results/clientpositive/cmdwithcomments.q.out @@ -63,12 +63,23 @@ POSTHOOK: Input: default@numt this is another --string value PREHOOK: query: --comment8 -drop table numt +select 1, --comment +2 +PREHOOK: type: QUERY +PREHOOK: Input: _dummy_database@_dummy_table +#### A masked pattern was here #### +POSTHOOK: query: --comment8 +select 1, --comment +2 +POSTHOOK: type: QUERY +POSTHOOK: Input: _dummy_database@_dummy_table +#### A masked pattern was here #### +1 2 +PREHOOK: query: drop table numt PREHOOK: type: DROPTABLE PREHOOK: Input: default@numt PREHOOK: Output: default@numt -POSTHOOK: query: --comment8 -drop table numt +POSTHOOK: query: drop table numt POSTHOOK: type: DROPTABLE POSTHOOK: Input: default@numt POSTHOOK: Output: default@numt