private List<ReadEntity> getRestrictedPartitionSet(Table targetTable) {
    List<ReadEntity> partitionsRead = new ArrayList<>();
    for (ReadEntity re : inputs) {
      if (re.isFromTopLevelQuery && re.getType() == Entity.Type.PARTITION && isTargetTable(re, targetTable)) {
        partitionsRead.add(re);
      }
    }
    return partitionsRead;
  }
If the optimizer has determined that it only has to read some of the partitions of the
target table to satisfy the query, then we know that the write side of update/delete
(and update/delete parts of merge)
can only write (at most) that set of partitions (since we currently don't allow updating
partition (or bucket) columns).  So we want to replace the table level
WriteEntity in the outputs with WriteEntity for each of these partitions
ToDo: see if this should be moved to SemanticAnalyzer itself since it applies to any
insert which does a select against the same table.  Then SemanticAnalyzer would also
be able to not use DP for the Insert...

Note that the Insert of Merge may be creating new partitions and writing to partitions
which were not read  (WHEN NOT MATCHED...).  WriteEntity for that should be created
in MoveTask (or some other task after the query is complete).
ql/src/java/org/apache/hadoop/hive/ql/parse/RewriteSemanticAnalyzer.java