asolimando commented on code in PR #3687:
URL: https://github.com/apache/calcite/pull/3687#discussion_r1490147805
##########
core/src/test/java/org/apache/calcite/test/JdbcTest.java:
##########
@@ -8301,6 +8301,67 @@ private void checkGetTimestamp(Connection con) throws
SQLException {
});
}
+ final String[] intTypes = {"tinyint", "smallint", "int", "bigint"};
Review Comment:
You can use `SqlTypeFamily.INTEGER` to derive those type names
##########
core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java:
##########
@@ -1374,11 +1374,35 @@ private Result toInnerStorageType(Result result, Type
storageType) {
}
final Type storageType = currentStorageType != null
? currentStorageType :
typeFactory.getJavaClass(dynamicParam.getType());
- final Expression valueExpression =
+
+ // For numeric types, get the value using the following functions on the
Review Comment:
As @mihaibudiu suggests, this is basically a cast, which is already
available via the `Types.castIfNecessary` method, see below for how it can be
used:
```
final boolean isNumeric =
SqlTypeFamily.NUMERIC.contains(dynamicParam.getType());
final Expression valueExpression = Types.castIfNecessary(storageType,
EnumUtils.convert(Expressions.call(root,
BuiltInMethod.DATA_CONTEXT_GET.method,
Expressions.constant("?" + dynamicParam.getIndex())),
isNumeric ? java.lang.Number.class : storageType));
```
If you replace your code with this, it passes all the tests you added, and
it might be working for non-numeric cases too (maybe with some adaptations).
Could you give it a try and add more tests non-numeric types to check?
--
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]