@Override
      public void visit(RelNode node, int ordinal, RelNode parent) {
        if (node instanceof TableScan) {
          // We can continue
          // TODO: Need to check that this is the same MV that we are rebuilding
          RelOptHiveTable hiveTable = (RelOptHiveTable) node.getTable();
          if (!hiveTable.getHiveTableMD().isMaterializedView()) {
            // If it is not a materialized view, we do not rewrite it
            throw new ReturnedValue(IncrementalRebuildMode.NOT_AVAILABLE);
          }
          if (containsAggregate && !fullAcidView) {
            // If it contains an aggregate and it is not a full acid table,
            // we do not rewrite it (we need MERGE support)
            throw new ReturnedValue(IncrementalRebuildMode.NOT_AVAILABLE);
          }
        } else if (node instanceof Project) {
          // We can continue
          super.visit(node, ordinal, parent);
        } else {
          throw new ReturnedValue(IncrementalRebuildMode.NOT_AVAILABLE);
        }
      }
This class is a helper to check whether a materialized view rebuild
can be transformed from INSERT OVERWRITE to INSERT INTO.

We are verifying that:
  1) the rewriting is rooted by legal operators (Filter and Project)
  before reaching a Union operator,
  2) the left branch uses the MV that we are trying to rebuild and
  legal operators (Filter and Project), and
  3) the right branch only uses legal operators (i.e., Filter, Project,
  Join, and TableScan)
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/views/MaterializedViewRewritingRelVisitor.java