@Override
  public void visit(RelNode node, int ordinal, RelNode parent) {
    if (node instanceof Aggregate) {
      this.containsAggregate = true;
      // Aggregate mode - it should be followed by union
      // that we need to analyze
      RelNode input = node.getInput(0);
      if (input instanceof Union) {
        check((Union) input);
      }
    } else if (node instanceof Union) {
      // Non aggregate mode - analyze union operator
      check((Union) node);
    } else if (node instanceof Project) {
      // Project operator, we can continue
      super.visit(node, ordinal, parent);
    }
    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