@Test public void testAddSourcePrefixAlterTable() throws Exception { String ddl = "ALTER TABLE `gibraltar_production`.`_instrument_details_paypal_new`\n" + "ADD COLUMN `account_id` VARBINARY ( 255 ) NULL AFTER `paypal_email_encrypted`,\n" + "ADD COLUMN `first_name` VARBINARY ( 255 ) NULL AFTER `account_id`,\n" + "ADD COLUMN `updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"; String expectedDDL = "ALTER TABLE `source/gibraltar_production`.`_instrument_details_paypal_new`\n" + "ADD COLUMN `account_id` VARBINARY ( 255 ) NULL AFTER `paypal_email_encrypted`,\n" + "ADD COLUMN `first_name` VARBINARY ( 255 ) NULL AFTER `account_id`,\n" + "ADD COLUMN `updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"; assertEquals(expectedDDL, schemaDatabase.addSourcePrefix(ddl)); ddl = "ALTER TABLE my_test_table RENAME TO `tmp`.`my_test_table_1234`;"; expectedDDL = "ALTER TABLE my_test_table RENAME TO `source/tmp`.`my_test_table_1234`;"; assertEquals(expectedDDL, schemaDatabase.addSourcePrefix(ddl)); ddl = "ALTER TABLE test_db.test_table DROP INDEX some_index"; expectedDDL = "ALTER TABLE `source/test_db`.`test_table` DROP INDEX some_index"; assertEquals(expectedDDL, schemaDatabase.addSourcePrefix(ddl)); ddl = "ALTER TABLE `test_table123` DROP COLUMN `some_column`"; assertEquals(ddl, 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(); }    }