public static ReduceSinkDesc getReduceSinkDesc(
      List<ExprNodeDesc> keyCols, int numKeys, List<ExprNodeDesc> valueCols,
      List<List<Integer>> distinctColIndices,
      List<String> outputKeyColumnNames, List<String> outputValueColumnNames,
      boolean includeKey, int tag,
      int numPartitionFields, int numReducers, AcidUtils.Operation writeType,
      NullOrdering defaultNullOrder)
      throws SemanticException {

    ArrayList<ExprNodeDesc> partitionCols = new ArrayList<>();
    if (numPartitionFields >= keyCols.size()) {
      partitionCols.addAll(keyCols);
    } else if (numPartitionFields >= 0) {
      partitionCols.addAll(keyCols.subList(0, numPartitionFields));
    } else {
      // numPartitionFields = -1 means random partitioning
      partitionCols.add(ExprNodeTypeCheck.getExprNodeDefaultExprProcessor().
          getFuncExprNodeDesc("rand"));
    }

    StringBuilder order = new StringBuilder();
    StringBuilder nullOrder = new StringBuilder();
    for (int i = 0; i < keyCols.size(); i++) {
      order.append("+");
      nullOrder.append(defaultNullOrder.getSign());
    }
    return getReduceSinkDesc(keyCols, numKeys, valueCols, distinctColIndices,
        outputKeyColumnNames, outputValueColumnNames, includeKey, tag,
        partitionCols, order.toString(), nullOrder.toString(), defaultNullOrder, numReducers, writeType);
  }
Create the reduce sink descriptor.

@param keyCols
         The columns to be stored in the key
@param numKeys  number of distribution keys. Equals to group-by-key
       numbers usually.
@param valueCols
         The columns to be stored in the value
@param distinctColIndices
         column indices for distinct aggregates
@param outputKeyColumnNames
         The output key columns names
@param outputValueColumnNames
         The output value columns names
@param tag
         The tag for this reducesink
@param numPartitionFields
         The first numPartitionFields of keyCols will be partition columns.
         If numPartitionFields=-1, then partition randomly.
@param numReducers
         The number of reducers, set to -1 for automatic inference based on
         input data size.
@param writeType Whether this is an Acid write, and if so whether it is insert, update,
                 or delete.
@return The reduceSinkDesc object.
ql/src/java/org/apache/hadoop/hive/ql/plan/PlanUtils.java