Vladsz83 commented on code in PR #11581:
URL: https://github.com/apache/ignite/pull/11581#discussion_r1806157374
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/IgniteSqlFunctions.java:
##########
@@ -64,46 +73,42 @@ public static String toString(BigDecimal x) {
return x == null ? null : x.toPlainString();
}
- /** */
- private static BigDecimal setScale(int precision, int scale, BigDecimal
decimal) {
- return precision ==
IgniteTypeSystem.INSTANCE.getDefaultPrecision(SqlTypeName.DECIMAL)
- ? decimal : decimal.setScale(scale, RoundingMode.HALF_UP);
- }
-
/** CAST(DOUBLE AS DECIMAL). */
public static BigDecimal toBigDecimal(double val, int precision, int
scale) {
- BigDecimal decimal = BigDecimal.valueOf(val);
- return setScale(precision, scale, decimal);
+ return removeDefaultScale(precision, scale,
toBigDecimal(BigDecimal.valueOf(val), precision, scale));
}
/** CAST(FLOAT AS DECIMAL). */
public static BigDecimal toBigDecimal(float val, int precision, int scale)
{
- BigDecimal decimal = new BigDecimal(String.valueOf(val));
- return setScale(precision, scale, decimal);
+ return removeDefaultScale(precision, scale,
toBigDecimal(BigDecimal.valueOf(val), precision, scale));
+ }
+
+ /** Removes redundant scale in case of default DECIMAL (without passed
precision and scale). */
+ private static BigDecimal removeDefaultScale(int precision, int scale,
BigDecimal val) {
+ if (precision == DFLT_NUM_PRECISION && scale == 0 &&
val.compareTo(val.setScale(0, NUMERIC_ROUNDING_MODE)) == 0)
+ return val.setScale(0, NUMERIC_ROUNDING_MODE);
Review Comment:
Without this, the tests fail: `testDecimalScale()`,
`testNumericConversion()`. Actually, there are questions about current
precisions of numeric. But in this ticket I didn't fix anithing about it.
--
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]