danny0405 commented on a change in pull request #2089:
URL: https://github.com/apache/calcite/pull/2089#discussion_r463435842



##########
File path: core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java
##########
@@ -1751,4 +1752,18 @@ public static RelDataType 
extractLastNFields(RelDataTypeFactory typeFactory,
     return typeFactory.createStructType(
         type.getFieldList().subList(fieldsCnt - numToKeep, fieldsCnt));
   }
+
+  public static boolean isValidDecimalValue(BigDecimal value, RelDataType 
toType) {
+    if (value == null) {
+      return true;
+    }
+    switch (toType.getSqlTypeName()) {
+    case DECIMAL:
+      final int intDigits = value.precision() - value.scale();
+      final int maxIntDigits = toType.getPrecision() - toType.getScale();
+      return intDigits <= maxIntDigits;

Review comment:
       If `toType` is not decimal, how can you ensure that it has a valid 
precision and scale, such as `-1`.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to