danny0405 commented on a change in pull request #1507: [CALCITE-3414] In
calcite-core, use RexToLixTranslator.convert for type conversion code
generation uniformly
URL: https://github.com/apache/calcite/pull/1507#discussion_r336828426
##########
File path:
core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
##########
@@ -966,6 +967,13 @@ public static Expression convert(Expression operand, Type
fromType,
if (fromType.equals(toType)) {
return operand;
}
+ if (toType instanceof Types.RecordType) {
+ // We can't extract Class from RecordType since mapping Java Class might
not generated yet.
+ return operand;
+ }
+ if (Types.isAssignableFrom(toType, fromType)) {
+ return operand;
+ }
// E.g. from "Short" to "int".
// Generate "x.intValue()".
Review comment:
Can we define a new method named `needsCast(Type tpe1, Type tpe2)` in
`Types` ? Then `Types.castIfNecessary` and `RexToLixTranslator.convert` can
both reuse this method. The method should include the content:
```java
if (fromType.equals(toType)) {
return operand;
}
if (toType instanceof Types.RecordType) {
// We can't extract Class from RecordType since mapping Java Class
might not generated yet.
return operand;
}
if (Types.isAssignableFrom(toType, fromType)) {
return operand;
}
```
----------------------------------------------------------------
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]
With regards,
Apache Git Services