healchow commented on code in PR #8338:
URL: https://github.com/apache/inlong/pull/8338#discussion_r1244980862


##########
inlong-sort/sort-flink/base/src/main/java/org/apache/inlong/sort/base/format/JsonDynamicSchemaFormat.java:
##########
@@ -336,6 +358,45 @@ protected RowType extractSchemaNode(JsonNode schema, 
List<String> pkNames) {
         return new RowType(fields);
     }
 
+    /**
+     * set precision and scale for decimal and other types
+     *
+     * @param type original flink type
+     * @param dialectType database dialect type
+     * @return flink type revised according to dialect type
+     */
+    public LogicalType handleDialectSqlType(LogicalType type, String 
dialectType) {
+        if (StringUtils.isBlank(dialectType)) {
+            return type;
+        }
+        if (type instanceof DecimalType) {
+            Matcher matcher = DIALECT_SQL_TYPE_PATTERN.matcher(dialectType);
+            int precision;
+            int scale;
+            DecimalType decimalType = new 
DecimalType(DecimalType.MAX_PRECISION);
+            if (matcher.matches()) {
+                String[] items = matcher.group(1).split(",");
+                precision = Integer.parseInt(items[0].trim());
+                if (precision < DecimalType.MIN_PRECISION || precision > 
DecimalType.MAX_PRECISION) {
+                    LOG.info("Decimal has invalid precision {}", precision);
+                    return decimalType;
+                }
+                if (items.length == 2) {
+                    scale = Integer.parseInt(items[1].trim());
+                    if (scale < DecimalType.MIN_SCALE || scale > precision) {
+                        LOG.info("Decimal has invalid scale {}", scale);
+                        return new DecimalType(precision);

Review Comment:
   ```suggestion
                           decimalType = new DecimalType(precision);
                           LOG.info("invalid decimal scale: {}, change to: {}", 
scale, decimalType.getScale());
                           return decimalType;
   ```



-- 
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]

Reply via email to