@Test public void testAddSourcePrefixDropIndex() throws Exception { String ddl = "DROP INDEX `index123` ON table"; assertEquals(ddl, schemaDatabase.addSourcePrefix(ddl)); ddl = "DROP INDEX `index222` ON `db_name`.`table22`;"; String expectedDDL = "DROP INDEX `index222` ON `source/db_name`.`table22`;"; assertEquals(expectedDDL, schemaDatabase.addSourcePrefix(ddl)); }
@VisibleForTesting String addSourcePrefix(@NotNull final String sql) { CharStream charStream = CharStreams.fromString(sql); MySQLLexer lexer = new MySQLLexer(charStream); CommonTokenStream tokens = new CommonTokenStream(lexer); MySQLParser parser = new MySQLParser(tokens); ParseTree tree = parser.root(); ParseTreeWalker walker = new ParseTreeWalker(); MySQLDBNamePrefixAdder prefixAdder = new com.airbnb.spinaltap.mysql.schema.MysqlSchemaDatabase.MySQLDBNamePrefixAdder(tokens); walker.walk(prefixAdder, tree); return prefixAdder.rewriter.getText(); }
MysqlSchemaDatabase { @VisibleForTesting String addSourcePrefix(@NotNull final String sql) { CharStream charStream = CharStreams.fromString(sql); MySQLLexer lexer = new MySQLLexer(charStream); CommonTokenStream tokens = new CommonTokenStream(lexer); MySQLParser parser = new MySQLParser(tokens); ParseTree tree = parser.root(); ParseTreeWalker walker = new ParseTreeWalker(); MySQLDBNamePrefixAdder prefixAdder = new com.airbnb.spinaltap.mysql.schema.MysqlSchemaDatabase.MySQLDBNamePrefixAdder(tokens); walker.walk(prefixAdder, tree); return prefixAdder.rewriter.getText(); } }
MysqlSchemaDatabase { @VisibleForTesting String addSourcePrefix(@NotNull final String sql) { CharStream charStream = CharStreams.fromString(sql); MySQLLexer lexer = new MySQLLexer(charStream); CommonTokenStream tokens = new CommonTokenStream(lexer); MySQLParser parser = new MySQLParser(tokens); ParseTree tree = parser.root(); ParseTreeWalker walker = new ParseTreeWalker(); MySQLDBNamePrefixAdder prefixAdder = new com.airbnb.spinaltap.mysql.schema.MysqlSchemaDatabase.MySQLDBNamePrefixAdder(tokens); walker.walk(prefixAdder, tree); return prefixAdder.rewriter.getText(); }  }
MysqlSchemaDatabase { @VisibleForTesting String addSourcePrefix(@NotNull final String sql) { CharStream charStream = CharStreams.fromString(sql); MySQLLexer lexer = new MySQLLexer(charStream); CommonTokenStream tokens = new CommonTokenStream(lexer); MySQLParser parser = new MySQLParser(tokens); ParseTree tree = parser.root(); ParseTreeWalker walker = new ParseTreeWalker(); MySQLDBNamePrefixAdder prefixAdder = new com.airbnb.spinaltap.mysql.schema.MysqlSchemaDatabase.MySQLDBNamePrefixAdder(tokens); walker.walk(prefixAdder, tree); return prefixAdder.rewriter.getText(); }   }
MysqlSchemaDatabase { @VisibleForTesting String addSourcePrefix(@NotNull final String sql) { CharStream charStream = CharStreams.fromString(sql); MySQLLexer lexer = new MySQLLexer(charStream); CommonTokenStream tokens = new CommonTokenStream(lexer); MySQLParser parser = new MySQLParser(tokens); ParseTree tree = parser.root(); ParseTreeWalker walker = new ParseTreeWalker(); MySQLDBNamePrefixAdder prefixAdder = new com.airbnb.spinaltap.mysql.schema.MysqlSchemaDatabase.MySQLDBNamePrefixAdder(tokens); walker.walk(prefixAdder, tree); return prefixAdder.rewriter.getText(); }    }