danny0405 commented on a change in pull request #1083: [CALCITE-2889]
IndexOutOfBoundsException thrown if targetTypes[] contains varargs
URL: https://github.com/apache/calcite/pull/1083#discussion_r285414861
##########
File path:
core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java
##########
@@ -202,7 +202,23 @@ static Expression fromInternal(Expression e, Class<?>
targetType) {
List<Expression> expressions) {
final List<Expression> list = new ArrayList<>();
for (int i = 0; i < expressions.size(); i++) {
- list.add(fromInternal(expressions.get(i), targetTypes[i]));
+ if (i == targetTypes.length - 1 && targetTypes[i].isArray()) {
+ // only the last type could be varargs. All left expressions
+ // are supposed to be the same type as
targetTypes[i].getComponentType().
+ List<Expression> subList = expressions.subList(i, expressions.size());
+ list.addAll(fromInternal(targetTypes[i].getComponentType(), subList));
+ break;
+ } else {
+ list.add(fromInternal(expressions.get(i), targetTypes[i]));
+ }
+ }
+ return list;
+ }
+
+ private static List<Expression> fromInternal(Class<?> targetType,
List<Expression> expressions) {
+ final List<Expression> list = new ArrayList<>();
Review comment:
Maybe we should rename the method cause there is already a method named
`fromInternal`, say `fromComponentInternal` ?
----------------------------------------------------------------
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