private static void findBucketingSortingColumns(List<ExprNodeDesc> exprs,
      List<ColumnInfo> colInfos, List<BucketCol> bucketCols, List<SortCol> sortCols,
      BucketCol[] newBucketCols, SortCol[] newSortCols, int colInfosOffset) {
    for(int cnt = 0; cnt < exprs.size(); cnt++) {
      ExprNodeDesc expr = exprs.get(cnt);

      // Only columns can be sorted/bucketed, in particular applying a function to a column
      // voids any assumptions
      if (!(expr instanceof ExprNodeColumnDesc)) {
        continue;
      }

      ExprNodeColumnDesc columnExpr = (ExprNodeColumnDesc)expr;

      int colInfosIndex = cnt + colInfosOffset;

      if (newBucketCols != null) {
        int bucketIndex = indexOfColName(bucketCols, columnExpr.getColumn());
        if (bucketIndex != -1) {
          if (newBucketCols[bucketIndex] == null) {
            newBucketCols[bucketIndex] = new BucketCol();
          }
          newBucketCols[bucketIndex].addAlias(
              colInfos.get(colInfosIndex).getInternalName(), colInfosIndex);
        }
      }

      if (newSortCols != null) {
        int sortIndex = indexOfColName(sortCols, columnExpr.getColumn());
        if (sortIndex != -1) {
          if (newSortCols[sortIndex] == null) {
            newSortCols[sortIndex] = new SortCol(sortCols.get(sortIndex).getSortOrder());
          }
          newSortCols[sortIndex].addAlias(
              colInfos.get(colInfosIndex).getInternalName(), colInfosIndex);
        }
      }
    }
  }
For each expression, check if it represents a column known to be bucketed/sorted.

The methods setBucketingColsIfComplete and setSortingColsIfComplete should be used to assign
the values of newBucketCols and newSortCols as the bucketing/sorting columns of this operator
because these arrays may contain nulls indicating that the output of this operator is not
bucketed/sorted.

@param exprs - list of expression
@param colInfos - list of column infos
@param bucketCols - list of bucketed columns from the input
@param sortCols - list of sorted columns from the input
@param newBucketCols - an array of bucket columns which should be the same length as
   bucketCols, updated such that the bucketed column(s) at index i in bucketCols became
   the bucketed column(s) at index i of newBucketCols in the output
@param newSortCols - an array of sort columns which should be the same length as
   sortCols, updated such that the sorted column(s) at index i in sortCols became
   the sorted column(s) at index i of sortCols in the output
@param colInfosOffset - the expressions are known to be represented by column infos
   beginning at this index
ql/src/java/org/apache/hadoop/hive/ql/optimizer/physical/BucketingSortingOpProcFactory.java