vladErmakov07 commented on a change in pull request #9199:
URL: https://github.com/apache/ignite/pull/9199#discussion_r659792913
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ConverterUtils.java
##########
@@ -175,6 +175,54 @@ public static Expression convert(Expression operand, Type
toType) {
return convert(operand, fromType, toType);
}
+ /**
+ * Convert {@code operand} from {@code targetType} to BigDecimal type.
+ *
+ * @param operand The expression to convert
+ * @param targetType Target type
+ * @param fromType Field type
+ * @return An expression with BidDecimal type, which calls
IgniteSqlFunctions.toBigDecimal function.
+ */
+ public static Expression convertToDecimal(Expression operand, Type
fromType, RelDataType targetType) {
+ final Primitive fromBox = Primitive.ofBox(fromType);
+ final Primitive fromPrimitive = Primitive.of(fromType);
+ if (fromBox != null) {
+ // E.g. from "Integer" to "BigDecimal".
+ // Generate "x == null ? null : new BigDecimal(x.intValue())"
+
+ return Expressions.condition(
+ Expressions.equal(operand, RexImpTable.NULL_EXPR),
+ RexImpTable.NULL_EXPR,
+ Expressions.call(
+ IgniteSqlFunctions.class,
+ "toBigDecimal",
+ Expressions.unbox(operand, fromBox),
+ Expressions.constant(targetType.getPrecision()),
+ Expressions.constant(targetType.getScale())));
+ }
+ if (fromPrimitive != null) {
+ // E.g. from "int" to "BigDecimal".
Review comment:
Added IgniteSqlFunctionsTest that covers all the cases.
--
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]