Search in sources :

Example 61 with TableId

use of io.debezium.relational.TableId 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 62 with TableId

use of io.debezium.relational.TableId 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)

Example 63 with TableId

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

the class DdlParserSql2003 method parseDropTable.

protected void parseDropTable(Marker start) {
    tokens.canConsume("TEMPORARY");
    tokens.consume("TABLE");
    tokens.canConsume("IF", "EXISTS");
    TableId tableId = parseQualifiedTableName(start);
    databaseTables.removeTable(tableId);
    // ignore the rest ...
    consumeRemainingStatement(start);
    signalDropTable(tableId, start);
}
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