snuyanzin commented on a change in pull request #17800:
URL: https://github.com/apache/flink/pull/17800#discussion_r750215594



##########
File path: 
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/data/binary/BinaryStringDataUtil.java
##########
@@ -168,21 +179,35 @@ public static BinaryStringData hash(BinaryStringData str, 
String algorithm)
     }
 
     /**
-     * Parses this BinaryStringData to DecimalData.
+     * Parses a {@link BinaryStringData} to {@link DecimalData}.
      *
-     * @return DecimalData value if the parsing was successful, or null if 
overflow
-     * @throws NumberFormatException if the parsing failed.
+     * @return DecimalData value if the parsing was successful.
+     * @throws TableException if the parsing failed or if overflow happened.
      */
-    public static DecimalData toDecimal(BinaryStringData str, int precision, 
int scale) {
+    public static DecimalData toDecimal(BinaryStringData str, int precision, 
int scale)
+            throws TableException {
         str.ensureMaterialized();
 
-        if (DecimalDataUtils.isByteArrayDecimal(precision)
-                || DecimalDataUtils.isByteArrayDecimal(str.getSizeInBytes())) {
-            return toBigPrecisionDecimal(str, precision, scale);
+        DecimalData data;
+
+        try {
+            if (DecimalDataUtils.isByteArrayDecimal(precision)
+                    || 
DecimalDataUtils.isByteArrayDecimal(str.getSizeInBytes())) {
+                data = toBigPrecisionDecimal(str, precision, scale);
+            } else {
+                int sizeInBytes = str.getSizeInBytes();
+                data =
+                        toDecimalFromBytes(
+                                precision, scale, getTmpBytes(str, 
sizeInBytes), 0, sizeInBytes);
+            }
+        } catch (NumberFormatException e) {
+            throw new TableException("Cannot parse string to decimal", e);

Review comment:
       Probably it makes sense to specify what string cannot be parsed like it 
is done for `toBoolean`.




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