private SemanticNodeProcessor getSortDynPartProc(ParseContext pCtx) {
    return new SortedDynamicPartitionProc(pCtx);
  }
When dynamic partitioning (with or without bucketing and sorting) is enabled, this optimization
sorts the records on partition, bucket and sort columns respectively before inserting records
into the destination table. This enables reducers to keep only one record writer all the time
thereby reducing the the memory pressure on the reducers.
Sorting is based on the Dynamic Partitioning context that is already created in the file sink operator.
If that contains instructions for custom expression sorting, then this optimizer will disregard any partitioning or
bucketing information of the Hive (table format) table, and will arrange the plan solely as per the custom exprs.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/SortedDynPartitionOptimizer.java