@Deprecated public TopNQueryBuilder copy(TopNQueryBuilder builder) { return new TopNQueryBuilder() .dataSource(builder.dataSource) .virtualColumns(builder.virtualColumns) .dimension(builder.dimensionSpec) .metric(builder.topNMetricSpec) .threshold(builder.threshold) .intervals(builder.querySegmentSpec) .filters(builder.dimFilter) .granularity(builder.granularity) .aggregators(builder.aggregatorSpecs) .postAggregators(builder.postAggregatorSpecs) .context(builder.context); }
private TopNQuery makeTopNQuery() { return new TopNQueryBuilder() .dataSource(dataSource) .granularity(allGran) .dimension(marketDimension) .metric(indexMetric) .threshold(3) .intervals(fullOnInterval) .aggregators( Lists.newArrayList( Iterables.concat( commonAggregators, Lists.newArrayList( new DoubleMaxAggregatorFactory("maxIndex", "index"), new DoubleMinAggregatorFactory("minIndex", "index") ) ) ) ) .postAggregators(Collections.singletonList(addRowsIndexConstant)) .build(); }
@Test public void testQuerySerialization() throws IOException { Query query = new TopNQueryBuilder() .dataSource(dataSource) .granularity(allGran) .dimension(marketDimension) .metric(indexMetric) .threshold(4) .intervals(fullOnIntervalSpec) .aggregators( Lists.newArrayList( Iterables.concat( commonDoubleAggregators, Lists.newArrayList( new DoubleMaxAggregatorFactory("maxIndex", "index"), new DoubleMinAggregatorFactory("minIndex", "index") ) ) ) ) .postAggregators(Collections.singletonList(addRowsIndexConstant)) .build(); String json = jsonMapper.writeValueAsString(query); Query serdeQuery = jsonMapper.readValue(json, Query.class); Assert.assertEquals(query, serdeQuery); }
/** See {@link #runTests} */ @SuppressWarnings("unused") private void testFullOnTopN(QueryRunner runner, List<Result<TopNResultValue>> expectedResults, String failMsg) { TopNQuery query = new TopNQueryBuilder() .dataSource(dataSource) .granularity(allGran) .dimension(marketDimension) .metric(indexMetric) .threshold(3) .intervals(fullOnInterval) .aggregators( Lists.newArrayList( Iterables.concat( commonAggregators, Lists.newArrayList( new DoubleMaxAggregatorFactory("maxIndex", "index"), new DoubleMinAggregatorFactory("minIndex", "index") ) ) ) ) .postAggregators(Collections.singletonList(addRowsIndexConstant)) .build(); failMsg += " topN "; HashMap<String, Object> context = new HashMap<>(); Iterable<Result<TopNResultValue>> actualResults = runner.run(QueryPlus.wrap(query), context).toList(); TestHelper.assertExpectedResults(expectedResults, actualResults, failMsg); }
/** See {@link #runTests} */ @SuppressWarnings("unused") private void testFilteredTopN(QueryRunner runner, List<Result<TopNResultValue>> expectedResults, String failMsg) { TopNQuery query = new TopNQueryBuilder() .dataSource(dataSource) .granularity(allGran) .dimension(marketDimension) .filters(marketDimension, "spot") .metric(indexMetric) .threshold(3) .intervals(fullOnInterval) .aggregators( Lists.newArrayList( Iterables.concat( commonAggregators, Lists.newArrayList( new DoubleMaxAggregatorFactory("maxIndex", "index"), new DoubleMinAggregatorFactory("minIndex", "index") ) ) ) ) .postAggregators(Collections.singletonList(addRowsIndexConstant)) .build(); failMsg += " filtered topN "; HashMap<String, Object> context = new HashMap<>(); Iterable<Result<TopNResultValue>> actualResults = runner.run(QueryPlus.wrap(query), context).toList(); TestHelper.assertExpectedResults(expectedResults, actualResults, failMsg); }
.postAggregators(Collections.singletonList(QueryRunnerTestHelper.addRowsIndexConstant)) .build();
.intervals(QueryRunnerTestHelper.firstToThird) .aggregators(commonAggregators) .postAggregators(Collections.singletonList(QueryRunnerTestHelper.addRowsIndexConstant)) .build();
.intervals(QueryRunnerTestHelper.firstToThird) .aggregators(commonAggregators) .postAggregators(Collections.singletonList(QueryRunnerTestHelper.addRowsIndexConstant)) .build();
@Test public void testTopNWithNonExistentFilter() { TopNQuery query = new TopNQueryBuilder() .dataSource(QueryRunnerTestHelper.dataSource) .granularity(QueryRunnerTestHelper.allGran) .filters(QueryRunnerTestHelper.marketDimension, "billyblank") .dimension(QueryRunnerTestHelper.marketDimension) .metric(QueryRunnerTestHelper.indexMetric) .threshold(4) .intervals(QueryRunnerTestHelper.firstToThird) .aggregators(commonAggregators) .postAggregators(Collections.singletonList(QueryRunnerTestHelper.addRowsIndexConstant)) .build(); assertExpectedResults( Collections.singletonList( new Result<>(DateTimes.of("2011-04-01T00:00:00.000Z"), new TopNResultValue(Collections.emptyList())) ), query ); }
.intervals(QueryRunnerTestHelper.firstToThird) .aggregators(commonAggregators) .postAggregators(Collections.singletonList(QueryRunnerTestHelper.addRowsIndexConstant)) .build();
.intervals(QueryRunnerTestHelper.firstToThird) .aggregators(commonAggregators) .postAggregators(Collections.singletonList(QueryRunnerTestHelper.addRowsIndexConstant)) .build();
private TopNQuery makeFilteredTopNQuery() { return new TopNQueryBuilder() .dataSource(dataSource) .granularity(allGran) .dimension(marketDimension) .metric(indexMetric) .threshold(3) .filters( new AndDimFilter( new SelectorDimFilter(marketDimension, "spot", null), new SelectorDimFilter(placementDimension, "preferred", null) ) ) .intervals(fullOnInterval) .aggregators( Lists.newArrayList( Iterables.concat( commonAggregators, Lists.newArrayList( new DoubleMaxAggregatorFactory("maxIndex", "index"), new DoubleMinAggregatorFactory("minIndex", "index") ) ) ) ) .postAggregators(Collections.singletonList(addRowsIndexConstant)) .build(); }
.intervals(QueryRunnerTestHelper.firstToThird) .aggregators(commonAggregators) .postAggregators(Collections.singletonList(QueryRunnerTestHelper.addRowsIndexConstant)) .build();
.granularity(Granularities.ALL) .dimension(new DefaultDimensionSpec("dim1", "d0")) .postAggregators(ImmutableList.of( EXPRESSION_POST_AGG("p0", "substring(\"d0\", 1, -1)") ))
.granularity(Granularities.ALL) .dimension(new DefaultDimensionSpec("dim1", "d0")) .postAggregators(ImmutableList.of( EXPRESSION_POST_AGG("p0", "substring(\"d0\", 1, -1)"), EXPRESSION_POST_AGG("p1", "strlen(\"d0\")")
.intervals(QueryRunnerTestHelper.firstToThird) .aggregators(commonAggregators) .postAggregators(Collections.singletonList(QueryRunnerTestHelper.addRowsIndexConstant)) .build();
.intervals(QueryRunnerTestHelper.firstToThird) .aggregators(commonAggregators) .postAggregators(Collections.singletonList(QueryRunnerTestHelper.addRowsIndexConstant)) .build();
.intervals(QueryRunnerTestHelper.firstToThird) .aggregators(commonAggregators) .postAggregators(Collections.singletonList(QueryRunnerTestHelper.addRowsIndexConstant)) .build(); .intervals(QueryRunnerTestHelper.firstToThird) .aggregators(commonAggregators) .postAggregators(Collections.singletonList(QueryRunnerTestHelper.addRowsIndexConstant)) .build() ).toList(),
@Test public void testTopNWithNonExistentFilterMultiDim() { AndDimFilter andDimFilter = new AndDimFilter( new SelectorDimFilter(QueryRunnerTestHelper.marketDimension, "billyblank", null), new SelectorDimFilter(QueryRunnerTestHelper.qualityDimension, "mezzanine", null) ); TopNQuery query = new TopNQueryBuilder() .dataSource(QueryRunnerTestHelper.dataSource) .granularity(QueryRunnerTestHelper.allGran) .filters(andDimFilter) .dimension(QueryRunnerTestHelper.marketDimension) .metric(QueryRunnerTestHelper.indexMetric) .threshold(4) .intervals(QueryRunnerTestHelper.firstToThird) .aggregators(commonAggregators) .postAggregators(Collections.singletonList(QueryRunnerTestHelper.addRowsIndexConstant)) .build(); assertExpectedResults( Collections.singletonList( new Result<>(DateTimes.of("2011-04-01T00:00:00.000Z"), new TopNResultValue(Collections.emptyList())) ), query ); }
new FloatMaxAggregatorFactory("a1", "m1") )) .postAggregators( ImmutableList.of( EXPRESSION_POST_AGG("p0", "(\"a0\" + \"a1\")")