Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,12 @@ protected Map<String, String> extractRowData(

String transformed =
DebeziumSchemaUtils.transformRawValue(
rawValue, debeziumType, className, typeMapping, record.get(fieldName));
rawValue,
debeziumType,
className,
typeMapping,
record.get(fieldName),
parameters.get(fieldName));
resultMap.put(fieldName, transformed);

paimonFieldTypes.put(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.JsonNode;

import io.debezium.data.Bits;
import io.debezium.data.EnumSet;
import io.debezium.data.geometry.Geometry;
import io.debezium.data.geometry.Point;
import io.debezium.time.Date;
Expand All @@ -41,6 +42,7 @@
import javax.annotation.Nullable;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
Expand All @@ -61,7 +63,8 @@ public static String transformRawValue(
String debeziumType,
@Nullable String className,
TypeMapping typeMapping,
JsonNode origin) {
JsonNode origin,
Map<String, String> parameters) {
if (rawValue == null) {
return null;
}
Expand All @@ -87,9 +90,14 @@ public static String transformRawValue(
} else if ("bytes".equals(debeziumType) && decimalLogicalName().equals(className)) {
// MySQL numeric, fixed, decimal
try {
new BigDecimal(rawValue);
} catch (NumberFormatException e) {
throw new IllegalArgumentException(
byte[] bytes = Base64.getDecoder().decode(rawValue);
transformed =
new BigDecimal(
new BigInteger(bytes),
Integer.parseInt(parameters.get("scale")))
.toPlainString();
} catch (Exception e) {
throw new RuntimeException(
"Invalid big decimal value "
+ rawValue
+ ". Make sure that in the `customConverterConfigs` "
Expand Down Expand Up @@ -211,6 +219,10 @@ public static DataType toDataType(
return DataTypes.TIME();
}

if (EnumSet.LOGICAL_NAME.equals(className)) {
return DataTypes.ARRAY(DataTypes.STRING());
}

return fromDebeziumType(debeziumType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,6 @@ public void testSchemaIncludeRecord(String format) throws Exception {
waitForResult(expected, table, rowType, primaryKeys);
}

// TODO some types are different from mysql cdc; maybe need to fix
public void testAllTypesWithSchemaImpl(String format) throws Exception {
String topic = "schema_include_all_type";
createTestTopic(topic, 1, 1);
Expand Down Expand Up @@ -805,7 +804,7 @@ public void testAllTypesWithSchemaImpl(String format) throws Exception {
DataTypes.STRING(), // _multiline
DataTypes.STRING(), // _multipolygon
DataTypes.STRING(), // _geometrycollection
DataTypes.STRING() // _set different from mysql cdc
DataTypes.ARRAY(DataTypes.STRING()) // _set different from mysql cdc
},
new String[] {
"_id",
Expand Down Expand Up @@ -907,9 +906,7 @@ public void testAllTypesWithSchemaImpl(String format) throws Exception {
+ "1.000011, 2.000022, 3.000033, "
+ "1.000111, 2.000222, 3.000333, "
+ "12345.110, 12345.220, 12345.330, "
// TODO fix FIXED
+ "1.2345678987654322E32, 1.2345678987654322E32, 1.2345678987654322E32, "
// TODO fix BIG DECIMAL
+ "123456789876543212345678987654321.110, 123456789876543212345678987654321.220, 123456789876543212345678987654321.330, "
+ "11111, 22222, 33333, 2222222222222222400000000000.0000000000, "
+ "19439, "
// display value of datetime is not affected by timezone
Expand Down Expand Up @@ -940,8 +937,7 @@ public void testAllTypesWithSchemaImpl(String format) throws Exception {
+ "{\"coordinates\":[[[1,1],[2,2],[3,3]],[[4,4],[5,5]]],\"type\":\"MultiLineString\",\"srid\":0}, "
+ "{\"coordinates\":[[[[0,0],[10,0],[10,10],[0,10],[0,0]]],[[[5,5],[7,5],[7,7],[5,7],[5,5]]]],\"type\":\"MultiPolygon\",\"srid\":0}, "
+ "{\"geometries\":[{\"type\":\"Point\",\"coordinates\":[10,10]},{\"type\":\"Point\",\"coordinates\":[30,30]},{\"type\":\"LineString\",\"coordinates\":[[15,15],[20,20]]}],\"type\":\"GeometryCollection\",\"srid\":0}, "
// TODO fix set
+ "a,b"
+ "[a, b]"
+ "]");

List<String> primaryKeys = Arrays.asList("pt", "_id");
Expand Down
Loading