MOBIN-F commented on code in PR #3362:
URL: https://github.com/apache/paimon/pull/3362#discussion_r1608023414
##########
paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/action/cdc/postgres/PostgresRecordParser.java:
##########
@@ -209,6 +226,18 @@ private DataType extractFieldType(DebeziumEvent.Field
field) {
case "boolean":
return DataTypes.BOOLEAN();
case "string":
+ int newLength = afterData.get(field.field()).asText().length();
+ if (paimonField == null) {
+ return DataTypes.VARCHAR(newLength == 0 ? MIN_LENGTH :
newLength);
+ } else if (paimonField.type() instanceof VarCharType) {
+ int oldLength = ((VarCharType)
paimonField.type()).getLength();
+ return DataTypes.VARCHAR(
+ Math.max(oldLength, newLength == 0 ? MIN_LENGTH :
newLength));
+ } else if (paimonField.type() instanceof CharType) {
+ int oldLength = ((CharType)
paimonField.type()).getLength();
+ return DataTypes.CHAR(
+ Math.max(oldLength, newLength == 0 ? MIN_LENGTH :
newLength));
+ }
Review Comment:
in case "string", We cannot convert the varchar(n)/char(n) type into the
string type, which will cause schemaCompatible to fail if the field changes
when restarting the paimon-cdc job, because the string length of paimon is
integer.max is always greater than n.
At the same time, when pg table performs column type alter(example: n
changes from 10 to 20), because pg-debezium does not have ddl event, we can
only get the length value n from the record
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]