This is an automated email from the ASF dual-hosted git repository.

aloalt pushed a commit to branch 295
in repository https://gitbox.apache.org/repos/asf/incubator-wayang.git


The following commit(s) were added to refs/heads/295 by this push:
     new acd67f69 Added logging
acd67f69 is described below

commit acd67f6999fc2481da39904a16de1be3792ba633
Author: Alexander Alten <[email protected]>
AuthorDate: Tue Dec 5 08:15:46 2023 +0100

    Added logging
---
 .../wayang/api/sql/sources/fs/CsvRowConverter.java | 31 ++++++++++++++++++----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git 
a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/sources/fs/CsvRowConverter.java
 
b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/sources/fs/CsvRowConverter.java
index 0c84573e..58005652 100755
--- 
a/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/sources/fs/CsvRowConverter.java
+++ 
b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/sources/fs/CsvRowConverter.java
@@ -29,6 +29,32 @@ import java.text.ParseException;
 import java.util.Date;
 import java.util.Locale;
 import java.util.TimeZone;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+
+public class CsvRowConverter {
+
+    private static final Logger LOGGER = 
Logger.getLogger(CsvRowConverter.class.getName());
+
+    private static BigDecimal parseDecimal(int precision, int scale, String 
string) {
+        BigDecimal result = new BigDecimal(string);
+        
+        if (result.scale() > scale) {
+            // Logging the rounding operation
+            LOGGER.log(Level.INFO, "Rounding decimal value {0} to scale {1}", 
new Object[]{result, scale});
+            result = result.setScale(scale, RoundingMode.HALF_UP);
+        }
+
+        if (result.precision() - result.scale() > precision - scale) {
+            String errorMessage = String.format(Locale.ROOT, "Decimal value %s 
exceeds declared precision (%d) and scale (%d).", result, precision, scale);
+            LOGGER.log(Level.SEVERE, errorMessage);
+            throw new IllegalArgumentException(errorMessage);
+        }
+        return result;
+    }
+
+}
+
 
 /**
  * Based on Calcite's CSV enumerator.
@@ -143,11 +169,6 @@ public class CsvRowConverter {
         // If the parsed value has more fractional digits than the specified 
scale, round ties away
         // from 0.
         if (result.scale() > scale) {
-            //TODO: enable logging
-            /*LOGGER.warn(
-                    "Decimal value {} exceeds declared scale ({}). Performing 
rounding to keep the "
-                            + "first {} fractional digits.",
-                    result, scale, scale);*/
             result = result.setScale(scale, RoundingMode.HALF_UP);
         }
         // Throws an exception if the parsed value has more digits to the left 
of the decimal point

Reply via email to