suhwan-cheon commented on code in PR #4277:
URL: https://github.com/apache/flink-cdc/pull/4277#discussion_r2909039726
##########
flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-iceberg/src/main/java/org/apache/flink/cdc/connectors/iceberg/sink/utils/IcebergTypeUtils.java:
##########
@@ -53,6 +60,66 @@ public static Types.NestedField
convertCdcColumnToIcebergField(
column.getComment());
}
+ /**
+ * Parse a CDC default value expression string into an Iceberg {@link
Literal}.
+ *
+ * @return the parsed Literal, or null if the expression is null or cannot
be parsed for the
+ * given type.
+ */
+ @Nullable
+ public static Literal<?> parseDefaultValue(
+ @Nullable String defaultValueExpression, DataType cdcType) {
+ if (defaultValueExpression == null) {
+ return null;
+ }
+ try {
+ switch (cdcType.getTypeRoot()) {
+ case CHAR:
+ case VARCHAR:
+ return Literal.of(defaultValueExpression);
+ case BOOLEAN:
+ if ("true".equalsIgnoreCase(defaultValueExpression)) {
+ return Literal.of(true);
+ } else if
("false".equalsIgnoreCase(defaultValueExpression)) {
+ return Literal.of(false);
+ } else {
+ LOG.warn(
+ "Invalid boolean default value '{}', skipping
default value.",
+ defaultValueExpression);
+ return null;
+ }
+ case TINYINT:
+ case SMALLINT:
+ case INTEGER:
+ return
Literal.of(Integer.parseInt(defaultValueExpression));
+ case BIGINT:
+ return Literal.of(Long.parseLong(defaultValueExpression));
+ case FLOAT:
+ return
Literal.of(Float.parseFloat(defaultValueExpression));
+ case DOUBLE:
+ return
Literal.of(Double.parseDouble(defaultValueExpression));
+ case DECIMAL:
+ int scale = DataTypes.getScale(cdcType).orElse(0);
+ return Literal.of(
+ new java.math.BigDecimal(defaultValueExpression)
+ .setScale(scale,
java.math.RoundingMode.HALF_UP));
+ default:
Review Comment:
@lvyanquan
Hello!
I think you're confused by the markdown structure.
The PR summary already states that DATE/TIME/TIMESTAMP defaults are not
supported.
```
DATE/TIME/TIMESTAMP defaults not supported: parseDefaultValue() returns null
for these types
```
Please let me know if I misunderstood!
--
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]