DBZ-6758 Add it test for (+/-) infinity values for numeric/decimal types

This commit is contained in:
harveyyue 2023-08-11 17:54:50 +08:00 committed by Jiri Pechanec
parent 15e81c1a84
commit 76738a6402
3 changed files with 40 additions and 1 deletions

View File

@ -750,7 +750,7 @@ public static AutoCreateMode parse(String value, String defaultValue) {
.withWidth(Width.MEDIUM)
.withImportance(Importance.MEDIUM)
.withValidation((config, field, output) -> {
if (config.getString(SNAPSHOT_MODE).toLowerCase().equals("custom") && config.getString(field, "").isEmpty()) {
if (config.getString(SNAPSHOT_MODE).equalsIgnoreCase("custom") && config.getString(field, "").isEmpty()) {
output.accept(field, "", "snapshot.custom_class cannot be empty when snapshot.mode 'custom' is defined");
return 1;
}

View File

@ -167,6 +167,15 @@ public abstract class AbstractRecordsProducerTest extends AbstractConnectorTest
+ "null, null, null, null, null, null"
+ ")";
protected static final String INSERT_NUMERIC_DECIMAL_TYPES_STMT_WITH_INFINITY = "INSERT INTO numeric_decimal_table (d, dzs, dvs, d_nn, n, nzs, nvs, "
+ "d_int, dzs_int, dvs_int, n_int, nzs_int, nvs_int, "
+ "d_nan, dzs_nan, dvs_nan, n_nan, nzs_nan, nvs_nan"
+ ") "
+ "VALUES (1.1, 10.11, 10.1111, 3.30, 22.22, 22.2, 22.2222, "
+ "1, 10, 10, 22, 22, 22, "
+ "null, null, 'Infinity', null, null, '-Infinity'"
+ ")";
protected static final String INSERT_RANGE_TYPES_STMT = "INSERT INTO range_table (unbounded_exclusive_tsrange, bounded_inclusive_tsrange, unbounded_exclusive_tstzrange, bounded_inclusive_tstzrange, unbounded_exclusive_daterange, bounded_exclusive_daterange, int4_number_range, numerange, int8_number_range) "
+
"VALUES ('[2019-03-31 15:30:00, infinity)', '[2019-03-31 15:30:00, 2019-04-30 15:30:00]', '[2017-06-05 11:29:12.549426+00,)', '[2017-06-05 11:29:12.549426+00, 2017-06-05 12:34:56.789012+00]', '[2019-03-31, infinity)', '[2019-03-31, 2019-04-30)', '[1000,6000)', '[5.3,6.3)', '[1000000,6000000)')";
@ -299,6 +308,24 @@ protected List<SchemaAndValueField> schemasAndValuesForStringEncodedNumericTypes
return fields;
}
protected List<SchemaAndValueField> schemasAndValuesForStringEncodedNumericTypesWithInfinity() {
return Arrays.asList(
new SchemaAndValueField("d", Schema.OPTIONAL_STRING_SCHEMA, "1.10"),
new SchemaAndValueField("dzs", Schema.OPTIONAL_STRING_SCHEMA, "10"),
new SchemaAndValueField("dvs", Schema.OPTIONAL_STRING_SCHEMA, "10.1111"),
new SchemaAndValueField("n", Schema.OPTIONAL_STRING_SCHEMA, "22.2200"),
new SchemaAndValueField("nzs", Schema.OPTIONAL_STRING_SCHEMA, "22"),
new SchemaAndValueField("nvs", Schema.OPTIONAL_STRING_SCHEMA, "22.2222"),
new SchemaAndValueField("d_int", Schema.OPTIONAL_STRING_SCHEMA, "1.00"),
new SchemaAndValueField("dzs_int", Schema.OPTIONAL_STRING_SCHEMA, "10"),
new SchemaAndValueField("dvs_int", Schema.OPTIONAL_STRING_SCHEMA, "10"),
new SchemaAndValueField("n_int", Schema.OPTIONAL_STRING_SCHEMA, "22.0000"),
new SchemaAndValueField("nzs_int", Schema.OPTIONAL_STRING_SCHEMA, "22"),
new SchemaAndValueField("nvs_int", Schema.OPTIONAL_STRING_SCHEMA, "22"),
new SchemaAndValueField("dvs_nan", Schema.OPTIONAL_STRING_SCHEMA, "POSITIVE_INFINITY"),
new SchemaAndValueField("nvs_nan", Schema.OPTIONAL_STRING_SCHEMA, "NEGATIVE_INFINITY"));
}
protected List<SchemaAndValueField> schemasAndValuesForDoubleEncodedNumericTypes() {
final List<SchemaAndValueField> fields = new ArrayList<SchemaAndValueField>(Arrays.asList(
new SchemaAndValueField("d", Schema.OPTIONAL_FLOAT64_SCHEMA, 1.1d),

View File

@ -12,6 +12,7 @@
import static io.debezium.connector.postgresql.TestHelper.TYPE_SCALE_PARAMETER_KEY;
import static io.debezium.connector.postgresql.TestHelper.topicName;
import static io.debezium.connector.postgresql.junit.SkipWhenDecoderPluginNameIs.DecoderPluginName.PGOUTPUT;
import static io.debezium.junit.EqualityCheck.LESS_THAN_OR_EQUAL;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
@ -1156,6 +1157,17 @@ public void shouldReceiveNumericTypeAsString() throws Exception {
assertInsert(INSERT_NUMERIC_DECIMAL_TYPES_STMT, 1, schemasAndValuesForStringEncodedNumericTypes());
}
@Test
@FixFor("DBZ-6758")
@SkipWhenDatabaseVersion(check = LESS_THAN_OR_EQUAL, major = 10, reason = "Database version less than or equal 10.0")
public void shouldReceiveChangesForInfinityNumericWithInfinity() throws Exception {
TestHelper.executeDDL("postgres_create_tables.ddl");
startConnector(config -> config.with(PostgresConnectorConfig.DECIMAL_HANDLING_MODE, "string"));
assertInsert(INSERT_NUMERIC_DECIMAL_TYPES_STMT_WITH_INFINITY, 1, schemasAndValuesForStringEncodedNumericTypesWithInfinity());
}
@Test
@FixFor("DBZ-898")
public void shouldReceiveHStoreTypeWithSingleValueAsMap() throws Exception {