Skip to content

Commit

Permalink
QueryLanguageParser: Explicitly Create VarArgs for Primitives and Box…
Browse files Browse the repository at this point in the history
…ed Primitives (#3565)
  • Loading branch information
nbauernfeind authored Mar 21, 2023
1 parent 2bbcc16 commit 1821cc2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package io.deephaven.engine.table.impl.lang;

import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.ast.ArrayCreationLevel;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.ImportDeclaration;
Expand Down Expand Up @@ -1102,19 +1103,24 @@ && isAssignableFrom(argumentTypes[lastArgIndex], expressionTypes[lastArgIndex]))
}
}

if (varArgType.isPrimitive() && allExpressionTypesArePrimitive) {
// there are ambiguous oddities with primitive varargs, so if its primitive lets just box it ourselves
if ((TypeUtils.isBoxedType(varArgType) || varArgType.isPrimitive()) && allExpressionTypesArePrimitive) {
// method invocation is ambiguous when both boxed and primitive versions of the method exist
Expression[] temp = new Expression[nArgs];
Expression[] varArgExpressions = new Expression[nArgExpressions - nArgs + 1];
System.arraycopy(expressions, 0, temp, 0, temp.length - 1);
System.arraycopy(expressions, nArgs - 1, varArgExpressions, 0,
varArgExpressions.length);

NodeList<ArrayCreationLevel> levels = new NodeList<>(new ArrayCreationLevel());
com.github.javaparser.ast.type.Type elementType;
if (varArgType.isPrimitive()) {
elementType = new PrimitiveType(PrimitiveType.Primitive.valueOf(
varArgType.getSimpleName().toUpperCase()));
} else {
elementType = StaticJavaParser.parseClassOrInterfaceType(varArgType.getSimpleName());
}
temp[temp.length - 1] = new ArrayCreationExpr(
new PrimitiveType(
PrimitiveType.Primitive.valueOf(varArgType.getSimpleName().toUpperCase())),
levels, new ArrayInitializerExpr(new NodeList<>(varArgExpressions)));
elementType, levels, new ArrayInitializerExpr(new NodeList<>(varArgExpressions)));

expressions = temp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1079,4 +1079,16 @@ public void testRedirectUpdate() {
Assert.assertEquals(4L, updated.getColumnSource("D").get(updated.getRowSet().get(1)));
Assert.assertEquals(8L, updated.getColumnSource("D").getPrev(updated.getRowSet().copyPrev().get(2)));
}

@Test
public void testRegressionGH3562() {
final Table src = TableTools.emptyTable(3).update("A = true", "B = ii != 1", "C = ii != 2");
final Table result = src.select("And = and(A, B, C)", "Or = or(A, B, C)");

final Table expected = TableTools.newTable(
TableTools.col("And", true, false, false),
TableTools.col("Or", true, true, true));

assertTableEquals(expected, result);
}
}

0 comments on commit 1821cc2

Please sign in to comment.