Search in sources :

Example 51 with TableId

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

the class MySqlDdlParserTest method shouldParseCreateTableStatementWithSignedTypes.

@Test
public void shouldParseCreateTableStatementWithSignedTypes() {
    String ddl = "CREATE TABLE foo ( " + System.lineSeparator() + " c1 BIGINT SIGNED NOT NULL, " + System.lineSeparator() + " c2 INT UNSIGNED NOT NULL " + 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", "BIGINT SIGNED", Types.BIGINT, -1, -1, false, false, false);
    assertColumn(foo, "c2", "INT UNSIGNED", Types.INTEGER, -1, -1, false, false, false);
}
Also used : TableId(io.debezium.relational.TableId) Table(io.debezium.relational.Table) Test(org.junit.Test)

Example 52 with TableId

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

the class FiltersTest method assertTableIncluded.

protected void assertTableIncluded(String fullyQualifiedTableName) {
    TableId id = TableId.parse(fullyQualifiedTableName);
    assertThat(filters.tableFilter().test(id)).isTrue();
}
Also used : TableId(io.debezium.relational.TableId)

Example 53 with TableId

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

the class FiltersTest method assertTableExcluded.

protected void assertTableExcluded(String fullyQualifiedTableName) {
    TableId id = TableId.parse(fullyQualifiedTableName);
    assertThat(filters.tableFilter().test(id)).isFalse();
}
Also used : TableId(io.debezium.relational.TableId)

Example 54 with TableId

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

the class MySqlDdlParser method parseAlterSpecification.

protected void parseAlterSpecification(Marker start, TableEditor table, Consumer<TableId> newTableName) {
    parseTableOptions(start, table);
    if (tokens.canConsume("ADD")) {
        if (tokens.matches("COLUMN", "(") || tokens.matches('(')) {
            tokens.canConsume("COLUMN");
            parseCreateDefinitionList(start, table);
        } else if (tokens.canConsume("PARTITION", "(")) {
            parsePartitionDefinition(start, table);
            tokens.consume(')');
        } else {
            parseCreateDefinition(start, table, true);
        }
    } else if (tokens.canConsume("DROP")) {
        if (tokens.canConsume("PRIMARY", "KEY")) {
            table.setPrimaryKeyNames();
        } else if (tokens.canConsume("FOREIGN", "KEY")) {
            // foreign key symbol
            tokens.consume();
        } else if (tokens.canConsumeAnyOf("INDEX", "KEY")) {
            // index name
            tokens.consume();
        } else if (tokens.canConsume("PARTITION")) {
            parsePartitionNames(start);
        } else {
            if (!isNextTokenQuotedIdentifier()) {
                tokens.canConsume("COLUMN");
            }
            String columnName = parseColumnName();
            table.removeColumn(columnName);
            tokens.canConsume("RESTRICT");
        }
    } else if (tokens.canConsume("ALTER")) {
        if (!isNextTokenQuotedIdentifier()) {
            tokens.canConsume("COLUMN");
        }
        // column name
        tokens.consume();
        if (!tokens.canConsume("DROP", "DEFAULT")) {
            tokens.consume("SET");
            parseDefaultClause(start);
        }
    } else if (tokens.canConsume("CHANGE")) {
        if (!isNextTokenQuotedIdentifier()) {
            tokens.canConsume("COLUMN");
        }
        String oldName = parseColumnName();
        String newName = parseColumnName();
        parseCreateColumn(start, table, oldName, newName);
    } else if (tokens.canConsume("MODIFY")) {
        if (!isNextTokenQuotedIdentifier()) {
            tokens.canConsume("COLUMN");
        }
        String columnName = parseColumnName();
        parseCreateColumn(start, table, columnName, null);
    } else if (tokens.canConsumeAnyOf("ALGORITHM", "LOCK")) {
        tokens.canConsume('=');
        tokens.consume();
    } else if (tokens.canConsume("DISABLE", "KEYS") || tokens.canConsume("ENABLE", "KEYS")) {
    } else if (tokens.canConsume("RENAME", "INDEX") || tokens.canConsume("RENAME", "KEY")) {
        // old
        tokens.consume();
        tokens.consume("TO");
        // new
        tokens.consume();
    } else if (tokens.canConsume("RENAME")) {
        tokens.canConsumeAnyOf("AS", "TO");
        TableId newTableId = parseQualifiedTableName(start);
        newTableName.accept(newTableId);
    } else if (tokens.canConsume("ORDER", "BY")) {
        // this should not affect the order of the columns in the table
        consumeCommaSeparatedValueList(start);
    } else if (tokens.canConsume("CONVERT", "TO", "CHARACTER", "SET") || tokens.canConsume("CONVERT", "TO", "CHARSET")) {
        // charset name
        tokens.consume();
        if (tokens.canConsume("COLLATE")) {
            // collation name
            tokens.consume();
        }
    } else if (tokens.canConsume("CHARACTER", "SET") || tokens.canConsume("CHARSET") || tokens.canConsume("DEFAULT", "CHARACTER", "SET") || tokens.canConsume("DEFAULT", "CHARSET")) {
        tokens.canConsume('=');
        // charset name
        String charsetName = tokens.consume();
        table.setDefaultCharsetName(charsetName);
        if (tokens.canConsume("COLLATE")) {
            tokens.canConsume('=');
            // collation name (ignored)
            tokens.consume();
        }
    } else if (tokens.canConsume("DISCARD", "TABLESPACE") || tokens.canConsume("IMPORT", "TABLESPACE")) {
    // nothing
    } else if (tokens.canConsume("FORCE")) {
    // nothing
    } else if (tokens.canConsume("WITH", "VALIDATION") || tokens.canConsume("WITHOUT", "VALIDATION")) {
    // nothing
    } else if (tokens.canConsume("DISCARD", "PARTITION") || tokens.canConsume("IMPORT", "PARTITION")) {
        if (!tokens.canConsume("ALL")) {
            // partition name
            tokens.consume();
        }
        tokens.consume("TABLESPACE");
    } else if (tokens.canConsume("COALLESCE", "PARTITION")) {
        // number
        tokens.consume();
    } else if (tokens.canConsume("REORGANIZE", "PARTITION")) {
        parsePartitionNames(start);
        tokens.consume("INTO", "(");
        do {
            parsePartitionDefinition(start, table);
        } while (tokens.canConsume(','));
        tokens.consume(')');
    } else if (tokens.canConsume("EXCHANGE", "PARTITION")) {
        // partition name
        tokens.consume();
        tokens.consume("WITH", "TABLE");
        // table name
        parseSchemaQualifiedName(start);
        if (tokens.canConsumeAnyOf("WITH", "WITHOUT")) {
            tokens.consume("VALIDATION");
        }
    } else if (tokens.matches(TokenStream.ANY_VALUE, "PARTITION")) {
        tokens.consumeAnyOf("TRUNCATE", "CHECK", "ANALYZE", "OPTIMIZE", "REBUILD", "REPAIR");
        tokens.consume("PARTITION");
        if (!tokens.canConsume("ALL")) {
            parsePartitionNames(start);
        }
    } else if (tokens.canConsume("REMOVE", "PARTITIONING")) {
    // nothing
    } else if (tokens.canConsume("UPGRADE", "PARTITIONING")) {
    // nothing
    }
}
Also used : TableId(io.debezium.relational.TableId)

Example 55 with TableId

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

the class MySqlDdlParser method parseRenameTable.

protected void parseRenameTable(Marker start) {
    TableId from = parseQualifiedTableName(start);
    tokens.consume("TO");
    TableId to = parseQualifiedTableName(start);
    databaseTables.renameTable(from, to);
    // Signal a separate statement for this table rename action, even though multiple renames might be
    // performed by a single DDL statement on the token stream ...
    signalAlterTable(from, to, "RENAME TABLE " + from + " TO " + to);
}
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