String build() {
    StringBuilder query = new StringBuilder(operation.toString());

    if (operation == Operation.CREATE) {
      query.append(" temporary external");
    }
    if (operation == Operation.INSERT) {
      query.append(CompactionType.REBALANCE.equals(compactionType) ? " overwrite" : " into");
    }
    query.append(" table ");

    if (operation == Operation.DROP) {
      query.append("if exists ");
    }

    query.append(resultTableName);

    switch (operation) {
    case CREATE:
      getDdlForCreate(query);
      break;
    case ALTER:
      buildAddClauseForAlter(query);
      break;
    case INSERT:
      query.append(" select ");
      buildSelectClauseForInsert(query);
      query.append(" from ");
      getSourceForInsert(query);
      buildWhereClauseForInsert(query);
      break;
    case DROP:
    default:
    }
    return query.toString();
  }
Build the query string based on parameters.

@return query String
ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/CompactionQueryBuilder.java