mirror of https://github.com/apache/druid.git
JavaScriptAggregatorFactory: Handle missing columns by passing down null args
This commit is contained in:
parent
dbd551e6a8
commit
3b2833d55d
|
@ -265,9 +265,11 @@ public class JavaScriptAggregatorFactory implements AggregatorFactory
|
|||
final Object[] args = new Object[size + 1];
|
||||
|
||||
args[0] = current;
|
||||
int i = 0;
|
||||
while (i < size) {
|
||||
args[i + 1] = selectorList[i++].get();
|
||||
for (int i = 0 ; i < size ; i++) {
|
||||
final ObjectColumnSelector selector = selectorList[i];
|
||||
if (selector != null) {
|
||||
args[i + 1] = selector.get();
|
||||
}
|
||||
}
|
||||
|
||||
final Object res = fnAggregate.call(cx, scope, scope, args);
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.junit.Test;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public class JavaScriptAggregatorTest
|
||||
|
@ -141,6 +142,39 @@ public class JavaScriptAggregatorTest
|
|||
Assert.assertEquals(val, agg.get(buf, position));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAggregateMissingColumn()
|
||||
{
|
||||
Map<String, String> script = scriptDoubleSum;
|
||||
|
||||
JavaScriptAggregator agg = new JavaScriptAggregator(
|
||||
"billy",
|
||||
Collections.<ObjectColumnSelector>singletonList(null),
|
||||
JavaScriptAggregatorFactory.compileScript(script.get("fnAggregate"),
|
||||
script.get("fnReset"),
|
||||
script.get("fnCombine"))
|
||||
);
|
||||
|
||||
final double val = 0;
|
||||
|
||||
Assert.assertEquals("billy", agg.getName());
|
||||
|
||||
agg.reset();
|
||||
Assert.assertEquals(val, agg.get());
|
||||
Assert.assertEquals(val, agg.get());
|
||||
Assert.assertEquals(val, agg.get());
|
||||
|
||||
agg.aggregate();
|
||||
Assert.assertEquals(val, agg.get());
|
||||
Assert.assertEquals(val, agg.get());
|
||||
Assert.assertEquals(val, agg.get());
|
||||
|
||||
agg.aggregate();
|
||||
Assert.assertEquals(val, agg.get());
|
||||
Assert.assertEquals(val, agg.get());
|
||||
Assert.assertEquals(val, agg.get());
|
||||
}
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
final LoopingFloatColumnSelector selector = new LoopingFloatColumnSelector(new float[]{42.12f, 9f});
|
||||
|
||||
|
|
Loading…
Reference in New Issue