private void quoteIdentifierTokens(TokenRewriteStream tokenRewriteStream) {
    if (conf.getVar(ConfVars.HIVE_QUOTEDID_SUPPORT).equals("none")) {
      return;
    }

    for (int idx = tokenRewriteStream.MIN_TOKEN_INDEX; idx <= tokenRewriteStream.size()-1; idx++) {
      Token curTok = tokenRewriteStream.get(idx);
      if (curTok.getType() == HiveLexer.Identifier) {
        // The Tokens have no distinction between Identifiers and QuotedIdentifiers.
        // Ugly solution is just to surround all identifiers with quotes.
        // Re-escape any backtick (`) characters in the identifier.
        String escapedTokenText = curTok.getText().replaceAll("`", "``");
        tokenRewriteStream.replace(curTok, "`" + escapedTokenText + "`");
      }
    }
  }
Construct the data structures containing ExprNodeDesc for partition
columns and order columns. Use the input definition to construct the list
of output columns for the ReduceSinkOperator
ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java