chunweilei commented on a change in pull request #2089:
URL: https://github.com/apache/calcite/pull/2089#discussion_r463390656
##########
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
`toType` can be any type. I used `case when`. So I think it is fine.
> Also, can we add some doc to this method ?
Makes sense.
----------------------------------------------------------------
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]