Search in sources :

Example 11 with TableId

use of io.debezium.relational.TableId in project debezium by debezium.

the class MySqlDdlParserTest method shouldParseAlterTableWithNewlineFeeds.

@FixFor("DBZ-162")
@Test
public void shouldParseAlterTableWithNewlineFeeds() {
    String ddl = "CREATE TABLE `test` (id INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT);";
    parser.parse(ddl, tables);
    assertThat(tables.size()).isEqualTo(1);
    Table t = tables.forTable(new TableId(null, null, "test"));
    assertThat(t).isNotNull();
    assertThat(t.columnNames()).containsExactly("id");
    assertThat(t.primaryKeyColumnNames()).containsExactly("id");
    assertColumn(t, "id", "INT UNSIGNED", Types.INTEGER, 11, -1, false, true, true);
    ddl = "ALTER TABLE `test` CHANGE `id` `collection_id` INT(11)\n UNSIGNED\n NOT NULL\n AUTO_INCREMENT;";
    parser.parse(ddl, tables);
    assertThat(tables.size()).isEqualTo(1);
    t = tables.forTable(new TableId(null, null, "test"));
    assertThat(t).isNotNull();
    assertThat(t.columnNames()).containsExactly("collection_id");
    assertThat(t.primaryKeyColumnNames()).containsExactly("collection_id");
    assertColumn(t, "collection_id", "INT UNSIGNED", Types.INTEGER, 11, -1, false, true, true);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test) FixFor(io.debezium.doc.FixFor)

Example 12 with TableId

use of io.debezium.relational.TableId in project debezium by debezium.

the class MySqlDdlParserTest method shouldParseCreateTableWithBitDefault.

@FixFor("DBZ-160")
@Test
public void shouldParseCreateTableWithBitDefault() {
    String ddl = "CREATE TABLE t ( c1 Bit(2) NOT NULL DEFAULT b'1', c2 Bit(2) NOT NULL);";
    parser.parse(ddl, tables);
    assertThat(tables.size()).isEqualTo(1);
    Table t = tables.forTable(new TableId(null, null, "t"));
    assertThat(t).isNotNull();
    assertThat(t.columnNames()).containsExactly("c1", "c2");
    assertThat(t.primaryKeyColumnNames()).isEmpty();
    assertColumn(t, "c1", "BIT", Types.BIT, 2, -1, false, false, false);
    assertColumn(t, "c2", "BIT", Types.BIT, 2, -1, false, false, false);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test) FixFor(io.debezium.doc.FixFor)

Example 13 with TableId

use of io.debezium.relational.TableId in project debezium by debezium.

the class MySqlDdlParserTest method parseDdlForUnscaledDecAndFixed.

@Test
@FixFor("DBZ-615")
public void parseDdlForUnscaledDecAndFixed() {
    String ddl = "CREATE TABLE t ( c1 DEC NOT NULL, c2 FIXED(3) NOT NULL);";
    parser.parse(ddl, tables);
    assertThat(tables.size()).isEqualTo(1);
    Table t = tables.forTable(new TableId(null, null, "t"));
    assertThat(t).isNotNull();
    assertThat(t.columnNames()).containsExactly("c1", "c2");
    assertThat(t.primaryKeyColumnNames()).isEmpty();
    assertColumn(t, "c1", "DEC", Types.DECIMAL, 10, 0, false, false, false);
    assertColumn(t, "c2", "FIXED", Types.DECIMAL, 3, 0, false, false, false);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test) FixFor(io.debezium.doc.FixFor)

Example 14 with TableId

use of io.debezium.relational.TableId in project debezium by debezium.

the class MySqlDdlParserTest method shouldParseCreateAndAlterWithOnUpdate.

@Test
@FixFor("DBZ-169")
public void shouldParseCreateAndAlterWithOnUpdate() {
    String ddl = "CREATE TABLE customers ( " + "id INT PRIMARY KEY NOT NULL, " + "name VARCHAR(30) NOT NULL, " + "PRIMARY KEY (id) );" + "" + "CREATE TABLE `CUSTOMERS_HISTORY` LIKE `customers`; " + "" + "ALTER TABLE `CUSTOMERS_HISTORY` MODIFY COLUMN `id` varchar(36) NOT NULL," + "DROP PRIMARY KEY," + "ADD action tinyint(3) unsigned NOT NULL FIRST," + "ADD revision int(10) unsigned NOT NULL AFTER action," + "ADD changed_on DATETIME NOT NULL DEFAULT NOW() AFTER revision," + "ADD PRIMARY KEY (id, revision);";
    parser.parse(ddl, tables);
    assertThat(tables.size()).isEqualTo(2);
    assertThat(listener.total()).isEqualTo(3);
    Table t = tables.forTable(new TableId(null, null, "customers"));
    assertThat(t).isNotNull();
    assertThat(t.columnNames()).containsExactly("id", "name");
    assertThat(t.primaryKeyColumnNames()).containsExactly("id");
    assertColumn(t, "id", "INT", Types.INTEGER, -1, -1, false, false, false);
    assertColumn(t, "name", "VARCHAR", Types.VARCHAR, 30, -1, false, false, false);
    assertThat(t.columnWithName("id").position()).isEqualTo(1);
    assertThat(t.columnWithName("name").position()).isEqualTo(2);
    t = tables.forTable(new TableId(null, null, "CUSTOMERS_HISTORY"));
    assertThat(t).isNotNull();
    assertThat(t).isNotNull();
    assertThat(t.columnNames()).containsExactly("action", "revision", "changed_on", "id", "name");
    assertThat(t.primaryKeyColumnNames()).containsExactly("id", "revision");
    assertColumn(t, "action", "TINYINT UNSIGNED", Types.SMALLINT, 3, -1, false, false, false);
    assertColumn(t, "revision", "INT UNSIGNED", Types.INTEGER, 10, -1, false, false, false);
    assertColumn(t, "changed_on", "DATETIME", Types.TIMESTAMP, -1, -1, false, false, false);
    assertColumn(t, "id", "VARCHAR", Types.VARCHAR, 36, -1, false, false, false);
    assertColumn(t, "name", "VARCHAR", Types.VARCHAR, 30, -1, false, false, false);
    assertThat(t.columnWithName("action").position()).isEqualTo(1);
    assertThat(t.columnWithName("revision").position()).isEqualTo(2);
    assertThat(t.columnWithName("changed_on").position()).isEqualTo(3);
    assertThat(t.columnWithName("id").position()).isEqualTo(4);
    assertThat(t.columnWithName("name").position()).isEqualTo(5);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test) FixFor(io.debezium.doc.FixFor)

Example 15 with TableId

use of io.debezium.relational.TableId in project debezium by debezium.

the class MySqlDdlParserTest method shouldParseStatementForDbz200.

@FixFor("DBZ-200")
@Test
public void shouldParseStatementForDbz200() {
    parser.parse(readFile("ddl/mysql-dbz-200.ddl"), tables);
    Testing.print(tables);
    assertThat(tables.size()).isEqualTo(1);
    assertThat(listener.total()).isEqualTo(1);
    Table t = tables.forTable(new TableId(null, null, "customfield"));
    assertThat(t).isNotNull();
    assertThat(t.columnNames()).containsExactly("ENCODEDKEY", "ID", "CREATIONDATE", "LASTMODIFIEDDATE", "DATATYPE", "ISDEFAULT", "ISREQUIRED", "NAME", "VALUES", "AMOUNTS", "DESCRIPTION", "TYPE", "VALUELENGTH", "INDEXINLIST", "CUSTOMFIELDSET_ENCODEDKEY_OID", "STATE", "VALIDATIONPATTERN", "VIEWUSAGERIGHTSKEY", "EDITUSAGERIGHTSKEY", "BUILTINCUSTOMFIELDID", "UNIQUE");
    assertColumn(t, "ENCODEDKEY", "VARCHAR", Types.VARCHAR, 32, -1, false, false, false);
    assertColumn(t, "ID", "VARCHAR", Types.VARCHAR, 32, -1, true, false, false);
    assertColumn(t, "CREATIONDATE", "DATETIME", Types.TIMESTAMP, -1, -1, true, false, false);
    assertColumn(t, "LASTMODIFIEDDATE", "DATETIME", Types.TIMESTAMP, -1, -1, true, false, false);
    assertColumn(t, "DATATYPE", "VARCHAR", Types.VARCHAR, 256, -1, true, false, false);
    assertColumn(t, "ISDEFAULT", "BIT", Types.BIT, 1, -1, true, false, false);
    assertColumn(t, "ISREQUIRED", "BIT", Types.BIT, 1, -1, true, false, false);
    assertColumn(t, "NAME", "VARCHAR", Types.VARCHAR, 256, -1, true, false, false);
    assertColumn(t, "VALUES", "MEDIUMBLOB", Types.BLOB, -1, -1, true, false, false);
    assertColumn(t, "AMOUNTS", "MEDIUMBLOB", Types.BLOB, -1, -1, true, false, false);
    assertColumn(t, "DESCRIPTION", "VARCHAR", Types.VARCHAR, 256, -1, true, false, false);
    assertColumn(t, "TYPE", "VARCHAR", Types.VARCHAR, 256, -1, true, false, false);
    assertColumn(t, "VALUELENGTH", "VARCHAR", Types.VARCHAR, 256, -1, false, false, false);
    assertColumn(t, "INDEXINLIST", "INT", Types.INTEGER, 11, -1, true, false, false);
    assertColumn(t, "CUSTOMFIELDSET_ENCODEDKEY_OID", "VARCHAR", Types.VARCHAR, 32, -1, false, false, false);
    assertColumn(t, "STATE", "VARCHAR", Types.VARCHAR, 256, -1, false, false, false);
    assertColumn(t, "VALIDATIONPATTERN", "VARCHAR", Types.VARCHAR, 256, -1, true, false, false);
    assertColumn(t, "VIEWUSAGERIGHTSKEY", "VARCHAR", Types.VARCHAR, 32, -1, true, false, false);
    assertColumn(t, "EDITUSAGERIGHTSKEY", "VARCHAR", Types.VARCHAR, 32, -1, true, false, false);
    assertColumn(t, "BUILTINCUSTOMFIELDID", "VARCHAR", Types.VARCHAR, 255, -1, true, false, false);
    assertColumn(t, "UNIQUE", "VARCHAR", Types.VARCHAR, 32, -1, false, false, false);
    assertThat(t.columnWithName("ENCODEDKEY").position()).isEqualTo(1);
    assertThat(t.columnWithName("id").position()).isEqualTo(2);
    assertThat(t.columnWithName("CREATIONDATE").position()).isEqualTo(3);
    assertThat(t.columnWithName("DATATYPE").position()).isEqualTo(5);
    assertThat(t.columnWithName("UNIQUE").position()).isEqualTo(21);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test) FixFor(io.debezium.doc.FixFor)

Aggregations

TableId (io.debezium.relational.TableId)63 Table (io.debezium.relational.Table)39 Test (org.junit.Test)34 FixFor (io.debezium.doc.FixFor)18 Column (io.debezium.relational.Column)7 TableEditor (io.debezium.relational.TableEditor)7 ArrayList (java.util.ArrayList)4 ConnectException (org.apache.kafka.connect.errors.ConnectException)4 TableSchema (io.debezium.relational.TableSchema)3 ParsingException (io.debezium.text.ParsingException)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 HashSet (java.util.HashSet)3 List (java.util.List)3 SourceRecord (org.apache.kafka.connect.source.SourceRecord)3 Predicates (io.debezium.function.Predicates)2 ColumnEditor (io.debezium.relational.ColumnEditor)2 Marker (io.debezium.text.TokenStream.Marker)2 Strings (io.debezium.util.Strings)2 Connection (java.sql.Connection)2