Search in sources :

Example 1 with RegisteredLookupExtractionFn

use of io.druid.query.lookup.RegisteredLookupExtractionFn in project druid by druid-io.

the class CalciteQueryTest method testFilterAndGroupByLookup.

@Test
public void testFilterAndGroupByLookup() throws Exception {
    final RegisteredLookupExtractionFn extractionFn = new RegisteredLookupExtractionFn(null, "lookyloo", false, null, false, true);
    testQuery("SELECT LOOKUP(dim1, 'lookyloo'), COUNT(*) FROM foo\n" + "WHERE LOOKUP(dim1, 'lookyloo') <> 'xxx'\n" + "GROUP BY LOOKUP(dim1, 'lookyloo')", ImmutableList.<Query>of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(QSS(Filtration.eternity())).setGranularity(Granularities.ALL).setDimFilter(NOT(SELECTOR("dim1", "xxx", extractionFn))).setDimensions(DIMS(new ExtractionDimensionSpec("dim1", "d0", ValueType.STRING, extractionFn))).setAggregatorSpecs(AGGS(new CountAggregatorFactory("a0"))).setContext(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { "", 5L }, new Object[] { "xabc", 1L }));
}
Also used : CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) RegisteredLookupExtractionFn(io.druid.query.lookup.RegisteredLookupExtractionFn) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 2 with RegisteredLookupExtractionFn

use of io.druid.query.lookup.RegisteredLookupExtractionFn in project druid by druid-io.

the class LookupExtractionOperator method convert.

@Override
public RowExtraction convert(final DruidOperatorTable operatorTable, final PlannerContext plannerContext, final List<String> rowOrder, final RexNode expression) {
    final RexCall call = (RexCall) expression;
    final RowExtraction rex = Expressions.toRowExtraction(operatorTable, plannerContext, rowOrder, call.getOperands().get(0));
    if (rex == null) {
        return null;
    }
    final String lookupName = RexLiteral.stringValue(call.getOperands().get(1));
    final RegisteredLookupExtractionFn extractionFn = new RegisteredLookupExtractionFn(lookupReferencesManager, lookupName, false, null, false, true);
    return RowExtraction.of(rex.getColumn(), ExtractionFns.compose(extractionFn, rex.getExtractionFn()));
}
Also used : RexCall(org.apache.calcite.rex.RexCall) RegisteredLookupExtractionFn(io.druid.query.lookup.RegisteredLookupExtractionFn)

Example 3 with RegisteredLookupExtractionFn

use of io.druid.query.lookup.RegisteredLookupExtractionFn 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 }));
}
Also used : RegisteredLookupExtractionFn(io.druid.query.lookup.RegisteredLookupExtractionFn) CardinalityAggregatorFactory(io.druid.query.aggregation.cardinality.CardinalityAggregatorFactory) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Aggregations

RegisteredLookupExtractionFn (io.druid.query.lookup.RegisteredLookupExtractionFn)3 ExtractionDimensionSpec (io.druid.query.dimension.ExtractionDimensionSpec)2 Test (org.junit.Test)2 CountAggregatorFactory (io.druid.query.aggregation.CountAggregatorFactory)1 CardinalityAggregatorFactory (io.druid.query.aggregation.cardinality.CardinalityAggregatorFactory)1 RexCall (org.apache.calcite.rex.RexCall)1