private List<Partition> getPartitionsList(Hive db) throws HiveException {
    if (work.getLoadFileDesc() != null) {
      return null; //we are in CTAS, so we know there are no partitions
    }

    if (work.getTableSpecs() != null) {

      // ANALYZE command
      TableSpec tblSpec = work.getTableSpecs();
      table = tblSpec.tableHandle;
      if (!table.isPartitioned()) {
        return null;
      }
      // get all partitions that match with the partition spec
      return tblSpec.partitions != null ? unmodifiableList(tblSpec.partitions) : emptyList();
    } else if (work.getLoadTableDesc() != null) {

      // INSERT OVERWRITE command
      LoadTableDesc tbd = work.getLoadTableDesc();
      table = db.getTable(tbd.getTable().getTableName());
      if (!table.isPartitioned() || table.hasNonNativePartitionSupport()) {
        return null;
      }
      DynamicPartitionCtx dpCtx = tbd.getDPCtx();
      if (dpCtx != null && dpCtx.getNumDPCols() > 0) { // dynamic partitions
        // If no dynamic partitions are generated, dpPartSpecs may not be initialized
        if (dpPartSpecs != null) {
          // Reload partition metadata because another BasicStatsTask instance may have updated the stats.
          List<String> partNames = dpPartSpecs.stream().map(Partition::getName).collect(Collectors.toList());
          return db.getPartitionsByNames(table, partNames);
        }
      } else { // static partition
        return singletonList(db.getPartition(table, tbd.getPartitionSpec()));
      }
    }
    return emptyList();
  }
Get the list of partitions that need to update statistics.
TODO: we should reuse the Partitions generated at compile time
since getting the list of partitions is quite expensive.

@return a list of partitions that need to update statistics.
@throws HiveException
ql/src/java/org/apache/hadoop/hive/ql/stats/BasicStatsTask.java