Search in sources :

Example 21 with DdlResult

use of com.alibaba.otter.canal.parse.inbound.mysql.ddl.DdlResult in project canal by alibaba.

the class SimpleDdlParserTest method testCreate.

@Test
public void testCreate() {
    String queryString = "CREATE TABLE retl_mark ( `ID` int(11)";
    DdlResult result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("retl", result.getSchemaName());
    Assert.assertEquals("retl_mark", result.getTableName());
    queryString = "CREATE TABLE IF NOT EXISTS retl.retl_mark ( `ID` int(11)";
    result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("retl", result.getSchemaName());
    Assert.assertEquals("retl_mark", result.getTableName());
    queryString = "CREATE TABLE IF NOT EXISTS `retl_mark` ( `ID` int(11)";
    result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("retl", result.getSchemaName());
    Assert.assertEquals("retl_mark", result.getTableName());
    queryString = "CREATE TABLE IF NOT EXISTS `retl.retl_mark` ( `ID` int(11)";
    result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("retl", result.getSchemaName());
    Assert.assertEquals("retl_mark", result.getTableName());
    queryString = "CREATE TABLE  `retl`.`retl_mark` (\n  `ID` int(10) unsigned NOT NULL";
    result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("retl", result.getSchemaName());
    Assert.assertEquals("retl_mark", result.getTableName());
    queryString = "CREATE TABLE  `retl`.`retl_mark`(\n  `ID` int(10) unsigned NOT NULL";
    result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("retl", result.getSchemaName());
    Assert.assertEquals("retl_mark", result.getTableName());
    queryString = "CREATE table `bak591`.`j_order_log_back_201309` like j_order_log";
    result = SimpleDdlParser.parse(queryString, "bak");
    Assert.assertNotNull(result);
    Assert.assertEquals("bak591", result.getSchemaName());
    Assert.assertEquals("j_order_log_back_201309", result.getTableName());
    queryString = "CREATE DEFINER=sco*erce@% PROCEDURE SC_CPN_CODES_SAVE_ACTION(IN cosmosPassportId CHAR(32), IN orderId CHAR(32), IN codeIds TEXT) BEGIN SET @orderId = orderId; SET @timeNow = NOW(); START TRANSACTION; DELETE FROMsc_ord_couponWHEREORDER_ID= @orderId; SET @i=1; SET @numbers = FN_GET_ELEMENTS_COUNT(codeIds, '|'); WHILE @i <= @numbers DO SET @codeId = FN_FIND_ELEMENT_BYINDEX(codeIds, '|', @i); SET @orderCodeId = UUID32(); INSERT INTOsc_ord_coupon(ID,CREATE_BY,CREATE_TIME,UPDATE_BY,UPDATE_TIME,ORDER_ID,CODE_ID`) VALUES(@orderCodeId, cosmosPassportId, @timeNow, cosmosPassportId, @timeNow, @orderId, @codeId); SET @i = @i + 1; END WHILE; COMMIT; END";
    result = SimpleDdlParser.parse(queryString, "bak");
    Assert.assertEquals(EventType.QUERY, result.getType());
}
Also used : DdlResult(com.alibaba.otter.canal.parse.inbound.mysql.ddl.DdlResult) Test(org.junit.Test)

Example 22 with DdlResult

use of com.alibaba.otter.canal.parse.inbound.mysql.ddl.DdlResult in project canal by alibaba.

the class SimpleDdlParserTest method testDrop.

@Test
public void testDrop() {
    String queryString = "DROP TABLE retl_mark";
    DdlResult result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("retl_mark", result.getTableName());
    queryString = "DROP TABLE IF EXISTS retl.retl_mark;";
    result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("retl_mark", result.getTableName());
    queryString = "DROP TABLE IF EXISTS \n `retl.retl_mark` /;";
    result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("retl_mark", result.getTableName());
    queryString = "DROP /*!40005 TEMPORARY */  /*!40005 TEMPORARY */ TABLE IF EXISTS `temp_bond_keys`.`temp_bond_key_id`;";
    result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("temp_bond_keys", result.getSchemaName());
    Assert.assertEquals("temp_bond_key_id", result.getTableName());
    queryString = "CREATE TABLE performance_schema.cond_instances(NAME ";
    result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("performance_schema", result.getSchemaName());
    Assert.assertEquals("cond_instances", result.getTableName());
}
Also used : DdlResult(com.alibaba.otter.canal.parse.inbound.mysql.ddl.DdlResult) Test(org.junit.Test)

Example 23 with DdlResult

use of com.alibaba.otter.canal.parse.inbound.mysql.ddl.DdlResult in project canal by alibaba.

the class SimpleDdlParserTest method testTruncate.

@Test
public void testTruncate() {
    String queryString = "truncate table retl_mark";
    DdlResult result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("retl_mark", result.getTableName());
    queryString = "truncate table retl.retl_mark";
    result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("retl_mark", result.getTableName());
    queryString = "truncate \n  `retl.retl_mark` ";
    result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("retl_mark", result.getTableName());
}
Also used : DdlResult(com.alibaba.otter.canal.parse.inbound.mysql.ddl.DdlResult) Test(org.junit.Test)

Example 24 with DdlResult

use of com.alibaba.otter.canal.parse.inbound.mysql.ddl.DdlResult in project canal by alibaba.

the class SimpleDdlParserTest method testRename.

@Test
public void testRename() {
    String queryString = "rename table retl_mark to retl_mark2";
    DdlResult result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("retl", result.getOriSchemaName());
    Assert.assertEquals("retl", result.getSchemaName());
    Assert.assertEquals("retl_mark", result.getOriTableName());
    Assert.assertEquals("retl_mark2", result.getTableName());
    queryString = "rename table retl.retl_mark to retl2.retl_mark2";
    result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("retl", result.getOriSchemaName());
    Assert.assertEquals("retl2", result.getSchemaName());
    Assert.assertEquals("retl_mark", result.getOriTableName());
    Assert.assertEquals("retl_mark2", result.getTableName());
    queryString = "rename \n table \n `retl`.`retl_mark` to `retl2.retl_mark2`;";
    result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("retl", result.getOriSchemaName());
    Assert.assertEquals("retl2", result.getSchemaName());
    Assert.assertEquals("retl_mark", result.getOriTableName());
    Assert.assertEquals("retl_mark2", result.getTableName());
    queryString = "rename \n table \n `retl`.`retl_mark` to `retl2.retl_mark2` , `retl1`.`retl_mark1` to `retl3.retl_mark3`;";
    result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("retl", result.getOriSchemaName());
    Assert.assertEquals("retl2", result.getSchemaName());
    Assert.assertEquals("retl_mark", result.getOriTableName());
    Assert.assertEquals("retl_mark2", result.getTableName());
    result = result.getRenameTableResult();
    Assert.assertNotNull(result);
    Assert.assertEquals("retl1", result.getOriSchemaName());
    Assert.assertEquals("retl3", result.getSchemaName());
    Assert.assertEquals("retl_mark1", result.getOriTableName());
    Assert.assertEquals("retl_mark3", result.getTableName());
    // 正则匹配test case
    queryString = "rename table totl_mark to totl_mark2";
    result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("retl", result.getOriSchemaName());
    Assert.assertEquals("retl", result.getSchemaName());
    Assert.assertEquals("totl_mark", result.getOriTableName());
    Assert.assertEquals("totl_mark2", result.getTableName());
    queryString = "rename table totl.retl_mark to totl2.retl_mark2";
    result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("totl", result.getOriSchemaName());
    Assert.assertEquals("totl2", result.getSchemaName());
    Assert.assertEquals("retl_mark", result.getOriTableName());
    Assert.assertEquals("retl_mark2", result.getTableName());
    queryString = "rename \n table \n `totl`.`retl_mark` to `totl2.retl_mark2`;";
    result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("totl", result.getOriSchemaName());
    Assert.assertEquals("totl2", result.getSchemaName());
    Assert.assertEquals("retl_mark", result.getOriTableName());
    Assert.assertEquals("retl_mark2", result.getTableName());
    queryString = "rename \n table \n `totl`.`retl_mark` to `totl2.retl_mark2` , `totl1`.`retl_mark1` to `totl3.retl_mark3`;";
    result = SimpleDdlParser.parse(queryString, "retl");
    Assert.assertNotNull(result);
    Assert.assertEquals("totl", result.getOriSchemaName());
    Assert.assertEquals("totl2", result.getSchemaName());
    Assert.assertEquals("retl_mark", result.getOriTableName());
    Assert.assertEquals("retl_mark2", result.getTableName());
    result = result.getRenameTableResult();
    Assert.assertNotNull(result);
    Assert.assertEquals("totl1", result.getOriSchemaName());
    Assert.assertEquals("totl3", result.getSchemaName());
    Assert.assertEquals("retl_mark1", result.getOriTableName());
    Assert.assertEquals("retl_mark3", result.getTableName());
}
Also used : DdlResult(com.alibaba.otter.canal.parse.inbound.mysql.ddl.DdlResult) Test(org.junit.Test)

Example 25 with DdlResult

use of com.alibaba.otter.canal.parse.inbound.mysql.ddl.DdlResult in project canal by alibaba.

the class DdlResultTest method setSchemaNameInputNotNullOutputVoid.

// Test written by Diffblue Cover.
@Test
public void setSchemaNameInputNotNullOutputVoid() {
    // Arrange
    final DdlResult objectUnderTest = new DdlResult();
    final String schemaName = "3";
    // Act
    objectUnderTest.setSchemaName(schemaName);
    // Assert side effects
    Assert.assertEquals("3", objectUnderTest.getSchemaName());
}
Also used : DdlResult(com.alibaba.otter.canal.parse.inbound.mysql.ddl.DdlResult) Test(org.junit.Test)

Aggregations

DdlResult (com.alibaba.otter.canal.parse.inbound.mysql.ddl.DdlResult)33 Test (org.junit.Test)29 CanalParseException (com.alibaba.otter.canal.parse.exception.CanalParseException)3 ByteString (com.google.protobuf.ByteString)3 EventType (com.alibaba.otter.canal.protocol.CanalEntry.EventType)2 MetaHistoryDO (com.alibaba.otter.canal.parse.inbound.mysql.tsdb.dao.MetaHistoryDO)1 Header (com.alibaba.otter.canal.protocol.CanalEntry.Header)1 RowChange (com.alibaba.otter.canal.protocol.CanalEntry.RowChange)1 TransactionBegin (com.alibaba.otter.canal.protocol.CanalEntry.TransactionBegin)1 TransactionEnd (com.alibaba.otter.canal.protocol.CanalEntry.TransactionEnd)1 EntryPosition (com.alibaba.otter.canal.protocol.position.EntryPosition)1 LogHeader (com.taobao.tddl.dbsync.binlog.event.LogHeader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 List (java.util.List)1