public static String removeComments(String statement) {
    if (statement == null) {
      return null;
    }
    Iterator<String> iterator = Splitter.on("\n").omitEmptyStrings().split(statement).iterator();
    int[] startQuote = {-1};
    StringBuilder ret = new StringBuilder(statement.length());
    while (iterator.hasNext()) {
      String lineWithComments = iterator.next();
      String lineNoComments = removeComments(lineWithComments, startQuote);
      ret.append(lineNoComments);
      if (iterator.hasNext() && !lineNoComments.isEmpty()) {
        ret.append("\n");
      }
    }
    return ret.toString().trim();
  }
Strip comments from a sql statement, tracking when the statement contains a string literal.

@param statement the input string
@return a stripped statement
common/src/java/org/apache/hive/common/util/HiveStringUtils.java