Search in sources :

Example 16 with Table

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

the class MySqlDdlParserTest method shouldParseCreateTableWithEnumAndSetColumns.

@Test
public void shouldParseCreateTableWithEnumAndSetColumns() {
    String ddl = "CREATE TABLE t ( c1 ENUM('a','b','c') NOT NULL, c2 SET('a','b','c') 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", "ENUM", Types.CHAR, 1, -1, false, false, false);
    assertColumn(t, "c2", "SET", Types.CHAR, 5, -1, true, false, false);
    assertThat(t.columnWithName("c1").position()).isEqualTo(1);
    assertThat(t.columnWithName("c2").position()).isEqualTo(2);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test)

Example 17 with Table

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

the class MySqlDdlParserTest method shouldParseStatementForDbz142.

@Test
public void shouldParseStatementForDbz142() {
    parser.parse(readFile("ddl/mysql-dbz-142.ddl"), tables);
    Testing.print(tables);
    assertThat(tables.size()).isEqualTo(2);
    assertThat(listener.total()).isEqualTo(2);
    Table t = tables.forTable(new TableId(null, null, "nvarchars"));
    assertColumn(t, "c1", "NVARCHAR", Types.NVARCHAR, 255, "utf8", true);
    assertColumn(t, "c2", "NATIONAL VARCHAR", Types.NVARCHAR, 255, "utf8", true);
    assertColumn(t, "c3", "NCHAR VARCHAR", Types.NVARCHAR, 255, "utf8", true);
    assertColumn(t, "c4", "NATIONAL CHARACTER VARYING", Types.NVARCHAR, 255, "utf8", true);
    assertColumn(t, "c5", "NATIONAL CHAR VARYING", Types.NVARCHAR, 255, "utf8", true);
    Table t2 = tables.forTable(new TableId(null, null, "nchars"));
    assertColumn(t2, "c1", "NATIONAL CHARACTER", Types.NCHAR, 10, "utf8", true);
    assertColumn(t2, "c2", "NCHAR", Types.NCHAR, 10, "utf8", true);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test)

Example 18 with Table

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

the class MySqlDdlParserTest method shouldParseAlterTableStatementAddColumns.

@Test
public void shouldParseAlterTableStatementAddColumns() {
    String ddl = "CREATE TABLE t ( col1 VARCHAR(25) ); ";
    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("col1");
    assertThat(t.primaryKeyColumnNames()).isEmpty();
    assertColumn(t, "col1", "VARCHAR", Types.VARCHAR, 25, -1, true, false, false);
    assertThat(t.columnWithName("col1").position()).isEqualTo(1);
    ddl = "ALTER TABLE t ADD col2 VARCHAR(50) NOT NULL;";
    parser.parse(ddl, tables);
    Table t2 = tables.forTable(new TableId(null, null, "t"));
    assertThat(t2).isNotNull();
    assertThat(t2.columnNames()).containsExactly("col1", "col2");
    assertThat(t2.primaryKeyColumnNames()).isEmpty();
    assertColumn(t2, "col1", "VARCHAR", Types.VARCHAR, 25, -1, true, false, false);
    assertColumn(t2, "col2", "VARCHAR", Types.VARCHAR, 50, -1, false, false, false);
    assertThat(t2.columnWithName("col1").position()).isEqualTo(1);
    assertThat(t2.columnWithName("col2").position()).isEqualTo(2);
    ddl = "ALTER TABLE t ADD col3 FLOAT NOT NULL AFTER col1;";
    parser.parse(ddl, tables);
    Table t3 = tables.forTable(new TableId(null, null, "t"));
    assertThat(t3).isNotNull();
    assertThat(t3.columnNames()).containsExactly("col1", "col3", "col2");
    assertThat(t3.primaryKeyColumnNames()).isEmpty();
    assertColumn(t3, "col1", "VARCHAR", Types.VARCHAR, 25, -1, true, false, false);
    assertColumn(t3, "col3", "FLOAT", Types.FLOAT, -1, -1, false, false, false);
    assertColumn(t3, "col2", "VARCHAR", Types.VARCHAR, 50, -1, false, false, false);
    assertThat(t3.columnWithName("col1").position()).isEqualTo(1);
    assertThat(t3.columnWithName("col3").position()).isEqualTo(2);
    assertThat(t3.columnWithName("col2").position()).isEqualTo(3);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test)

Example 19 with Table

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

the class MySqlDdlParserTest method shouldParseAlterTableStatementWithColumnNamedColumnWithColumnWord.

@Test
@FixFor({ "DBZ-408", "DBZ-412", "DBZ-524" })
public void shouldParseAlterTableStatementWithColumnNamedColumnWithColumnWord() {
    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 `column` varchar(255) NOT NULL DEFAULT '', " + "ADD COLUMN `ghi` varchar(255) NOT NULL DEFAULT '', " + "ADD COLUMN 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 `column` varchar(1023) NOT NULL DEFAULT '';";
    parser.parse(ddl, tables);
    ddl = "ALTER TABLE `mytable` " + "ALTER COLUMN `column` DROP DEFAULT;";
    parser.parse(ddl, tables);
    ddl = "ALTER TABLE `mytable` " + "CHANGE COLUMN `column` newcol varchar(1023) NOT NULL DEFAULT '';";
    parser.parse(ddl, tables);
    ddl = "ALTER TABLE `mytable` " + "CHANGE COLUMN 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 `column`, " + "DROP COLUMN `ghi`, " + "DROP COLUMN jkl RESTRICT";
    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 20 with Table

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

the class MySqlDdlParserTest method shouldParseCreateTableStatementWithCollate.

@Test
@FixFor("DBZ-474")
public void shouldParseCreateTableStatementWithCollate() {
    String ddl = "CREATE TABLE c1 (pk INT PRIMARY KEY, v1 CHAR(36) NOT NULL COLLATE utf8_unicode_ci);";
    parser.parse(ddl, tables);
    assertThat(tables.size()).isEqualTo(1);
    Table table = tables.forTable(new TableId(null, null, "c1"));
    assertThat(table).isNotNull();
    assertColumn(table, "v1", "CHAR", Types.CHAR, 36, -1, false, false, false);
    Column column = table.columnWithName("v1");
    assertThat(column.typeUsesCharset()).isTrue();
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Column(io.debezium.relational.Column) 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