Search in sources :

Example 6 with Table

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

the class MySqlDdlParserTest method shouldParseAlterTableThatChangesMultipleColumns.

@FixFor("DBZ-204")
@Test
public void shouldParseAlterTableThatChangesMultipleColumns() {
    String ddl = "CREATE TABLE `s`.`test` (a INT(11) NULL, b INT NULL, c INT NULL, INDEX i1(b));";
    parser.parse(ddl, tables);
    assertThat(tables.size()).isEqualTo(1);
    Table t = tables.forTable(new TableId(null, "s", "test"));
    assertThat(t).isNotNull();
    assertThat(t.columnNames()).containsExactly("a", "b", "c");
    assertThat(t.primaryKeyColumnNames()).isEmpty();
    assertColumn(t, "a", "INT", Types.INTEGER, 11, -1, true, false, false);
    assertColumn(t, "b", "INT", Types.INTEGER, -1, -1, true, false, false);
    assertColumn(t, "c", "INT", Types.INTEGER, -1, -1, true, false, false);
    ddl = "ALTER TABLE `s`.`test` CHANGE COLUMN `a` `d` BIGINT(20) NOT NULL AUTO_INCREMENT";
    parser.parse(ddl, tables);
    assertThat(tables.size()).isEqualTo(1);
    t = tables.forTable(new TableId(null, "s", "test"));
    assertThat(t).isNotNull();
    assertThat(t.columnNames()).containsExactly("d", "b", "c");
    assertThat(t.primaryKeyColumnNames()).isEmpty();
    assertColumn(t, "d", "BIGINT", Types.BIGINT, 20, -1, false, true, true);
    assertColumn(t, "b", "INT", Types.INTEGER, -1, -1, true, false, false);
    assertColumn(t, "c", "INT", Types.INTEGER, -1, -1, true, false, false);
    ddl = "ALTER TABLE `s`.`test` DROP INDEX i1";
    parser.parse(ddl, tables);
    assertThat(tables.size()).isEqualTo(1);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test) FixFor(io.debezium.doc.FixFor)

Example 7 with Table

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

the class MySqlDdlParserTest method shouldParseCreateTableStatementWithSingleGeneratedAndPrimaryKeyColumn.

@Test
public void shouldParseCreateTableStatementWithSingleGeneratedAndPrimaryKeyColumn() {
    String ddl = "CREATE TABLE foo ( " + System.lineSeparator() + " c1 INTEGER NOT NULL AUTO_INCREMENT, " + System.lineSeparator() + " c2 VARCHAR(22) " + System.lineSeparator() + "); " + System.lineSeparator();
    parser.parse(ddl, tables);
    assertThat(tables.size()).isEqualTo(1);
    Table foo = tables.forTable(new TableId(null, null, "foo"));
    assertThat(foo).isNotNull();
    assertThat(foo.columnNames()).containsExactly("c1", "c2");
    assertThat(foo.primaryKeyColumnNames()).isEmpty();
    assertColumn(foo, "c1", "INTEGER", Types.INTEGER, -1, -1, false, true, true);
    assertColumn(foo, "c2", "VARCHAR", Types.VARCHAR, 22, -1, true, false, false);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test)

Example 8 with Table

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

the class MySqlDdlParserTest method shouldParseAlterTableStatementWithColumnNamedColumnWithoutColumnWord.

@Test
@FixFor({ "DBZ-408", "DBZ-412" })
public void shouldParseAlterTableStatementWithColumnNamedColumnWithoutColumnWord() {
    String ddl = "CREATE TABLE `mytable` ( " + System.lineSeparator() + " `def` int(11) unsigned NOT NULL AUTO_INCREMENT, " + System.lineSeparator() + " PRIMARY KEY (`def`) " + System.lineSeparator() + " ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
    parser.parse(ddl, tables);
    ddl = "ALTER TABLE `mytable` " + "ADD `column` varchar(255) NOT NULL DEFAULT '', " + "ADD `ghi` varchar(255) NOT NULL DEFAULT '', " + "ADD jkl varchar(255) NOT NULL DEFAULT '' ;";
    parser.parse(ddl, tables);
    assertThat(tables.size()).isEqualTo(1);
    Table mytable = tables.forTable(new TableId(null, null, "mytable"));
    assertThat(mytable).isNotNull();
    assertColumn(mytable, "column", "VARCHAR", Types.VARCHAR, 255, -1, false, false, false);
    assertColumn(mytable, "ghi", "VARCHAR", Types.VARCHAR, 255, -1, false, false, false);
    assertColumn(mytable, "jkl", "VARCHAR", Types.VARCHAR, 255, -1, false, false, false);
    ddl = "ALTER TABLE `mytable` " + "MODIFY `column` varchar(1023) NOT NULL DEFAULT '';";
    parser.parse(ddl, tables);
    ddl = "ALTER TABLE `mytable` " + "ALTER `column` DROP DEFAULT;";
    parser.parse(ddl, tables);
    ddl = "ALTER TABLE `mytable` " + "CHANGE `column` newcol varchar(1023) NOT NULL DEFAULT '';";
    parser.parse(ddl, tables);
    ddl = "ALTER TABLE `mytable` " + "CHANGE newcol `column` varchar(255) NOT NULL DEFAULT '';";
    parser.parse(ddl, tables);
    assertThat(tables.size()).isEqualTo(1);
    mytable = tables.forTable(new TableId(null, null, "mytable"));
    assertThat(mytable).isNotNull();
    assertColumn(mytable, "column", "VARCHAR", Types.VARCHAR, 255, -1, false, false, false);
    assertColumn(mytable, "ghi", "VARCHAR", Types.VARCHAR, 255, -1, false, false, false);
    assertColumn(mytable, "jkl", "VARCHAR", Types.VARCHAR, 255, -1, false, false, false);
    ddl = "ALTER TABLE `mytable` " + "DROP `column`, " + "DROP `ghi`, " + "DROP jkl";
    parser.parse(ddl, tables);
    mytable = tables.forTable(new TableId(null, null, "mytable"));
    List<String> mytableColumnNames = mytable.columns().stream().map(Column::name).collect(Collectors.toList());
    assertThat(mytableColumnNames).containsOnly("def");
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test) FixFor(io.debezium.doc.FixFor)

Example 9 with Table

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

the class MySqlDdlParserTest method shouldParseFulltextKeyInCreateTable.

@FixFor("DBZ-193")
@Test
public void shouldParseFulltextKeyInCreateTable() {
    parser.parse(readFile("ddl/mysql-dbz-193.ddl"), tables);
    Testing.print(tables);
    // 1 table
    assertThat(tables.size()).isEqualTo(1);
    assertThat(listener.total()).isEqualTo(1);
    listener.forEach(this::printEvent);
    Table t = tables.forTable(new TableId(null, null, "roles"));
    assertThat(t).isNotNull();
    assertThat(t.columnNames()).containsExactly("id", "name", "context", "organization_id", "client_id", "scope_action_ids");
    assertThat(t.primaryKeyColumnNames()).containsExactly("id");
    assertColumn(t, "id", "VARCHAR", Types.VARCHAR, 32, -1, false, false, false);
    assertColumn(t, "name", "VARCHAR", Types.VARCHAR, 100, -1, false, false, false);
    assertColumn(t, "context", "VARCHAR", Types.VARCHAR, 20, -1, false, false, false);
    assertColumn(t, "organization_id", "INT", Types.INTEGER, 11, -1, true, false, false);
    assertColumn(t, "client_id", "VARCHAR", Types.VARCHAR, 32, -1, false, false, false);
    assertColumn(t, "scope_action_ids", "TEXT", Types.VARCHAR, -1, -1, false, false, false);
    assertThat(t.columnWithName("id").position()).isEqualTo(1);
    assertThat(t.columnWithName("name").position()).isEqualTo(2);
    assertThat(t.columnWithName("context").position()).isEqualTo(3);
    assertThat(t.columnWithName("organization_id").position()).isEqualTo(4);
    assertThat(t.columnWithName("client_id").position()).isEqualTo(5);
    assertThat(t.columnWithName("scope_action_ids").position()).isEqualTo(6);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test) FixFor(io.debezium.doc.FixFor)

Example 10 with Table

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

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