Search in sources :

Example 6 with TableEditor

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

the class DdlParserSql2003 method parseCreateTable.

protected void parseCreateTable(Marker start) {
    tokens.canConsumeAnyOf("GLOBAL", "LOCAL", "TEMPORARY");
    tokens.consume("TABLE");
    TableId tableId = parseQualifiedTableName(start);
    TableEditor table = databaseTables.editOrCreateTable(tableId);
    if (tokens.matches('(')) {
        // Is either a subquery clause preceded by column name list, or table element list...
        Marker tableContentStart = tokens.mark();
        try {
            parseAsSubqueryClause(start, table);
        } catch (ParsingException e) {
            tokens.rewind(tableContentStart);
            parseTableElementList(start, table);
        }
    } else if (tokens.canConsume("OF")) {
        // Read the qualified name ...
        parseSchemaQualifiedName(start);
        if (tokens.canConsume("UNDER")) {
            // parent table name ...
            parseSchemaQualifiedName(start);
        }
        if (tokens.matches('(')) {
            parseTableElementList(start, table);
        }
    } else if (tokens.canConsume("AS")) {
        parseAsSubqueryClause(start, table);
    }
    if (tokens.canConsume("ON", "COMMIT")) {
        tokens.canConsume("PRESERVE");
        tokens.canConsume("DELETE");
        tokens.consume("ROWS");
    }
    // Update the table definition ...
    databaseTables.overwriteTable(table.create());
    signalCreateTable(tableId, start);
}
Also used : TableId(io.debezium.relational.TableId) ParsingException(io.debezium.text.ParsingException) Marker(io.debezium.text.TokenStream.Marker) TableEditor(io.debezium.relational.TableEditor)

Example 7 with TableEditor

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

the class DdlParserSql2003 method parseCreateView.

protected void parseCreateView(Marker start) {
    tokens.canConsume("RECURSIVE");
    tokens.consume("VIEW");
    TableId tableId = parseQualifiedTableName(start);
    if (skipViews) {
        // We don't care about the rest ...
        consumeRemainingStatement(start);
        signalCreateTable(tableId, start);
        debugSkipped(start);
        return;
    }
    TableEditor table = databaseTables.editOrCreateTable(tableId);
    List<String> columnNames = null;
    if (tokens.canConsume("OF")) {
        // Read the qualified name ...
        parseSchemaQualifiedName(start);
        if (tokens.canConsume("UNDER")) {
            // parent table name ...
            parseSchemaQualifiedName(start);
        }
        if (tokens.matches('(')) {
            columnNames = parseColumnNameList(start);
        }
    } else if (tokens.matches('(')) {
        columnNames = parseColumnNameList(start);
    }
    tokens.canConsume("AS");
    // We don't care about the rest ...
    consumeRemainingStatement(start);
    if (columnNames != null) {
        // We know nothing other than the names ...
        columnNames.forEach(name -> {
            table.addColumn(Column.editor().name(name).create());
        });
    }
    // Update the table definition ...
    databaseTables.overwriteTable(table.create());
    signalCreateView(tableId, start);
}
Also used : TableId(io.debezium.relational.TableId) TableEditor(io.debezium.relational.TableEditor)

Aggregations

TableEditor (io.debezium.relational.TableEditor)7 TableId (io.debezium.relational.TableId)7 Column (io.debezium.relational.Column)3 Table (io.debezium.relational.Table)3 ParsingException (io.debezium.text.ParsingException)2 Marker (io.debezium.text.TokenStream.Marker)2 ColumnEditor (io.debezium.relational.ColumnEditor)1 ArrayList (java.util.ArrayList)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1