hemanthsavasere commented on code in PR #1877:
URL: https://github.com/apache/fluss/pull/1877#discussion_r2554150176


##########
fluss-client/src/main/java/org/apache/fluss/client/converter/PojoToRowConverter.java:
##########
@@ -234,6 +242,135 @@ private static FieldToRow 
createFieldConverter(PojoType.Property prop, DataType
                         prop.name));
     }
 
+    /** Converts a numeric POJO property to TINYINT (Byte). */
+    private static @Nullable Byte convertToTinyInt(PojoType.Property prop, 
@Nullable Object v) {
+        if (v == null) {
+            return null;
+        }
+        if (v instanceof Byte) {
+            return (Byte) v;
+        }
+        throw new IllegalArgumentException(
+                String.format(
+                        "Field %s cannot be converted to TINYINT. Type: %s",
+                        prop.name, v.getClass().getName()));
+    }
+
+    /** Converts a numeric POJO property to SMALLINT (Short) with widening 
support. */
+    private static @Nullable Short convertToSmallInt(PojoType.Property prop, 
@Nullable Object v) {
+        if (v == null) {
+            return null;
+        }
+        if (v instanceof Short) {
+            return (Short) v;
+        }
+        if (v instanceof Byte) {
+            return ((Byte) v).shortValue(); // byte -> short widening
+        }
+        throw new IllegalArgumentException(
+                String.format(
+                        "Field %s cannot be converted to SMALLINT. Type: %s",
+                        prop.name, v.getClass().getName()));
+    }
+
+    /** Converts a numeric POJO property to INTEGER (Integer) with widening 
support. */
+    private static @Nullable Integer convertToInteger(PojoType.Property prop, 
@Nullable Object v) {
+        if (v == null) {
+            return null;
+        }
+        if (v instanceof Integer) {
+            return (Integer) v;
+        }
+        if (v instanceof Short) {
+            return ((Short) v).intValue(); // short -> int widening
+        }
+        if (v instanceof Byte) {
+            return ((Byte) v).intValue(); // byte -> int widening
+        }
+        throw new IllegalArgumentException(
+                String.format(
+                        "Field %s cannot be converted to INTEGER. Type: %s",
+                        prop.name, v.getClass().getName()));
+    }
+
+    /** Converts a numeric POJO property to BIGINT (Long) with widening 
support. */
+    private static @Nullable Long convertToBigInt(PojoType.Property prop, 
@Nullable Object v) {
+        if (v == null) {
+            return null;
+        }
+        if (v instanceof Long) {
+            return (Long) v;
+        }
+        if (v instanceof Integer) {
+            return ((Integer) v).longValue(); // int -> long widening
+        }
+        if (v instanceof Short) {
+            return ((Short) v).longValue(); // short -> long widening
+        }
+        if (v instanceof Byte) {
+            return ((Byte) v).longValue(); // byte -> long widening
+        }
+        throw new IllegalArgumentException(
+                String.format(
+                        "Field %s cannot be converted to BIGINT. Type: %s",
+                        prop.name, v.getClass().getName()));
+    }
+
+    /** Converts a numeric POJO property to FLOAT (Float) with widening 
support. */
+    private static @Nullable Float convertToFloat(PojoType.Property prop, 
@Nullable Object v) {
+        if (v == null) {
+            return null;
+        }
+        if (v instanceof Float) {
+            return (Float) v;
+        }
+        if (v instanceof Long) {
+            return ((Long) v).floatValue(); // long -> float widening
+        }
+        if (v instanceof Integer) {
+            return ((Integer) v).floatValue(); // int -> float widening
+        }
+        if (v instanceof Short) {
+            return ((Short) v).floatValue(); // short -> float widening
+        }
+        if (v instanceof Byte) {
+            return ((Byte) v).floatValue(); // byte -> float widening
+        }
+        throw new IllegalArgumentException(
+                String.format(
+                        "Field %s cannot be converted to FLOAT. Type: %s",
+                        prop.name, v.getClass().getName()));
+    }
+
+    /** Converts a numeric POJO property to DOUBLE (Double) with widening 
support. */
+    private static @Nullable Double convertToDouble(PojoType.Property prop, 
@Nullable Object v) {
+        if (v == null) {
+            return null;
+        }
+        if (v instanceof Double) {
+            return (Double) v;
+        }
+        if (v instanceof Float) {
+            return ((Float) v).doubleValue(); // float -> double widening
+        }
+        if (v instanceof Long) {
+            return ((Long) v).doubleValue(); // long -> double widening
+        }
+        if (v instanceof Integer) {
+            return ((Integer) v).doubleValue(); // int -> double widening
+        }
+        if (v instanceof Short) {
+            return ((Short) v).doubleValue(); // short -> double widening
+        }
+        if (v instanceof Byte) {
+            return ((Byte) v).doubleValue(); // byte -> double widening
+        }

Review Comment:
   Agreed, I have done the changes.



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