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);
}
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());
}
}
}
Aggregations