DBZ-2698 Added support for null default value for types int, bigint, smallint, tinyint, float, real
This commit is contained in:
parent
1875826d3a
commit
8cd2da3bfb
@ -118,7 +118,8 @@ private Map<String, DefaultValueMapper> createDefaultValueMappers() {
|
|||||||
final Map<String, DefaultValueMapper> result = new HashMap<>();
|
final Map<String, DefaultValueMapper> result = new HashMap<>();
|
||||||
|
|
||||||
// Exact numbers
|
// Exact numbers
|
||||||
result.put("bigint", v -> nullableDefaultValueMapper(v, value -> Long.parseLong(value.replaceAll("(\\.)$", "")))); // Sample value: ((3147483648.))
|
result.put("bigint",
|
||||||
|
v -> nullableDefaultValueMapper(v, value -> Long.parseLong(value.charAt(value.length() - 1) == '.' ? value.substring(0, value.length() - 1) : value))); // Sample value: ((3147483648.))
|
||||||
result.put("int", v -> nullableDefaultValueMapper(v, Integer::parseInt)); // Sample value: ((2147483647))
|
result.put("int", v -> nullableDefaultValueMapper(v, Integer::parseInt)); // Sample value: ((2147483647))
|
||||||
result.put("smallint", v -> nullableDefaultValueMapper(v, Short::parseShort)); // Sample value: ((32767))
|
result.put("smallint", v -> nullableDefaultValueMapper(v, Short::parseShort)); // Sample value: ((32767))
|
||||||
result.put("tinyint", v -> nullableDefaultValueMapper(v, Short::parseShort)); // Sample value: ((255))
|
result.put("tinyint", v -> nullableDefaultValueMapper(v, Short::parseShort)); // Sample value: ((255))
|
||||||
@ -180,7 +181,9 @@ private Map<String, DefaultValueMapper> createDefaultValueMappers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Object nullableDefaultValueMapper(String v, DefaultValueMapper mapper) throws Exception {
|
public static Object nullableDefaultValueMapper(String v, DefaultValueMapper mapper) throws Exception {
|
||||||
final String value = v.replaceAll("^[\\(]+|[\\)]+$", ""); // trim leading and trailing parenthesis
|
int start = v.lastIndexOf("(") == -1 ? 0 : v.lastIndexOf("(") + 1;
|
||||||
|
int end = !v.contains(")") ? v.length() : v.indexOf(")");
|
||||||
|
final String value = v.substring(start, end); // trim leading and trailing parenthesis
|
||||||
if ("NULL".equalsIgnoreCase(value)) {
|
if ("NULL".equalsIgnoreCase(value)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,9 @@
|
|||||||
import java.time.ZoneOffset;
|
import java.time.ZoneOffset;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.awaitility.Awaitility;
|
||||||
import org.fest.assertions.Assertions;
|
import org.fest.assertions.Assertions;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -276,7 +278,7 @@ public void shouldProperlyGetDefaultColumnNullValues() throws Exception {
|
|||||||
+ " bigint_no_default_not_null bigint not null,"
|
+ " bigint_no_default_not_null bigint not null,"
|
||||||
+ " bigint_no_default bigint,"
|
+ " bigint_no_default bigint,"
|
||||||
+ " bigint_default_null bigint default null,"
|
+ " bigint_default_null bigint default null,"
|
||||||
+ " bigint_column bigint default (3147483648),"
|
+ " bigint_column bigint default (3147483648.),"
|
||||||
|
|
||||||
+ " smallint_no_default_not_null smallint not null,"
|
+ " smallint_no_default_not_null smallint not null,"
|
||||||
+ " smallint_no_default smallint,"
|
+ " smallint_no_default smallint,"
|
||||||
@ -306,7 +308,9 @@ public void shouldProperlyGetDefaultColumnNullValues() throws Exception {
|
|||||||
// insert some data
|
// insert some data
|
||||||
|
|
||||||
// and issue a test call to a CDC wrapper function
|
// and issue a test call to a CDC wrapper function
|
||||||
Thread.sleep(5_000); // Need to wait to make sure the min_lsn is available
|
Awaitility.await()
|
||||||
|
.atMost(5, TimeUnit.SECONDS)
|
||||||
|
.until(() -> connection.getMinLsn("table_with_defaults").isAvailable()); // Need to wait to make sure the min_lsn is available
|
||||||
List<String> capturedColumns = Arrays
|
List<String> capturedColumns = Arrays
|
||||||
.asList(
|
.asList(
|
||||||
"int_no_default_not_null",
|
"int_no_default_not_null",
|
||||||
|
Loading…
Reference in New Issue
Block a user