private static Boolean isOutdatedMaterializedView(
          MaterializationSnapshot snapshot, Hive db,
          Set<TableName> tablesUsed, Table materializedViewTable) throws HiveException {
    List<String> tablesUsedNames = tablesUsed.stream()
        .map(tableName -> TableName.getDbTable(tableName.getDb(), tableName.getTable()))
        .collect(Collectors.toList());

    Map<String, SnapshotContext> snapshotMap = snapshot.getTableSnapshots();
    if (snapshotMap == null || snapshotMap.isEmpty()) {
      LOG.debug("Materialized view {} ignored for rewriting as we could not obtain current snapshot ids",
              materializedViewTable.getFullyQualifiedName());
      return null;
    }

    Set<String> storedTablesUsed = materializedViewTable.getMVMetadata().getSourceTableFullNames();
    for (String fullyQualifiedTableName : tablesUsedNames) {
      // Note. If the materialized view does not contain a table that is contained in the query,
      // we do not need to check whether that specific table is outdated or not. If a rewriting
      // is produced in those cases, it is because that additional table is joined with the
      // existing tables with an append-columns only join, i.e., PK-FK + not null.
      if (!storedTablesUsed.contains(fullyQualifiedTableName)) {
        continue;
      }

      Table table = db.getTable(fullyQualifiedTableName);
      if (table.getStorageHandler() == null) {
        LOG.debug("Materialized view {} ignored for rewriting as we could not get storage handler of table {}",
                materializedViewTable.getFullyQualifiedName(), fullyQualifiedTableName);
        return null;
      }
      if (!table.getStorageHandler().areSnapshotsSupported()) {
        LOG.debug("Materialized view {} ignored for rewriting as storage handler of table {} " +
                        "does not support snapshots.",
                materializedViewTable.getFullyQualifiedName(), fullyQualifiedTableName);
        return null;
      }
      SnapshotContext currentTableSnapshot = table.getStorageHandler().getCurrentSnapshotContext(table);
      SnapshotContext storedTableSnapshot = snapshotMap.get(fullyQualifiedTableName);
      if (!Objects.equals(currentTableSnapshot, storedTableSnapshot)) {
        LOG.debug("Materialized view {} contents are outdated", materializedViewTable.getFullyQualifiedName());
        return true;
      }
    }

    return false;
  }
Utility method that returns whether a materialized view is outdated (true), not outdated
(false), or it cannot be determined (null). The latest case may happen e.g. when the
materialized view definition uses external tables.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/views/HiveMaterializedViewUtils.java