use of io.debezium.relational.TableId in project debezium by debezium.
the class ColumnMappers method mapperFor.
/**
* Get the value mapping function for the given column.
*
* @param tableId the identifier of the table to which the column belongs; may not be null
* @param column the column; may not be null
* @return the mapping function, or null if there is no mapping function
*/
public ColumnMapper mapperFor(TableId tableId, Column column) {
ColumnId id = new ColumnId(tableId, column.name());
Optional<MapperRule> matchingRule = rules.stream().filter(rule -> rule.matches(id)).findFirst();
if (matchingRule.isPresent()) {
return matchingRule.get().mapper;
}
return null;
}
use of io.debezium.relational.TableId 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);
}
use of io.debezium.relational.TableId 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);
}
use of io.debezium.relational.TableId 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");
}
use of io.debezium.relational.TableId 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);
}
Aggregations