Search in sources :

Example 11 with Table

use of io.debezium.relational.Table 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 12 with Table

use of io.debezium.relational.Table 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 13 with Table

use of io.debezium.relational.Table 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 14 with Table

use of io.debezium.relational.Table 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)

Example 15 with Table

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

the class MySqlDdlParserTest method shouldParseCreateTableStatementWithMultipleColumnsForPrimaryKey.

@Test
public void shouldParseCreateTableStatementWithMultipleColumnsForPrimaryKey() {
    String ddl = "CREATE TABLE shop (" + " id BIGINT(20) NOT NULL AUTO_INCREMENT," + " version BIGINT(20) NOT NULL," + " name VARCHAR(255) NOT NULL," + " owner VARCHAR(255) NOT NULL," + " phone_number VARCHAR(255) NOT NULL," + " primary key (id, name)" + " );";
    parser.parse(ddl, tables);
    assertThat(tables.size()).isEqualTo(1);
    Table foo = tables.forTable(new TableId(null, null, "shop"));
    assertThat(foo).isNotNull();
    assertThat(foo.columnNames()).containsExactly("id", "version", "name", "owner", "phone_number");
    assertThat(foo.primaryKeyColumnNames()).containsExactly("id", "name");
    assertColumn(foo, "id", "BIGINT", Types.BIGINT, 20, -1, false, true, true);
    assertColumn(foo, "version", "BIGINT", Types.BIGINT, 20, -1, false, false, false);
    assertColumn(foo, "name", "VARCHAR", Types.VARCHAR, 255, -1, false, false, false);
    assertColumn(foo, "owner", "VARCHAR", Types.VARCHAR, 255, -1, false, false, false);
    assertColumn(foo, "phone_number", "VARCHAR", Types.VARCHAR, 255, -1, false, false, false);
    parser.parse("DROP TABLE shop", tables);
    assertThat(tables.size()).isEqualTo(0);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test)

Aggregations

Table (io.debezium.relational.Table)47 TableId (io.debezium.relational.TableId)39 Test (org.junit.Test)34 FixFor (io.debezium.doc.FixFor)17 Column (io.debezium.relational.Column)6 TableSchema (io.debezium.relational.TableSchema)4 TableEditor (io.debezium.relational.TableEditor)3 ArrayList (java.util.ArrayList)3 Predicates (io.debezium.function.Predicates)2 ParsingException (io.debezium.text.ParsingException)2 Marker (io.debezium.text.TokenStream.Marker)2 Strings (io.debezium.util.Strings)2 List (java.util.List)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 ConnectException (org.apache.kafka.connect.errors.ConnectException)2 Immutable (io.debezium.annotation.Immutable)1 Configuration (io.debezium.config.Configuration)1 RecordsForTable (io.debezium.connector.mysql.RecordMakers.RecordsForTable)1 PostgresConnection (io.debezium.connector.postgresql.connection.PostgresConnection)1 BufferedBlockingConsumer (io.debezium.function.BufferedBlockingConsumer)1