@Test public void testAddSourcePrefixRenameTable() throws Exception { String ddl = "RENAME TABLE `db1`.`table1` TO `tmp`.`table1`"; String expectedDDL = "RENAME TABLE `source/db1`.`table1` TO `source/tmp`.`table1`"; assertEquals(expectedDDL, schemaDatabase.addSourcePrefix(ddl)); ddl = "RENAME TABLE airbed3_production.20170810023312170_reservation2s to tmp.20170810023312170_reservation2s"; expectedDDL = "RENAME TABLE `source/airbed3_production`.`20170810023312170_reservation2s` to `source/tmp`.`20170810023312170_reservation2s`"; assertEquals(expectedDDL, schemaDatabase.addSourcePrefix(ddl)); ddl = "RENAME TABLE `table123` TO new_table_123, some_db.table123 TO `other_db`.table456"; expectedDDL = "RENAME TABLE `table123` TO new_table_123, `source/some_db`.`table123` TO `source/other_db`.`table456`"; 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(); }    }