Search in sources :

Example 41 with TableId

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

the class MySqlDdlParserTest method shouldParseCreateTableStatementWithColumnNamedColumn.

@Test
@FixFor("DBZ-408")
public void shouldParseCreateTableStatementWithColumnNamedColumn() {
    String ddl = "CREATE TABLE `mytable` ( " + System.lineSeparator() + " `def` int(11) unsigned NOT NULL AUTO_INCREMENT, " + System.lineSeparator() + " `ghi` varchar(255) NOT NULL DEFAULT '', " + System.lineSeparator() + " `column` varchar(255) NOT NULL DEFAULT '', " + System.lineSeparator() + " PRIMARY KEY (`def`) " + System.lineSeparator() + " ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
    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);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test) FixFor(io.debezium.doc.FixFor)

Example 42 with TableId

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

the class MySqlDdlParserTest method shouldParseCreateTableWithUnnamedPrimaryKeyConstraint.

@FixFor("DBZ-419")
@Test
public void shouldParseCreateTableWithUnnamedPrimaryKeyConstraint() {
    final String ddl = "CREATE TABLE IF NOT EXISTS tables_exception (table_name VARCHAR(100), create_date TIMESTAMP DEFAULT NOW(), enabled INT(1), retention int(1) default 30, CONSTRAINT PRIMARY KEY (table_name));";
    parser.parse(ddl, tables);
    Testing.print(tables);
    Table t = tables.forTable(new TableId(null, null, "tables_exception"));
    assertThat(t).isNotNull();
    assertThat(t.primaryKeyColumnNames()).containsExactly("table_name");
    assertThat(tables.size()).isEqualTo(1);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test) FixFor(io.debezium.doc.FixFor)

Example 43 with TableId

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

the class MySqlDdlParserTest method shouldParseCreateTableStatementWithCharacterSetForColumns.

@Test
public void shouldParseCreateTableStatementWithCharacterSetForColumns() {
    String ddl = "CREATE TABLE t ( col1 VARCHAR(25) CHARACTER SET greek ); ";
    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);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test)

Example 44 with TableId

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

the class MySqlDdlParserTest method shouldParseCreateUserTable.

@Test
public void shouldParseCreateUserTable() {
    String ddl = "CREATE TABLE IF NOT EXISTS user (   Host char(60) binary DEFAULT '' NOT NULL, User char(32) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Reload_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Shutdown_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Process_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, File_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tablespace_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL, ssl_cipher BLOB NOT NULL, x509_issuer BLOB NOT NULL, x509_subject BLOB NOT NULL, max_questions int(11) unsigned DEFAULT 0  NOT NULL, max_updates int(11) unsigned DEFAULT 0  NOT NULL, max_connections int(11) unsigned DEFAULT 0  NOT NULL, max_user_connections int(11) unsigned DEFAULT 0  NOT NULL, plugin char(64) DEFAULT 'mysql_native_password' NOT NULL, authentication_string TEXT, password_expired ENUM('N', 'Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, password_last_changed timestamp NULL DEFAULT NULL, password_lifetime smallint unsigned NULL DEFAULT NULL, account_locked ENUM('N', 'Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Users and global privileges';";
    parser.parse(ddl, tables);
    assertThat(tables.size()).isEqualTo(1);
    Table foo = tables.forTable(new TableId(null, null, "user"));
    assertThat(foo).isNotNull();
    assertThat(foo.columnNames()).contains("Host", "User", "Select_priv");
    assertColumn(foo, "Host", "CHAR BINARY", Types.BINARY, 60, -1, false, false, false);
    parser.parse("DROP TABLE user", tables);
    assertThat(tables.size()).isEqualTo(0);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test)

Example 45 with TableId

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

the class MySqlDdlParserTest method shouldParseCreateTableStatementWithSingleGeneratedColumnAsPrimaryKey.

@Test
public void shouldParseCreateTableStatementWithSingleGeneratedColumnAsPrimaryKey() {
    String ddl = "CREATE TABLE my.foo ( " + System.lineSeparator() + " c1 INTEGER NOT NULL AUTO_INCREMENT, " + System.lineSeparator() + " c2 VARCHAR(22), " + System.lineSeparator() + " PRIMARY KEY (c1)" + System.lineSeparator() + "); " + System.lineSeparator();
    parser.parse(ddl, tables);
    assertThat(tables.size()).isEqualTo(1);
    Table foo = tables.forTable(new TableId("my", null, "foo"));
    assertThat(foo).isNotNull();
    assertThat(foo.columnNames()).containsExactly("c1", "c2");
    assertThat(foo.primaryKeyColumnNames()).containsExactly("c1");
    assertColumn(foo, "c1", "INTEGER", Types.INTEGER, -1, -1, false, true, true);
    assertColumn(foo, "c2", "VARCHAR", Types.VARCHAR, 22, -1, true, false, false);
    parser.parse("DROP TABLE my.foo", tables);
    assertThat(tables.size()).isEqualTo(0);
}
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