use of io.druid.query.dimension.ExtractionDimensionSpec in project druid by druid-io.
the class TopNQueryRunnerTest method testTopNQueryCardinalityAggregatorWithExtractionFn.
@Test
public void testTopNQueryCardinalityAggregatorWithExtractionFn() {
String helloJsFn = "function(str) { return 'hello' }";
ExtractionFn helloFn = new JavaScriptExtractionFn(helloJsFn, false, JavaScriptConfig.getEnabledInstance());
DimensionSpec dimSpec = new ExtractionDimensionSpec(QueryRunnerTestHelper.marketDimension, QueryRunnerTestHelper.marketDimension, helloFn);
ImmutableList<DimensionSpec> aggregatorDimensionSpecs = ImmutableList.<DimensionSpec>of(new ExtractionDimensionSpec(QueryRunnerTestHelper.qualityDimension, QueryRunnerTestHelper.qualityDimension, helloFn));
TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).dimension(dimSpec).metric(new NumericTopNMetricSpec("numVals")).threshold(10).intervals(QueryRunnerTestHelper.firstToThird).aggregators(duplicateAggregators(new CardinalityAggregatorFactory("numVals", aggregatorDimensionSpecs, false), new CardinalityAggregatorFactory("numVals1", aggregatorDimensionSpecs, false))).build();
List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(new DateTime("2011-04-01T00:00:00.000Z"), new TopNResultValue(withDuplicateResults(Collections.singletonList(ImmutableMap.<String, Object>of("market", "hello", "numVals", 1.0002442201269182d)), "numVals", "numVals1"))));
assertExpectedResults(expectedResults, query);
}
use of io.druid.query.dimension.ExtractionDimensionSpec in project druid by druid-io.
the class TopNQueryRunnerTest method testTopNDimExtractionFastTopNOptimal.
@Test
public // Test a "direct" query
void testTopNDimExtractionFastTopNOptimal() {
TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).dimension(new ExtractionDimensionSpec(QueryRunnerTestHelper.marketDimension, QueryRunnerTestHelper.marketDimension, new LookupExtractionFn(new MapLookupExtractor(ImmutableMap.of("spot", "2spot0", "total_market", "1total_market0", "upfront", "3upfront0"), false), true, null, true, false))).metric("rows").threshold(4).intervals(QueryRunnerTestHelper.firstToThird).aggregators(QueryRunnerTestHelper.commonAggregators).postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant)).build();
List<Result<TopNResultValue>> expectedResults = Arrays.asList(new Result<>(new DateTime("2011-04-01T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.<String, Object>of(QueryRunnerTestHelper.marketDimension, "2spot0", "rows", 18L, "index", 2231.8768157958984D, "addRowsIndexConstant", 2250.8768157958984D, "uniques", QueryRunnerTestHelper.UNIQUES_9), ImmutableMap.<String, Object>of(QueryRunnerTestHelper.marketDimension, "1total_market0", "rows", 4L, "index", 5351.814697265625D, "addRowsIndexConstant", 5356.814697265625D, "uniques", QueryRunnerTestHelper.UNIQUES_2), ImmutableMap.<String, Object>of(QueryRunnerTestHelper.marketDimension, "3upfront0", "rows", 4L, "index", 4875.669677734375D, "addRowsIndexConstant", 4880.669677734375D, "uniques", QueryRunnerTestHelper.UNIQUES_2)))));
assertExpectedResults(expectedResults, query);
}
use of io.druid.query.dimension.ExtractionDimensionSpec in project druid by druid-io.
the class CalciteQueryTest method testCountDistinctOfLookup.
@Test
public void testCountDistinctOfLookup() throws Exception {
final RegisteredLookupExtractionFn extractionFn = new RegisteredLookupExtractionFn(null, "lookyloo", false, null, false, true);
testQuery("SELECT COUNT(DISTINCT LOOKUP(dim1, 'lookyloo')) FROM foo", ImmutableList.<Query>of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(QSS(Filtration.eternity())).granularity(Granularities.ALL).aggregators(AGGS(new CardinalityAggregatorFactory("a0", ImmutableList.<DimensionSpec>of(new ExtractionDimensionSpec("dim1", null, extractionFn)), false))).context(TIMESERIES_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { 2L }));
}
use of io.druid.query.dimension.ExtractionDimensionSpec in project druid by druid-io.
the class ExpressionVirtualColumnTest method testDimensionSelectorWithExtraction.
@Test
public void testDimensionSelectorWithExtraction() {
final DimensionSelector selector = XPLUSY.makeDimensionSelector(new ExtractionDimensionSpec("expr", "x", new BucketExtractionFn(1.0, 0.0)), COLUMN_SELECTOR_FACTORY);
final ValueMatcher nullMatcher = selector.makeValueMatcher((String) null);
final ValueMatcher fiveMatcher = selector.makeValueMatcher("5");
final ValueMatcher nonNullMatcher = selector.makeValueMatcher(Predicates.<String>notNull());
COLUMN_SELECTOR_FACTORY.setRow(ROW0);
Assert.assertEquals(true, nullMatcher.matches());
Assert.assertEquals(false, fiveMatcher.matches());
Assert.assertEquals(false, nonNullMatcher.matches());
Assert.assertEquals(null, selector.lookupName(selector.getRow().get(0)));
COLUMN_SELECTOR_FACTORY.setRow(ROW1);
Assert.assertEquals(true, nullMatcher.matches());
Assert.assertEquals(false, fiveMatcher.matches());
Assert.assertEquals(false, nonNullMatcher.matches());
Assert.assertEquals(null, selector.lookupName(selector.getRow().get(0)));
COLUMN_SELECTOR_FACTORY.setRow(ROW2);
Assert.assertEquals(false, nullMatcher.matches());
Assert.assertEquals(true, fiveMatcher.matches());
Assert.assertEquals(true, nonNullMatcher.matches());
Assert.assertEquals("5", selector.lookupName(selector.getRow().get(0)));
}
Aggregations