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