Search in sources :

Example 6 with ColumnEditor

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

the class DdlParserSql2003 method parseAlterTable.

protected void parseAlterTable(Marker start) {
    tokens.canConsume("IGNORE");
    tokens.consume("TABLE");
    TableId tableId = parseQualifiedTableName(start);
    TableEditor table = databaseTables.editOrCreateTable(tableId);
    if (tokens.matches("ADD", "CONSTRAINT") || tokens.matches("ADD", "UNIQUE") || tokens.matches("ADD", "PRIMARY") || tokens.matches("ADD", "FOREIGN") || tokens.matches("ADD", "CHECK")) {
        tokens.consume("ADD");
        parseTableConstraintDefinition(start, table);
    } else if (tokens.canConsume("ADD", "COLUMN") || tokens.canConsume("ADD")) {
        // Adding a column ...
        String columnName = tokens.consume();
        ColumnEditor column = Column.editor().name(columnName);
        AtomicBoolean isPrimaryKey = new AtomicBoolean(false);
        parseColumnDefinition(start, columnName, tokens, table, column, isPrimaryKey);
        // Update the table ...
        Column newColumnDefn = column.create();
        table.addColumn(newColumnDefn);
        if (isPrimaryKey.get()) {
            table.setPrimaryKeyNames(newColumnDefn.name());
        }
    } else if (tokens.canConsume("ALTER", "COLUMN") || tokens.canConsume("ALTER")) {
        // Altering a column ...
        String columnName = tokens.consume();
        Column existingColumn = table.columnWithName(columnName);
        ColumnEditor column = existingColumn != null ? existingColumn.edit() : Column.editor().name(columnName);
        parseAlterColumn(start, column);
        // Update the table ...
        Column newColumnDefn = column.create();
        table.setColumns(newColumnDefn);
    } else if (tokens.matches("DROP", "CONSTRAINT")) {
        parseDropTableConstraint(start, table);
    } else if (tokens.canConsume("DROP", "COLUMN") || tokens.canConsume("DROP")) {
        parseDropColumn(start, table);
    }
    databaseTables.overwriteTable(table.create());
    // rename is not supported
    signalAlterTable(tableId, null, start);
}
Also used : TableId(io.debezium.relational.TableId) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Column(io.debezium.relational.Column) ColumnEditor(io.debezium.relational.ColumnEditor) TableEditor(io.debezium.relational.TableEditor)

Example 7 with ColumnEditor

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

the class DdlParserSql2003 method parseTableElement.

protected void parseTableElement(Marker start, TableEditor table) {
    if (tokens.matchesAnyOf("CONSTRAINT", "UNIQUE", "PRIMARY", "FOREIGN", "CHECK")) {
        parseTableConstraintDefinition(start, table);
    } else if (tokens.matches("LIKE")) {
        parseTableLikeClause(start, table);
    } else if (tokens.matches("REF", "IS")) {
        parseSelfReferencingColumnSpec(start, table);
    } else {
        // Obtain the column editor ...
        String columnName = tokens.consume();
        Column existingColumn = table.columnWithName(columnName);
        ColumnEditor column = existingColumn != null ? existingColumn.edit() : Column.editor().name(columnName);
        AtomicBoolean isPrimaryKey = new AtomicBoolean(false);
        if (tokens.matches("WITH", "OPTIONS")) {
            parseColumnOptions(start, columnName, tokens, column);
        } else {
            parseColumnDefinition(start, columnName, tokens, table, column, isPrimaryKey);
        }
        // Update the table ...
        Column newColumnDefn = column.create();
        table.addColumns(newColumnDefn);
        if (isPrimaryKey.get()) {
            table.setPrimaryKeyNames(newColumnDefn.name());
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Column(io.debezium.relational.Column) ColumnEditor(io.debezium.relational.ColumnEditor)

Aggregations

ColumnEditor (io.debezium.relational.ColumnEditor)7 Column (io.debezium.relational.Column)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 TableId (io.debezium.relational.TableId)2 TableEditor (io.debezium.relational.TableEditor)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1