private List<HiveRelOptMaterialization> getValidMaterializedViews(
      List<Table> materializedViewTables,
      Set<TableName> tablesUsed, boolean forceMVContentsUpToDate, boolean expandGroupingSets,
      Supplier<String> validTxnsList, HiveTxnManager txnMgr,
      EnumSet<RewriteAlgorithm> scope) throws HiveException {
    final boolean tryIncrementalRewriting =
        HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_MATERIALIZED_VIEW_REWRITING_INCREMENTAL);
    final boolean tryIncrementalRebuild =
        HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_MATERIALIZED_VIEW_REBUILD_INCREMENTAL);
    try {
      // Final result
      List<HiveRelOptMaterialization> result = new ArrayList<>();
      for (Table materializedViewTable : materializedViewTables) {
        final Boolean outdated = isOutdatedMaterializedView(
            materializedViewTable, tablesUsed, forceMVContentsUpToDate, validTxnsList, txnMgr);
        if (outdated == null) {
          continue;
        }

        final MaterializedViewMetadata metadata = materializedViewTable.getMVMetadata();
        Materialization invalidationInfo = null;
        if (outdated) {
          // The MV is outdated, see whether we should consider it for rewriting or not
          boolean ignore;
          if (forceMVContentsUpToDate && !tryIncrementalRebuild) {
            // We will not try partial rewriting for rebuild if incremental rebuild is disabled
            ignore = true;
          } else if (!forceMVContentsUpToDate && !tryIncrementalRewriting) {
            // We will not try partial rewriting for non-rebuild if incremental rewriting is disabled
            ignore = true;
          } else {
            // Obtain additional information if we should try incremental rewriting / rebuild
            // We will not try partial rewriting if there were update/delete/compaction operations on source tables
            invalidationInfo = getMaterializationInvalidationInfo(metadata);
            ignore = invalidationInfo == null || invalidationInfo.isSourceTablesCompacted();
          }
          if (ignore) {
            LOG.debug("Materialized view " + materializedViewTable.getFullyQualifiedName() +
                " ignored for rewriting as its contents are outdated");
            continue;
          }
        }

        // It passed the test, load
        HiveRelOptMaterialization relOptMaterialization =
            HiveMaterializedViewsRegistry.get().getRewritingMaterializedView(
                materializedViewTable.getDbName(), materializedViewTable.getTableName(), scope);
        if (relOptMaterialization != null) {
          Table cachedMaterializedViewTable = extractTable(relOptMaterialization);
          if (cachedMaterializedViewTable.equals(materializedViewTable)) {
            // It is in the cache and up to date
            if (outdated) {
              // We will rewrite it to include the filters on transaction list
              // so we can produce partial rewritings
              relOptMaterialization = HiveMaterializedViewUtils.augmentMaterializationWithTimeInformation(
                  relOptMaterialization, validTxnsList,
                  metadata.getSnapshot());
            }
            addToMaterializationList(expandGroupingSets, invalidationInfo, relOptMaterialization, result);
            continue;
          }
        }

        // It was not present in the cache (maybe because it was added by another HS2)
        // or it is not up to date. We need to add it
        if (LOG.isDebugEnabled()) {
          LOG.debug("Materialized view " + materializedViewTable.getFullyQualifiedName() +
              " was not in the cache or it is not supported by specified rewrite algorithm {}", scope);
        }
        HiveRelOptMaterialization hiveRelOptMaterialization =
                HiveMaterializedViewsRegistry.get().createMaterialization(conf, materializedViewTable);
        if (hiveRelOptMaterialization != null && hiveRelOptMaterialization.isSupported(scope)) {
          relOptMaterialization = hiveRelOptMaterialization;
          HiveMaterializedViewsRegistry.get().refreshMaterializedView(conf, null, materializedViewTable);
          if (outdated) {
            // We will rewrite it to include the filters on transaction list
            // so we can produce partial rewritings
            relOptMaterialization = HiveMaterializedViewUtils.augmentMaterializationWithTimeInformation(
                hiveRelOptMaterialization, validTxnsList, 
                metadata.getSnapshot());
          }
          addToMaterializationList(expandGroupingSets, invalidationInfo, relOptMaterialization, result);
        }
      }
      return result;
    } catch (Exception e) {
      throw new HiveException(e);
    }
  }
Get the target materialized view from the metastore. Although it may load the plan
from the registry, it is guaranteed that it will always return an up-to-date version
wrt metastore.

@return the materialized view for rebuild
@throws HiveException
ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java