Source:
private static String execDropTable(Database db, String sql, SqlDropTable dropStmt, VoltXMLElement schema, VoltCompiler compiler) { final String tableName = dropStmt.getOperandList().get(0).toString(); final boolean ignoreNotFound = dropStmt.getIfExists(), cascaded = dropStmt.getCascade(); final Optional<Table> table = db == null ? Optional.empty() : StreamSupport.stream(((Iterable<Table>) db.getTables()::iterator).spliterator(), false) .filter(tbl -> tbl.getTypeName().equals(tableName)).findAny(); CreateTableUtils.exceptWhen(!ignoreNotFound && !table.isPresent(), String.format("Table %s not found", tableName)); if (table.isPresent()) { final Table tbl = table.get(); final Set<String> materializedViews = collectMaterializedViews(tbl), procs = collectStoredProcedures(db, new HashSet<String>(){{ addAll(materializedViews); add(tableName); }}); CreateTableUtils.exceptWhen(! procs.isEmpty(), String.format("Cannot drop table %s: stored procedure(s) %s depend on it.", tableName, String.join(", ", procs))); final String viewNames = String.join(", ", materializedViews); CreateTableUtils.exceptWhen(!cascaded && !materializedViews.isEmpty(), String.format("Dependent object exists: PUBLIC.%s in statement [%s]", viewNames, sql)); materializedViews.add(tableName); final VoltXMLElement.VoltXMLDiff od = new VoltXMLElement.VoltXMLDiff("databaseschemadatabaseschema"); IntStream.range(0, schema.children.size()) .filter(index -> { final VoltXMLElement elm = schema.children.get(index); final String dirtyTable = elm.attributes.get("name"); if (elm.name.equals("table") && materializedViews.contains(dirtyTable)) { compiler.markTableAsDirty(dirtyTable); od.getRemovedNodes().add(elm); return true; } else { return false; } }).boxed().sorted(Comparator.reverseOrder()) .forEach(schema.children::remove); schema.applyDiff(od); return Encoder.hexEncode(sql) + "\n"; } else { return ""; } }

Target:
private static String execDropTable(Database db, String sql, SqlDropTable dropStmt, VoltXMLElement schema, VoltCompiler compiler) { final String tableName = dropStmt.getOperandList().get(0).toString(); final boolean ignoreNotFound = dropStmt.getIfExists(), cascaded = dropStmt.getCascade(); final Optional<Table> table = db == null ? Optional.empty() : StreamSupport.stream(((Iterable<Table>) db.getTables()::iterator).spliterator(), false) .filter(tbl -> tbl.getTypeName().equals(tableName)).findAny(); CreateTableUtils.exceptWhen(!ignoreNotFound && !table.isPresent(), String.format("Table %s not found", tableName)); if (table.isPresent()) { final Table tbl = table.get(); final Set<String> materializedViews = collectMaterializedViews(tbl), procs = collectStoredProcedures(db, new HashSet<String>(){{ addAll(materializedViews); add(tableName); }}); CreateTableUtils.exceptWhen(! procs.isEmpty(), String.format("Cannot drop table %s: stored procedure(s) %s depend on it.", tableName, String.join(", ", procs))); final String viewNames = String.join(", ", materializedViews); CreateTableUtils.exceptWhen(!cascaded && !materializedViews.isEmpty(), String.format("Dependent object exists: PUBLIC.%s in statement [%s]", viewNames, sql)); materializedViews.add(tableName); final VoltXMLElement.VoltXMLDiff od = new VoltXMLElement.VoltXMLDiff("databaseschemadatabaseschema"); for (int index = schema.children.size() - 1; index >= 0; --index) { final VoltXMLElement elm = schema.children.get(index); final String dirtyTable = elm.attributes.get("name"); if (elm.name.equals("table") && materializedViews.contains(dirtyTable)) { compiler.markTableAsDirty(dirtyTable); od.getRemovedNodes().add(elm); schema.children.remove(index); } } schema.applyDiff(od); return Encoder.hexEncode(sql) + "\n"; } else { return ""; } }