private boolean shouldDo(List<Integer> partitionPos, Operator<? extends OperatorDesc> fsParent) {

      int threshold = HiveConf.getIntVar(this.parseCtx.getConf(),
          HiveConf.ConfVars.HIVE_OPT_SORT_DYNAMIC_PARTITION_THRESHOLD);
      long MAX_WRITERS = -1;

      switch (threshold) {
      case -1:
        return false;
      case 0:
        break;
      case 1:
        return true;
      default:
        MAX_WRITERS = threshold;
        break;
      }

      Statistics tStats = fsParent.getStatistics();
      if (tStats == null) {
        return true;
      }

      List<ColStatistics> colStats = tStats.getColumnStats();
      if (colStats == null || colStats.isEmpty()) {
        return true;
      }
      long partCardinality = 1;

      // compute cardinality for partition columns
      for (Integer idx : partitionPos) {
        ColumnInfo ci = fsParent.getSchema().getSignature().get(idx);
        ColStatistics partStats = fsParent.getStatistics().getColumnStatisticsFromColName(ci.getInternalName());
        if (partStats == null) {
          // statistics for this partition are for some reason not available
          return true;
        }
        partCardinality = partCardinality * partStats.getCountDistint();
      }

      if (MAX_WRITERS < 0) {
        double orcMemPool = this.parseCtx.getConf().getDouble(OrcConf.MEMORY_POOL.getHiveConfName(),
            (Double) OrcConf.MEMORY_POOL.getDefaultValue());
        long orcStripSize = this.parseCtx.getConf().getLong(OrcConf.STRIPE_SIZE.getHiveConfName(),
            (Long) OrcConf.STRIPE_SIZE.getDefaultValue());
        MemoryInfo memoryInfo = new MemoryInfo(this.parseCtx.getConf());
        LOG.debug("Memory info during SDPO opt: {}", memoryInfo);
        long executorMem = memoryInfo.getMaxExecutorMemory();
        MAX_WRITERS = (long) (executorMem * orcMemPool) / orcStripSize;

      }
      if (partCardinality <= MAX_WRITERS) {
        return false;
      }
      return true;
    }
Get the sort order for the sort columns.

@param tabSortCols
@param tabCols
@return
ql/src/java/org/apache/hadoop/hive/ql/optimizer/SortedDynPartitionOptimizer.java