Java Code Examples for io.debezium.relational.ddl.DdlParser

Following code examples demonstrate how to use io.debezium.relational.ddl.DdlParser from debezium. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use io.debezium.relational.ddl.DdlParser and various code implementation of this class.
Example 1
Project : debezium Source File : AbstractDatabaseHistory.java View Source Code on GitHub

    public final void recover(Map<String, ?> source, Map<String, ?> position, Tables schema, DdlParser ddlParser) {
        logger.debug("Recovering DDL history for source partition {} and offset {}", source, position);
        HistoryRecord stopPoint = new HistoryRecord(source, position, null, null, null, null);
        recoverRecords(recovered -> {
            if (comparator.isAtOrBefore(recovered, stopPoint)) {
                Array tableChanges = recovered.tableChanges();
                String ddl = recovered.ddl();

                if (tableChanges != null) {
                    TableChanges changes = TableChanges.fromArray(tableChanges);
                    for (TableChange entry : changes) {
                        if (entry.getType() == TableChangeType.CREATE || entry.getType() == TableChangeType.ALTER) {
                            schema.overwriteTable(entry.getTable());
                        }
                        else {
                            schema.removeTable(entry.getId());
                        }
                    }
                }
                else if (ddl != null) {
                    if (recovered.databaseName() != null) {
                    }
                    if (recovered.schemaName() != null) {
                    }
                    Optional<Pattern> filteredBy = ddlFilter.apply(ddl);
                    if (filteredBy.isPresent()) {
                        logger.info("a DDL '{}' was filtered out of processing by regular expression '{}", ddl, filteredBy.get());
                        return;
                    }
                    try {
                        logger.debug("Applying: {}", ddl);
                        ddlParser.parse(ddl, schema);
                    } catch (final ParsingException e) {
                        if (skipUnparseableDDL) {
                            logger.warn("Ignoring unparseable statements '{}' stored in database history: {}", ddl, e);
                        } else {
                            throw e;
                        }
                    }
                }
            } else {
                logger.debug("Skipping: {}", recovered.ddl());
            }
        });
    }
			
Example 2
Project : debezium Source File : DebeziumMysqlParser.java View Source Code on GitHub

    public static void main(String[] args) {

        String createDDL = "CREATE TABLE products (\n" +
                "  id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,\n" +
                "  name VARCHAR(255) NOT NULL,\n" +
                "  description numeric(12,5),\n" +
                "  weight FLOAT comment 'column',\n" +
                "  primary key(id)\n" +
                ") comment='sadfadfa'  max_row=10;";

        DdlParser parser = new MySqlDdlParser();
        Tables tables = new Tables();
        parser.parse(createDDL, tables);

        tables.tableIds();
    }
			
Example 3
Project : debezium Source File : MySqlValueConvertersTest.java View Source Code on GitHub

    public void testJsonValues() {
        String sql = "CREATE TABLE JSON_TABLE (" +
                "    A JSON," +
                "    B JSON NOT NULL" +
                ");";

        MySqlValueConverters converters = new MySqlValueConverters(JdbcValueConverters.DecimalMode.DOUBLE,
            TemporalPrecisionMode.CONNECT,
            JdbcValueConverters.BigIntUnsignedMode.LONG);

        DdlParser parser = new MySqlAntlrDdlParser();
        Tables tables = new Tables();
        parser.parse(sql, tables);
        Table table = tables.forTable(new TableId(null, null, "JSON_TABLE"));

        Column colA= table.columnWithName("A");
        Field fieldA = new Field(colA.name(), -1, converters.schemaBuilder(colA).optional().build());
        assertThat(converters.converter(colA, fieldA).convert("{}")).isEqualTo("{}");
        assertThat(converters.converter(colA, fieldA).convert("[]")).isEqualTo("[]");
        assertThat(converters.converter(colA, fieldA).convert(new byte[0])).isNull();
        assertThat(converters.converter(colA, fieldA).convert(null)).isNull();
        assertThat(converters.converter(colA, fieldA).convert("{ \"key1\": \"val1\", \"key2\": {\"key3\":\"val3\"} }")).isEqualTo("{ \"key1\": \"val1\", \"key2\": {\"key3\":\"val3\"} }");

        Column colB= table.columnWithName("B");
        Field fieldB = new Field(colB.name(), -1, converters.schemaBuilder(colB).build());
        assertThat(converters.converter(colB, fieldB).convert("{}")).isEqualTo("{}");
        assertThat(converters.converter(colB, fieldB).convert("[]")).isEqualTo("[]");
        assertThat(converters.converter(colB, fieldB).convert(new byte[0])).isEqualTo("{}");
        assertThat(converters.converter(colB, fieldB).convert(null)).isEqualTo("{}");
        assertThat(converters.converter(colB, fieldB).convert("{ \"key1\": \"val1\", \"key2\": {\"key3\":\"val3\"} }")).isEqualTo("{ \"key1\": \"val1\", \"key2\": {\"key3\":\"val3\"} }");
    }