diff --git a/processing/src/test/java/io/druid/query/QueryRunnerTestHelper.java b/processing/src/test/java/io/druid/query/QueryRunnerTestHelper.java index 3aee65470fc..ffa6b02c236 100644 --- a/processing/src/test/java/io/druid/query/QueryRunnerTestHelper.java +++ b/processing/src/test/java/io/druid/query/QueryRunnerTestHelper.java @@ -81,13 +81,20 @@ public class QueryRunnerTestHelper public static final CountAggregatorFactory rowsCount = new CountAggregatorFactory("rows"); public static final LongSumAggregatorFactory indexLongSum = new LongSumAggregatorFactory("index", "index"); public static final DoubleSumAggregatorFactory indexDoubleSum = new DoubleSumAggregatorFactory("index", "index"); - public static final JavaScriptAggregatorFactory indexSumJsPlacementishN = new JavaScriptAggregatorFactory( + public static final JavaScriptAggregatorFactory jsIndexSumIfPlacementishA = new JavaScriptAggregatorFactory( "nindex", Arrays.asList("placementish", "index"), "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; }" ); + public static final JavaScriptAggregatorFactory jsPlacementishCount = new JavaScriptAggregatorFactory( + "pishcount", + Arrays.asList("placementish", "index"), + "function aggregate(current, a) { if (Array.isArray(a)) { return current + a.length; } else if (typeof a === 'string') { return current + 1; } else { return current; } }", + "function reset() { return 0; }", + "function combine(a, b) { return a + b; }" + ); public static final HyperUniquesAggregatorFactory qualityUniques = new HyperUniquesAggregatorFactory( "uniques", "quality_uniques" diff --git a/processing/src/test/java/io/druid/query/timeseries/TimeseriesQueryRunnerTest.java b/processing/src/test/java/io/druid/query/timeseries/TimeseriesQueryRunnerTest.java index bf15a8a75f5..cfc26c4326a 100644 --- a/processing/src/test/java/io/druid/query/timeseries/TimeseriesQueryRunnerTest.java +++ b/processing/src/test/java/io/druid/query/timeseries/TimeseriesQueryRunnerTest.java @@ -1273,7 +1273,8 @@ public class TimeseriesQueryRunnerTest .aggregators( ImmutableList.of( QueryRunnerTestHelper.indexDoubleSum, - QueryRunnerTestHelper.indexSumJsPlacementishN + QueryRunnerTestHelper.jsIndexSumIfPlacementishA, + QueryRunnerTestHelper.jsPlacementishCount ) ) .build(); @@ -1288,7 +1289,48 @@ public class TimeseriesQueryRunnerTest new TimeseriesResultValue( ImmutableMap.of( "index", 12459.361190795898d, - "nindex", 283.31103515625d + "nindex", 283.31103515625d, + "pishcount", 52d + ) + ) + ) + ); + Iterable> actualResults = Sequences.toList( + runner.run(query), + Lists.>newArrayList() + ); + TestHelper.assertExpectedResults(expectedResults, actualResults); + } + + @Test + public void testTimeseriesWithMultiValueFilteringJavascriptAggregatorAndAlsoRegularFilters() + { + TimeseriesQuery query = Druids.newTimeseriesQueryBuilder() + .dataSource(QueryRunnerTestHelper.dataSource) + .granularity(QueryRunnerTestHelper.allGran) + .filters(QueryRunnerTestHelper.placementishDimension, "a") + .intervals(QueryRunnerTestHelper.firstToThird) + .aggregators( + ImmutableList.of( + QueryRunnerTestHelper.indexDoubleSum, + QueryRunnerTestHelper.jsIndexSumIfPlacementishA, + QueryRunnerTestHelper.jsPlacementishCount + ) + ) + .build(); + + Iterable> expectedResults = ImmutableList.of( + new Result<>( + new DateTime( + QueryRunnerTestHelper.firstToThird.getIntervals() + .get(0) + .getStart() + ), + new TimeseriesResultValue( + ImmutableMap.of( + "index", 283.31103515625d, + "nindex", 283.31103515625d, + "pishcount", 4d ) ) )