/** * Create a stateful Avro fullname adjuster that calls the supplied {@link ReplacementOccurred} function when an invalid * fullname is seen and replaced with a valid fullname. This method replaces all invalid characters with the underscore * character ('_'). * * @param uponReplacement the function called each time the original fullname is replaced; may be null * @return the adjuster; never null */ public static SchemaNameAdjuster create(ReplacementOccurred uponReplacement) { return create("_", uponReplacement); }
/** * Create a stateful Avro fullname adjuster that logs a warning the first time an invalid fullname is seen and replaced * with a valid fullname, and throws an error if the replacement conflicts with that of a different original. This method * replaces all invalid characters with the underscore character ('_'). * * @param logger the logger to use; may not be null * @return the validator; never null */ public static SchemaNameAdjuster create(Logger logger) { return create(logger, (original, replacement, conflict) -> { String msg = "The Kafka Connect schema name '" + original + "' is not a valid Avro schema name and its replacement '" + replacement + "' conflicts with another different schema '" + conflict + "'"; throw new ConnectException(msg); }); }
/** * Create a stateful Avro fullname adjuster that logs a warning the first time an invalid fullname is seen and replaced * with a valid fullname. This method replaces all invalid characters with the underscore character ('_'). * * @param logger the logger to use; may not be null * @param uponConflict the function to be called when there is a conflict and after that conflict is logged; may be null * @return the validator; never null */ public static SchemaNameAdjuster create(Logger logger, ReplacementOccurred uponConflict) { ReplacementOccurred handler = (original, replacement, conflictsWith) -> { if (conflictsWith != null) { logger.error("The Kafka Connect schema name '{}' is not a valid Avro schema name and its replacement '{}' conflicts with another different schema '{}'", original, replacement, conflictsWith); if (uponConflict != null) { uponConflict.accept(original, replacement, conflictsWith); } } else { logger.warn("The Kafka Connect schema name '{}' is not a valid Avro schema name, so replacing with '{}'", original, replacement); } }; return create(handler.firstTimeOnly()); }
private static TableSchemaBuilder getTableSchemaBuilder(PostgresConnectorConfig config, TypeRegistry typeRegistry, Charset databaseCharset) { PostgresValueConverter valueConverter = new PostgresValueConverter(databaseCharset, config.getDecimalMode(), config.temporalPrecisionMode(), ZoneOffset.UTC, null, config.includeUnknownDatatypes(), typeRegistry, config.hStoreHandlingMode()); return new TableSchemaBuilder(valueConverter, SchemaNameAdjuster.create(LOGGER), SourceInfo.SCHEMA); }
@Test public void shouldReportReplacementEveryTime() { AtomicInteger counter = new AtomicInteger(); AtomicInteger conflicts = new AtomicInteger(); ReplacementOccurred handler = (original, replacement, conflict) -> { if (conflict != null) conflicts.incrementAndGet(); counter.incrementAndGet(); }; SchemaNameAdjuster adjuster = SchemaNameAdjuster.create(handler); for (int i = 0; i != 20; ++i) { adjuster.adjust("some-invalid-fullname$"); } assertThat(counter.get()).isEqualTo(20); assertThat(conflicts.get()).isEqualTo(0); }
@Test public void shouldReportReplacementOnlyOnce() { AtomicInteger counter = new AtomicInteger(); AtomicInteger conflicts = new AtomicInteger(); ReplacementOccurred handler = (original, replacement, conflict) -> { if (conflict != null) conflicts.incrementAndGet(); counter.incrementAndGet(); }; SchemaNameAdjuster adjuster = SchemaNameAdjuster.create(handler.firstTimeOnly()); for (int i = 0; i != 20; ++i) { adjuster.adjust("some-invalid-fullname$"); } assertThat(counter.get()).isEqualTo(1); assertThat(conflicts.get()).isEqualTo(0); }
@Test public void shouldReportConflictReplacement() { AtomicInteger counter = new AtomicInteger(); AtomicInteger conflicts = new AtomicInteger(); ReplacementOccurred handler = (original, replacement, conflict) -> { if (conflict != null) conflicts.incrementAndGet(); counter.incrementAndGet(); }; SchemaNameAdjuster adjuster = SchemaNameAdjuster.create(handler.firstTimeOnly()); adjuster.adjust("some-invalid-fullname$"); adjuster.adjust("some-invalid%fullname_"); assertThat(counter.get()).isEqualTo(2); assertThat(conflicts.get()).isEqualTo(1); }
final SchemaNameAdjuster schemaNameAdjuster = SchemaNameAdjuster.create(LOGGER);
tableFilters.columnFilter(), new TableSchemaBuilder( getValueConverters(configuration), SchemaNameAdjuster.create(logger), SourceInfo.SCHEMA)
/** * Create a stateful Avro fullname adjuster that calls the supplied {@link ReplacementOccurred} function when an invalid * fullname is seen and replaced with a valid fullname. This method replaces all invalid characters with the underscore * character ('_'). * * @param uponReplacement the function called each time the original fullname is replaced; may be null * @return the adjuster; never null */ public static SchemaNameAdjuster create(ReplacementOccurred uponReplacement) { return create("_", uponReplacement); }
@Before public void beforeEach() { adjuster = SchemaNameAdjuster.create((original,replacement, conflict)->{ fail("Should not have come across an invalid schema name"); });
/** * Create a stateful Avro fullname adjuster that logs a warning the first time an invalid fullname is seen and replaced * with a valid fullname, and throws an error if the replacement conflicts with that of a different original. This method * replaces all invalid characters with the underscore character ('_'). * * @param logger the logger to use; may not be null * @return the validator; never null */ public static SchemaNameAdjuster create(Logger logger) { return create(logger, (original, replacement, conflict) -> { String msg = "The Kafka Connect schema name '" + original + "' is not a valid Avro schema name and its replacement '" + replacement + "' conflicts with another different schema '" + conflict + "'"; throw new ConnectException(msg); }); }
/** * Create a stateful Avro fullname adjuster that logs a warning the first time an invalid fullname is seen and replaced * with a valid fullname. This method replaces all invalid characters with the underscore character ('_'). * * @param logger the logger to use; may not be null * @param uponConflict the function to be called when there is a conflict and after that conflict is logged; may be null * @return the validator; never null */ public static SchemaNameAdjuster create(Logger logger, ReplacementOccurred uponConflict) { ReplacementOccurred handler = (original, replacement, conflictsWith) -> { if (conflictsWith != null) { logger.error("The Kafka Connect schema name '{}' is not a valid Avro schema name and its replacement '{}' conflicts with another different schema '{}'", original, replacement, conflictsWith); if (uponConflict != null) { uponConflict.accept(original, replacement, conflictsWith); } } else { logger.warn("The Kafka Connect schema name '{}' is not a valid Avro schema name, so replacing with '{}'", original, replacement); } }; return create(handler.firstTimeOnly()); }
private static TableSchemaBuilder getTableSchemaBuilder(PostgresConnectorConfig config, TypeRegistry typeRegistry, Charset databaseCharset) { PostgresValueConverter valueConverter = new PostgresValueConverter(databaseCharset, config.getDecimalMode(), config.temporalPrecisionMode(), ZoneOffset.UTC, null, config.includeUnknownDatatypes(), typeRegistry, config.hStoreHandlingMode()); return new TableSchemaBuilder(valueConverter, SchemaNameAdjuster.create(LOGGER), SourceInfo.SCHEMA); }
SchemaNameAdjuster schemaNameAdjuster = SchemaNameAdjuster.create(LOGGER);