use of io.debezium.relational.Table in project debezium by debezium.
the class MySqlDdlParserTest method shouldParseAlterTableStatementThatAddsCharacterSetForColumns.
@Test
public void shouldParseAlterTableStatementThatAddsCharacterSetForColumns() {
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, null, true);
ddl = "ALTER TABLE t MODIFY col1 VARCHAR(50) CHARACTER SET greek;";
parser.parse(ddl, tables);
Table t2 = tables.forTable(new TableId(null, null, "t"));
assertThat(t2).isNotNull();
assertThat(t2.columnNames()).containsExactly("col1");
assertThat(t2.primaryKeyColumnNames()).isEmpty();
assertColumn(t2, "col1", "VARCHAR", Types.VARCHAR, 50, "greek", true);
ddl = "ALTER TABLE t MODIFY col1 VARCHAR(75) CHARSET utf8;";
parser.parse(ddl, tables);
Table t3 = tables.forTable(new TableId(null, null, "t"));
assertThat(t3).isNotNull();
assertThat(t3.columnNames()).containsExactly("col1");
assertThat(t3.primaryKeyColumnNames()).isEmpty();
assertColumn(t3, "col1", "VARCHAR", Types.VARCHAR, 75, "utf8", true);
}
use of io.debezium.relational.Table in project debezium by debezium.
the class MySqlDdlParserTest method shouldParseTimeWithNowDefault.
@Test
@FixFor("DBZ-169")
public void shouldParseTimeWithNowDefault() {
String ddl = "CREATE TABLE t1 ( " + "c1 int primary key auto_increment, " + "c2 datetime, " + "c3 datetime on update now(), " + "c4 char(4));";
parser.parse(ddl, tables);
assertThat(tables.size()).isEqualTo(1);
assertThat(listener.total()).isEqualTo(1);
Table t = tables.forTable(new TableId(null, null, "t1"));
assertThat(t).isNotNull();
assertThat(t.columnNames()).containsExactly("c1", "c2", "c3", "c4");
assertThat(t.primaryKeyColumnNames()).containsExactly("c1");
assertColumn(t, "c1", "INT", Types.INTEGER, -1, -1, false, true, true);
assertColumn(t, "c2", "DATETIME", Types.TIMESTAMP, -1, -1, true, false, false);
assertColumn(t, "c3", "DATETIME", Types.TIMESTAMP, -1, -1, true, false, true);
assertColumn(t, "c4", "CHAR", Types.CHAR, 4, -1, true, false, false);
assertThat(t.columnWithName("c1").position()).isEqualTo(1);
assertThat(t.columnWithName("c2").position()).isEqualTo(2);
assertThat(t.columnWithName("c3").position()).isEqualTo(3);
assertThat(t.columnWithName("c4").position()).isEqualTo(4);
}
use of io.debezium.relational.Table in project debezium by debezium.
the class MySqlDdlParserTest method shouldParseCreateTableWithTextType.
@Test
@FixFor("DBZ-428")
public void shouldParseCreateTableWithTextType() {
String ddl = "CREATE TABLE DBZ428 (" + "limtext TEXT(20), " + "unltext TEXT);";
parser.parse(ddl, tables);
assertThat(tables.size()).isEqualTo(1);
Table mytable = tables.forTable(new TableId(null, null, "DBZ428"));
assertThat(mytable).isNotNull();
assertColumn(mytable, "unltext", "TEXT", Types.VARCHAR, -1, -1, true, false, false);
assertColumn(mytable, "limtext", "TEXT", Types.VARCHAR, 20, -1, true, false, false);
}
use of io.debezium.relational.Table in project debezium by debezium.
the class MySqlDdlParser method parseAlterTable.
protected void parseAlterTable(Marker start) {
tokens.canConsume("IGNORE");
tokens.consume("TABLE");
TableId tableId = parseQualifiedTableName(start);
TableEditor table = databaseTables.editTable(tableId);
TableId oldTableId = null;
if (table != null) {
AtomicReference<TableId> newTableName = new AtomicReference<>(null);
if (!tokens.matches(terminator()) && !tokens.matches("PARTITION")) {
parseAlterSpecificationList(start, table, newTableName::set);
}
if (tokens.matches("PARTITION")) {
parsePartitionOptions(start, table);
}
databaseTables.overwriteTable(table.create());
if (newTableName.get() != null) {
// the table was renamed ...
Table renamed = databaseTables.renameTable(tableId, newTableName.get());
if (renamed != null) {
oldTableId = tableId;
tableId = renamed.id();
}
}
} else {
Marker marker = tokens.mark();
try {
// We don't know about this table but we still have to parse the statement ...
table = TableEditor.noOp(tableId);
if (!tokens.matches(terminator()) && !tokens.matches("PARTITION")) {
parseAlterSpecificationList(start, table, str -> {
});
}
if (tokens.matches("PARTITION")) {
parsePartitionOptions(start, table);
}
parseTableOptions(start, table);
// do nothing with this
} catch (ParsingException e) {
tokens.rewind(marker);
consumeRemainingStatement(start);
}
}
signalAlterTable(tableId, oldTableId, start);
}
use of io.debezium.relational.Table in project debezium by debezium.
the class MySqlSchema method refreshSchemas.
/**
* Discard any currently-cached schemas and rebuild them using the filters.
*/
protected void refreshSchemas() {
tableSchemaByTableId.clear();
// Create TableSchema instances for any existing table ...
this.tables.tableIds().forEach(id -> {
Table table = this.tables.forTable(id);
TableSchema schema = schemaBuilder.create(schemaPrefix, getEnvelopeSchemaName(table), table, filters.columnFilter(), filters.columnMappers());
tableSchemaByTableId.put(id, schema);
});
}
Aggregations