yuxiqian commented on code in PR #4375:
URL: https://github.com/apache/flink-cdc/pull/4375#discussion_r3064167725
##########
flink-cdc-common/src/main/java/org/apache/flink/cdc/common/converter/CommonConverter.java:
##########
@@ -153,13 +154,21 @@ static StringData convertToStringData(Object obj) {
"Cannot convert " + obj + " of type " + obj.getClass() + " to
STRING DATA.");
}
- static DecimalData convertToDecimalData(Object obj) {
+ static DecimalData convertToDecimalData(Object obj, DecimalType
decimalType) {
if (obj instanceof DecimalData) {
- return (DecimalData) obj;
+ DecimalData dd = (DecimalData) obj;
+ // Re-convert to target precision and scale if different
+ if (dd.precision() == decimalType.getPrecision()
+ && dd.scale() == decimalType.getScale()) {
+ return dd;
+ }
+ return DecimalData.fromBigDecimal(
+ dd.toBigDecimal(), decimalType.getPrecision(),
decimalType.getScale());
}
if (obj instanceof BigDecimal) {
BigDecimal bd = (BigDecimal) obj;
- return DecimalData.fromBigDecimal(bd, bd.precision(), bd.scale());
+ return DecimalData.fromBigDecimal(
+ bd, decimalType.getPrecision(), decimalType.getScale());
}
Review Comment:
Seems it's OK since `convertTo` series type does not guarantee success, and
it should return `null` if such conversion is not viable.
--
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]