Index: beeline/src/java/org/apache/hive/beeline/Commands.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- beeline/src/java/org/apache/hive/beeline/Commands.java (revision e8bcd2b19340da892185ca90d7a010d668ac2517) +++ beeline/src/java/org/apache/hive/beeline/Commands.java (revision c8ed87720749a3b37dc7381ba820f451b7394936) @@ -748,6 +748,42 @@ return execute(line, true, false); } + static String removeComments(String line) { + if (line == null || line.isEmpty()) { + return line; + } + + StringBuilder builder = new StringBuilder(); + int escape = -1; + for (int index = 0; index < line.length(); index++) { + + if (index < line.length() - 1 && line.charAt(index) == line.charAt(index + 1)) { + if (escape == -1 && line.charAt(index) == '-') { + //find \n as the end of comment + index = line.indexOf('\n',index+1); + + //there is no sql after this comment,so just break out + if (-1==index){ + break; + } + } + } + + char letter = line.charAt(index); + if (letter == escape) { + escape = -1; // Turn escape off. + } else if (escape == -1 && (letter == '\'' || letter == '"')) { + escape = letter; // Turn escape on. + } + + + builder.append(letter); + + } + + return builder.toString().replaceAll("#.*?\n", "\n"); + } + private boolean execute(String line, boolean call, boolean entireLineAsCommand) { if (line == null || line.length() == 0) { return false; // ??? @@ -795,8 +831,10 @@ if (!(beeLine.assertConnection())) { return false; } + //remove comments line = line.trim(); + line=this.removeComments(line); List cmdList = new ArrayList(); if (entireLineAsCommand) { cmdList.add(line);