zstan commented on code in PR #13543:
URL: https://github.com/apache/ignite/pull/13543#discussion_r3957875042
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ConverterUtils.java:
##########
@@ -145,6 +150,66 @@ static List<Expression> fromInternal(Class<?>[]
targetTypes,
return list;
}
+ /** */
+ static List<Expression> fromInternal(RexToLixTranslator translator,
Review Comment:
Look now you have two identical code, differs only with "RexToLixTranslator
translator" param
i mean:
ConverterUtils#fromInternal(java.lang.Class<?>[], List<Expression>)
and
ConverterUtils#fromInternal(RexToLixTranslator, java.lang.Class<?>[],
java.util.List<Expression>)
seems you can them just rewrite your code like :
```
private static Expression fromInternal(@Nullable Expression root,
Expression operand, Type targetType) {
if (Types.isAssignableFrom(targetType, operand.getType())
|| Types.isAssignableFrom(targetType,
Primitive.box(operand.getType())))
return operand;
if (!TypeUtils.isConvertableType(targetType))
return targetType == BigDecimal.class ? fromInternal(operand,
operand.getType(), targetType) :
convert(operand, operand.getType(), targetType);
Primitive primitive = Primitive.of(targetType);
if (Primitive.is(operand.getType()))
operand = Expressions.box(operand);
Expression converted = Expressions.call(
TypeUtils.class,
"fromInternal",
root,//translator.getRoot(),
operand,
Expressions.constant(targetType)
);
return primitive == null
? Expressions.convert_(converted, targetType)
: Expressions.unbox(Expressions.convert_(converted,
primitive.boxClass), primitive);
}
```
probably some assertions check are helpful, it\`s just a prototype
Irun this approach through all calcite tests and it`s ok
wdyt ? cons: more readable code, less code base
--
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]