Search in sources :

Example 46 with TableId

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

the class MySqlDdlParserTest method shouldParseCreateTableWithEnumDefault.

@FixFor("DBZ-160")
@Test
public void shouldParseCreateTableWithEnumDefault() {
    String ddl = "CREATE TABLE t ( c1 ENUM('a','b','c') NOT NULL DEFAULT 'b', c2 ENUM('a', 'b', 'c') NOT NULL DEFAULT 'a');";
    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", "ENUM", Types.CHAR, 1, -1, false, false, false);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test) FixFor(io.debezium.doc.FixFor)

Example 47 with TableId

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

the class MySqlDdlParserTest method parseTableWithNegativeDefault.

@Test
@FixFor("DBZ-429")
public void parseTableWithNegativeDefault() {
    String ddl = "CREATE TABLE t (id INT NOT NULL, myvalue INT DEFAULT -10, PRIMARY KEY (`id`));";
    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("id", "myvalue");
    assertThat(t.primaryKeyColumnNames()).hasSize(1);
    assertColumn(t, "myvalue", "INT", Types.INTEGER, -1, -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 48 with TableId

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

the class MySqlDdlParserTest method parseDdlForDecAndFixed.

@Test
public void parseDdlForDecAndFixed() {
    String ddl = "CREATE TABLE t ( c1 DEC(2) NOT NULL, c2 FIXED(1,0) NOT 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", "DEC", Types.DECIMAL, 2, 0, false, false, false);
    assertColumn(t, "c2", "FIXED", Types.DECIMAL, 1, 0, false, false, false);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test)

Example 49 with TableId

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

the class MySqlDdlParserTest method shouldParseCreateTableStatementWithCharacterSetForTable.

@Test
public void shouldParseCreateTableStatementWithCharacterSetForTable() {
    String ddl = "CREATE TABLE t ( col1 VARCHAR(25) ) DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; ";
    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);
    ddl = "CREATE TABLE t2 ( col1 VARCHAR(25) ) DEFAULT CHARSET utf8 DEFAULT COLLATE utf8_general_ci; ";
    parser.parse(ddl, tables);
    assertThat(tables.size()).isEqualTo(2);
    Table t2 = tables.forTable(new TableId(null, null, "t2"));
    assertThat(t2).isNotNull();
    assertThat(t2.columnNames()).containsExactly("col1");
    assertThat(t2.primaryKeyColumnNames()).isEmpty();
    assertColumn(t2, "col1", "VARCHAR", Types.VARCHAR, 25, -1, true, false, false);
    ddl = "CREATE TABLE t3 ( col1 VARCHAR(25) ) CHARACTER SET utf8 COLLATE utf8_general_ci; ";
    parser.parse(ddl, tables);
    assertThat(tables.size()).isEqualTo(3);
    Table t3 = tables.forTable(new TableId(null, null, "t3"));
    assertThat(t3).isNotNull();
    assertThat(t3.columnNames()).containsExactly("col1");
    assertThat(t3.primaryKeyColumnNames()).isEmpty();
    assertColumn(t3, "col1", "VARCHAR", Types.VARCHAR, 25, -1, true, false, false);
    ddl = "CREATE TABLE t4 ( col1 VARCHAR(25) ) CHARSET utf8 COLLATE utf8_general_ci; ";
    parser.parse(ddl, tables);
    assertThat(tables.size()).isEqualTo(4);
    Table t4 = tables.forTable(new TableId(null, null, "t4"));
    assertThat(t4).isNotNull();
    assertThat(t4.columnNames()).containsExactly("col1");
    assertThat(t4.primaryKeyColumnNames()).isEmpty();
    assertColumn(t4, "col1", "VARCHAR", Types.VARCHAR, 25, -1, true, false, false);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test)

Example 50 with TableId

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

the class MySqlDdlParserTest method parseTableWithPageChecksum.

@Test
public void parseTableWithPageChecksum() {
    String ddl = "CREATE TABLE t (id INT NOT NULL, PRIMARY KEY (`id`)) PAGE_CHECKSUM=1;" + "ALTER TABLE t PAGE_CHECKSUM=0;";
    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("id");
    assertThat(t.primaryKeyColumnNames()).hasSize(1);
    assertColumn(t, "id", "INT", Types.INTEGER, -1, -1, false, false, false);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test)

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