Search in sources :

Example 1 with TableSchema

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

the class PostgresSchemaIT method assertTablesIncluded.

protected void assertTablesIncluded(String... fullyQualifiedTableNames) {
    Arrays.stream(fullyQualifiedTableNames).forEach(fullyQualifiedTableName -> {
        TableSchema tableSchema = schemaFor(fullyQualifiedTableName);
        assertNotNull(fullyQualifiedTableName + " not included", tableSchema);
        assertThat(tableSchema.keySchema().name()).isEqualTo(validFullName(fullyQualifiedTableName, ".Key"));
        assertThat(tableSchema.valueSchema().name()).isEqualTo(validFullName(fullyQualifiedTableName, ".Value"));
    });
}
Also used : TableSchema(io.debezium.relational.TableSchema)

Example 2 with TableSchema

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

the class PostgresSchemaIT method assertTableSchema.

protected void assertTableSchema(String fullyQualifiedTableName, String fields, Schema... types) {
    TableSchema tableSchema = schemaFor(fullyQualifiedTableName);
    Schema keySchema = tableSchema.valueSchema();
    assertSchemaContent(fields.split(","), types, keySchema);
}
Also used : TableSchema(io.debezium.relational.TableSchema) Schema(org.apache.kafka.connect.data.Schema) TableSchema(io.debezium.relational.TableSchema)

Example 3 with TableSchema

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

the class PostgresSchemaIT method shouldLoadSchemaForBuiltinPostgresTypes.

@Test
public void shouldLoadSchemaForBuiltinPostgresTypes() throws Exception {
    TestHelper.executeDDL("postgres_create_tables.ddl");
    PostgresConnectorConfig config = new PostgresConnectorConfig(TestHelper.defaultConfig().build());
    schema = new PostgresSchema(config, TestHelper.getTypeRegistry(), TopicSelector.create(config));
    try (PostgresConnection connection = TestHelper.create()) {
        schema.refresh(connection, false);
        assertTablesIncluded(TEST_TABLES);
        Arrays.stream(TEST_TABLES).forEach(tableId -> assertKeySchema(tableId, "pk", Schema.INT32_SCHEMA));
        assertTableSchema("public.numeric_table", "si, i, bi, r, db, ss, bs, b", Schema.OPTIONAL_INT16_SCHEMA, Schema.OPTIONAL_INT32_SCHEMA, Schema.OPTIONAL_INT64_SCHEMA, Schema.OPTIONAL_FLOAT32_SCHEMA, Schema.OPTIONAL_FLOAT64_SCHEMA, Schema.INT16_SCHEMA, Schema.INT64_SCHEMA, Schema.OPTIONAL_BOOLEAN_SCHEMA);
        assertTableSchema("public.numeric_decimal_table", "d, dzs, dvs, n, nzs, nvs", Decimal.builder(2).optional().build(), Decimal.builder(0).optional().build(), VariableScaleDecimal.builder().optional().build(), Decimal.builder(4).optional().build(), Decimal.builder(0).optional().build(), VariableScaleDecimal.builder().optional().build());
        assertTableSchema("public.string_table", "vc, vcv, ch, c, t", Schema.OPTIONAL_STRING_SCHEMA, Schema.OPTIONAL_STRING_SCHEMA, Schema.OPTIONAL_STRING_SCHEMA, Schema.OPTIONAL_STRING_SCHEMA, Schema.OPTIONAL_STRING_SCHEMA);
        assertTableSchema("public.cash_table", "csh", Decimal.builder(0).optional().build());
        assertTableSchema("public.bitbin_table", "ba, bol, bs, bv", Schema.OPTIONAL_BYTES_SCHEMA, Schema.OPTIONAL_BOOLEAN_SCHEMA, Bits.builder(2).optional().build(), Bits.builder(2).optional().build());
        assertTableSchema("public.time_table", "ts, tz, date, ti, ttz, it", NanoTimestamp.builder().optional().build(), ZonedTimestamp.builder().optional().build(), Date.builder().optional().build(), NanoTime.builder().optional().build(), ZonedTime.builder().optional().build(), MicroDuration.builder().optional().build());
        assertTableSchema("public.text_table", "j, jb, x, u", Json.builder().optional().build(), Json.builder().optional().build(), Xml.builder().optional().build(), Uuid.builder().optional().build());
        assertTableSchema("public.geom_table", "p", Point.builder().optional().build());
        assertTableSchema("public.tstzrange_table", "unbounded_exclusive_range, bounded_inclusive_range", Schema.OPTIONAL_STRING_SCHEMA, Schema.OPTIONAL_STRING_SCHEMA);
        assertTableSchema("public.array_table", "int_array, bigint_array, text_array", SchemaBuilder.array(Schema.OPTIONAL_INT32_SCHEMA).optional().build(), SchemaBuilder.array(Schema.OPTIONAL_INT64_SCHEMA).optional().build(), SchemaBuilder.array(Schema.OPTIONAL_STRING_SCHEMA).optional().build());
        assertTableSchema("\"Quoted_\"\" . Schema\".\"Quoted_\"\" . Table\"", "\"Quoted_\"\" . Text_Column\"", Schema.OPTIONAL_STRING_SCHEMA);
        TableSchema tableSchema = schemaFor("public.custom_table");
        assertThat(tableSchema.valueSchema().field("lt")).isNull();
    }
}
Also used : TableSchema(io.debezium.relational.TableSchema) PostgresConnection(io.debezium.connector.postgresql.connection.PostgresConnection) Test(org.junit.Test)

Example 4 with TableSchema

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

the class PostgresSchemaIT method assertKeySchema.

protected void assertKeySchema(String fullyQualifiedTableName, String fields, Schema... types) {
    TableSchema tableSchema = schemaFor(fullyQualifiedTableName);
    Schema keySchema = tableSchema.keySchema();
    assertSchemaContent(fields.split(","), types, keySchema);
}
Also used : TableSchema(io.debezium.relational.TableSchema) Schema(org.apache.kafka.connect.data.Schema) TableSchema(io.debezium.relational.TableSchema)

Example 5 with TableSchema

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

the class MySqlSchemaTest method assertHistoryRecorded.

protected void assertHistoryRecorded() {
    MySqlSchema duplicate = build.storeDatabaseHistoryInFile(TEST_FILE_PATH).createSchemas();
    duplicate.loadHistory(source);
    // Make sure table is defined in each ...
    assertThat(duplicate.tables()).isEqualTo(mysql.tables());
    for (int i = 0; i != 2; ++i) {
        duplicate.tables().tableIds().forEach(tableId -> {
            TableSchema dupSchema = duplicate.schemaFor(tableId);
            TableSchema schema = mysql.schemaFor(tableId);
            assertThat(schema).isEqualTo(dupSchema);
            Table dupTable = duplicate.tables().forTable(tableId);
            Table table = mysql.tables().forTable(tableId);
            assertThat(table).isEqualTo(dupTable);
        });
        mysql.tables().tableIds().forEach(tableId -> {
            TableSchema dupSchema = duplicate.schemaFor(tableId);
            TableSchema schema = mysql.schemaFor(tableId);
            assertThat(schema).isEqualTo(dupSchema);
            Table dupTable = duplicate.tables().forTable(tableId);
            Table table = mysql.tables().forTable(tableId);
            assertThat(table).isEqualTo(dupTable);
        });
        duplicate.refreshSchemas();
    }
}
Also used : Table(io.debezium.relational.Table) TableSchema(io.debezium.relational.TableSchema)

Aggregations

TableSchema (io.debezium.relational.TableSchema)17 Schema (org.apache.kafka.connect.data.Schema)8 Envelope (io.debezium.data.Envelope)5 Struct (org.apache.kafka.connect.data.Struct)5 SourceRecord (org.apache.kafka.connect.source.SourceRecord)5 Table (io.debezium.relational.Table)4 TableId (io.debezium.relational.TableId)3 PostgresConnection (io.debezium.connector.postgresql.connection.PostgresConnection)2 ReplicationMessage (io.debezium.connector.postgresql.connection.ReplicationMessage)1 Point (io.debezium.data.geometry.Point)1 BlockingConsumer (io.debezium.function.BlockingConsumer)1 ParsingException (io.debezium.text.ParsingException)1 BitSet (java.util.BitSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ConnectException (org.apache.kafka.connect.errors.ConnectException)1 Test (org.junit.Test)1