public List<HiveRelOptMaterialization> getMaterializedViewsByAST(
          ASTNode astNode, Set<TableName> tablesUsed,  Supplier<String> validTxnsList, HiveTxnManager txnMgr) throws HiveException {

    List<HiveRelOptMaterialization> materializedViews =
            HiveMaterializedViewsRegistry.get().getRewritingMaterializedViews(astNode);
    if (materializedViews.isEmpty()) {
      return Collections.emptyList();
    }

    try {
      // Final result
      List<HiveRelOptMaterialization> result = new ArrayList<>();
      for (HiveRelOptMaterialization materialization : materializedViews) {
        Table materializedViewTable = extractTable(materialization);
        final Boolean outdated = isOutdatedMaterializedView(materializedViewTable, tablesUsed, 
            false, validTxnsList, txnMgr);
        if (outdated == null) {
          LOG.debug("Unable to determine if Materialized view " + materializedViewTable.getFullyQualifiedName() +
                  " contents are outdated. It may uses external tables?");
          continue;
        }

        if (outdated) {
          LOG.debug("Materialized view " + materializedViewTable.getFullyQualifiedName() +
                  " ignored for rewriting as its contents are outdated");
          continue;
        }

        result.add(materialization);
      }
      return result;
    } catch (Exception e) {
      throw new HiveException(e);
    }
  }
Get the materialized views from the metastore or from the registry which has the same query definition as the
specified sql query text. It is guaranteed that it will always return an up-to-date version wrt metastore.
This method filters out outdated Materialized views. It compares the transaction ids of the passed usedTables and
the materialized view using the txnMgr.
@param tablesUsed List of tables to verify whether materialized view is outdated
@param txnMgr Transaction manager to get open transactions affects used tables.
@return List of materialized views has matching query definition with querySql
@throws HiveException - an exception is thrown during validation or unable to pull transaction ids
ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java