private static boolean isValidRelNodePlan(RelNode rel, RelMetadataQuery mq) {
      final Multimap<Class<? extends RelNode>, RelNode> m =
          mq.getNodeTypes(rel);
      for (Entry<Class<? extends RelNode>, Collection<RelNode>> e : m.asMap().entrySet()) {
        Class<? extends RelNode> c = e.getKey();
        if (!TableScan.class.isAssignableFrom(c)
            && !Project.class.isAssignableFrom(c)
            && !Filter.class.isAssignableFrom(c)
            && !Join.class.isAssignableFrom(c)) {
          // Skip it
          return false;
        }
        if (Join.class.isAssignableFrom(c)) {
          for (RelNode n : e.getValue()) {
            final Join join = (Join) n;
            if (join.getJoinType() != JoinRelType.INNER && !join.isSemiJoin()) {
              // Skip it
              return false;
            }
          }
        }
      }
      return true;
    }
Rule that replaces Box operators by the plan they hold.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/views/HiveMaterializedViewBoxing.java