@Override
  public void analyzeInternal(ASTNode root) throws SemanticException {
    TableName tableName = getQualifiedTableName((ASTNode)root.getChild(0));

    // Value for the flag
    boolean rewriteEnable;
    switch (root.getChild(1).getType()) {
    case HiveParser.TOK_REWRITE_ENABLED:
      rewriteEnable = true;
      break;
    case HiveParser.TOK_REWRITE_DISABLED:
      rewriteEnable = false;
      break;
    default:
      throw new SemanticException("Invalid alter materialized view expression");
    }

    // It can be fully qualified name or use default database
    Table materializedViewTable = getTable(tableName, true);

    // One last test: if we are enabling the rewrite, we need to check that query
    // only uses transactional (MM and ACID and Iceberg) tables
    if (rewriteEnable) {
      for (SourceTable sourceTable : materializedViewTable.getMVMetadata().getSourceTables()) {
        Table table = new Table(sourceTable.getTable());
        if (!AcidUtils.isTransactionalTable(sourceTable.getTable()) &&
                !(table.isNonNative() && table.getStorageHandler().areSnapshotsSupported())) {
          throw new SemanticException("Automatic rewriting for materialized view cannot be enabled if the " +
              "materialized view uses non-transactional tables");
        }
      }
    }

    AlterMaterializedViewRewriteDesc desc =
        new AlterMaterializedViewRewriteDesc(tableName.getNotEmptyDbTable(), rewriteEnable);
    if (AcidUtils.isTransactionalTable(materializedViewTable)) {
      ddlDescWithWriteId = desc;
    }

    inputs.add(new ReadEntity(materializedViewTable));
    WriteEntity.WriteType type;
    if (MetaStoreUtils.isNonNativeTable(materializedViewTable.getTTable())
        && materializedViewTable.getStorageHandler().areSnapshotsSupported()) {
      type = WriteEntity.WriteType.DDL_SHARED;
    } else {
      type = AcidUtils.isLocklessReadsEnabled(materializedViewTable, conf) ?
          WriteEntity.WriteType.DDL_EXCL_WRITE : WriteEntity.WriteType.DDL_EXCLUSIVE;
    }
    outputs.add(new WriteEntity(materializedViewTable, type));

    // Create task for alterMVRewriteDesc
    DDLWork work = new DDLWork(getInputs(), getOutputs(), desc);
    Task<?> targetTask = TaskFactory.get(work);

    // Create task to update rewrite flag as dependant of previous one
    MaterializedViewUpdateDesc materializedViewUpdateDesc =
        new MaterializedViewUpdateDesc(tableName.getNotEmptyDbTable(), rewriteEnable, !rewriteEnable, false);
    DDLWork updateDdlWork = new DDLWork(getInputs(), getOutputs(), materializedViewUpdateDesc);
    targetTask.addDependentTask(TaskFactory.get(updateDdlWork, conf));

    // Add root task
    rootTasks.add(targetTask);
  }
Analyzer for alter materialized view rewrite commands.
ql/src/java/org/apache/hadoop/hive/ql/ddl/view/materialized/alter/rewrite/AlterMaterializedViewRewriteAnalyzer.java