Search in sources :

Example 21 with TableId

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

Example 22 with TableId

use of io.debezium.relational.TableId 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);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test)

Example 23 with TableId

use of io.debezium.relational.TableId 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);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test) FixFor(io.debezium.doc.FixFor)

Example 24 with TableId

use of io.debezium.relational.TableId 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);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test) FixFor(io.debezium.doc.FixFor)

Example 25 with TableId

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

the class MySqlDdlParser method parseDropIndex.

protected void parseDropIndex(Marker start) {
    tokens.consume("INDEX");
    // index name
    String indexName = tokens.consume();
    tokens.consume("ON");
    TableId tableId = parseQualifiedTableName(start);
    consumeRemainingStatement(start);
    signalDropIndex(indexName, tableId, start);
    debugParsed(start);
}
Also used : TableId(io.debezium.relational.TableId)

Aggregations

TableId (io.debezium.relational.TableId)63 Table (io.debezium.relational.Table)39 Test (org.junit.Test)34 FixFor (io.debezium.doc.FixFor)18 Column (io.debezium.relational.Column)7 TableEditor (io.debezium.relational.TableEditor)7 ArrayList (java.util.ArrayList)4 ConnectException (org.apache.kafka.connect.errors.ConnectException)4 TableSchema (io.debezium.relational.TableSchema)3 ParsingException (io.debezium.text.ParsingException)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 HashSet (java.util.HashSet)3 List (java.util.List)3 SourceRecord (org.apache.kafka.connect.source.SourceRecord)3 Predicates (io.debezium.function.Predicates)2 ColumnEditor (io.debezium.relational.ColumnEditor)2 Marker (io.debezium.text.TokenStream.Marker)2 Strings (io.debezium.util.Strings)2 Connection (java.sql.Connection)2