mirror of https://github.com/apache/druid.git
JavaScriptAggregator: Context.newArray makes nicer arrays than Context.javaToJS.
This commit is contained in:
parent
c2137e8416
commit
cb028f490a
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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; }"
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue