snuyanzin commented on code in PR #3779:
URL: https://github.com/apache/calcite/pull/3779#discussion_r1597039588
##########
core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java:
##########
@@ -1822,6 +1823,35 @@ public static RelDataType
extractLastNFields(RelDataTypeFactory typeFactory,
type.getFieldList().subList(fieldsCnt - numToKeep, fieldsCnt));
}
+ /**
+ * Returns whether the decimal value can be represented without information
loss
+ * using the specified type.
+ * For example, 1111.11
+ * - cannot be represented exactly using DECIMAL(3, 1) since it overflows.
+ * - cannot be represented exactly using DECIMAL(6, 3) since it overflows.
+ * - cannot be represented exactly using DECIMAL(6, 1) since it requires
rounding.
+ * - can be represented exactly using DECIMAL(6, 2)
+ *
+ * @param value A decimal value
+ * @param toType A DECIMAL type.
+ * @return whether the value is valid for the type
+ */
+ public static boolean canBeRepresentedExactly(@Nullable BigDecimal value,
RelDataType toType) {
+ assert toType.getSqlTypeName() == SqlTypeName.DECIMAL;
+ if (value == null) {
+ return true;
+ }
+ value = value.stripTrailingZeros();
+ if (value.scale() < 0) {
Review Comment:
as you mentioned if there is a separate issue for negative scale is
required, could you please file one in Calcite jira?
All the rest is ok to me, thanks
--
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]