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



##########
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:
       Seems the `toType` should always be a `Decimal` type, we should add a 
check here. Also, can we add some doc to this method ?




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