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);
}
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);
}
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);
}
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");
}
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();
}
Aggregations