diff --git a/processing/src/main/java/io/druid/query/aggregation/JavaScriptAggregatorFactory.java b/processing/src/main/java/io/druid/query/aggregation/JavaScriptAggregatorFactory.java index f3724695016..d54425d343b 100644 --- a/processing/src/main/java/io/druid/query/aggregation/JavaScriptAggregatorFactory.java +++ b/processing/src/main/java/io/druid/query/aggregation/JavaScriptAggregatorFactory.java @@ -37,6 +37,7 @@ import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.ScriptableObject; import javax.annotation.Nullable; +import java.lang.reflect.Array; import java.nio.ByteBuffer; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -276,7 +277,18 @@ public class JavaScriptAggregatorFactory implements AggregatorFactory for (int i = 0 ; i < size ; i++) { final ObjectColumnSelector selector = selectorList[i]; if (selector != null) { - args[i + 1] = Context.javaToJS(selector.get(), scope); + final Object arg = selector.get(); + if (arg.getClass().isArray()) { + // Context.javaToJS on an array sort of works, although it returns false for Array.isArray(...) and + // may have other issues too. Let's just copy the array and wrap that. + final Object[] arrayAsObjectArray = new Object[Array.getLength(arg)]; + for (int j = 0; j < Array.getLength(arg); j++) { + arrayAsObjectArray[j] = Array.get(arg, j); + } + args[i + 1] = cx.newArray(scope, arrayAsObjectArray); + } else { + args[i + 1] = Context.javaToJS(arg, scope); + } } } diff --git a/processing/src/test/java/io/druid/query/QueryRunnerTestHelper.java b/processing/src/test/java/io/druid/query/QueryRunnerTestHelper.java index 9421cba0aba..3aee65470fc 100644 --- a/processing/src/test/java/io/druid/query/QueryRunnerTestHelper.java +++ b/processing/src/test/java/io/druid/query/QueryRunnerTestHelper.java @@ -84,7 +84,7 @@ public class QueryRunnerTestHelper public static final JavaScriptAggregatorFactory indexSumJsPlacementishN = new JavaScriptAggregatorFactory( "nindex", Arrays.asList("placementish", "index"), - "function aggregate(current, a, b) { if ((typeof a !== 'string' && a.indexOf('a') > -1) || a === 'a') { return current + b; } else { return current; } }", + "function aggregate(current, a, b) { if ((Array.isArray(a) && a.indexOf('a') > -1) || a === 'a') { return current + b; } else { return current; } }", "function reset() { return 0; }", "function combine(a, b) { return a + b; }" );