Search in sources :

Example 16 with DimensionSpec

use of io.druid.query.dimension.DimensionSpec in project druid by druid-io.

the class MultiValuedDimensionTest method testGroupByWithDimFilter.

@Test
public void testGroupByWithDimFilter() throws Exception {
    GroupByQuery query = GroupByQuery.builder().setDataSource("xx").setQuerySegmentSpec(new LegacySegmentSpec("1970/3000")).setGranularity(Granularities.ALL).setDimensions(Lists.<DimensionSpec>newArrayList(new DefaultDimensionSpec("tags", "tags"))).setAggregatorSpecs(Arrays.asList(new AggregatorFactory[] { new CountAggregatorFactory("count") })).setDimFilter(new SelectorDimFilter("tags", "t3", null)).build();
    Sequence<Row> result = helper.runQueryOnSegmentsObjs(ImmutableList.<Segment>of(new QueryableIndexSegment("sid1", queryableIndex), new IncrementalIndexSegment(incrementalIndex, "sid2")), query);
    List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("1970-01-01T00:00:00.000Z", "tags", "t1", "count", 2L), GroupByQueryRunnerTestHelper.createExpectedRow("1970-01-01T00:00:00.000Z", "tags", "t2", "count", 2L), GroupByQueryRunnerTestHelper.createExpectedRow("1970-01-01T00:00:00.000Z", "tags", "t3", "count", 4L), GroupByQueryRunnerTestHelper.createExpectedRow("1970-01-01T00:00:00.000Z", "tags", "t4", "count", 2L), GroupByQueryRunnerTestHelper.createExpectedRow("1970-01-01T00:00:00.000Z", "tags", "t5", "count", 2L));
    TestHelper.assertExpectedObjects(expectedResults, Sequences.toList(result, new ArrayList<Row>()), "");
}
Also used : QueryableIndexSegment(io.druid.segment.QueryableIndexSegment) ListFilteredDimensionSpec(io.druid.query.dimension.ListFilteredDimensionSpec) DimensionSpec(io.druid.query.dimension.DimensionSpec) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) RegexFilteredDimensionSpec(io.druid.query.dimension.RegexFilteredDimensionSpec) IncrementalIndexSegment(io.druid.segment.IncrementalIndexSegment) ArrayList(java.util.ArrayList) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) LegacySegmentSpec(io.druid.query.spec.LegacySegmentSpec) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) GroupByQuery(io.druid.query.groupby.GroupByQuery) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) Row(io.druid.data.input.Row) GroupByQueryRunnerTest(io.druid.query.groupby.GroupByQueryRunnerTest) Test(org.junit.Test)

Example 17 with DimensionSpec

use of io.druid.query.dimension.DimensionSpec in project druid by druid-io.

the class FilteredAggregatorTest method makeColumnSelector.

private ColumnSelectorFactory makeColumnSelector(final TestFloatColumnSelector selector) {
    return new ColumnSelectorFactory() {

        @Override
        public DimensionSelector makeDimensionSelector(DimensionSpec dimensionSpec) {
            final String dimensionName = dimensionSpec.getDimension();
            final ExtractionFn extractionFn = dimensionSpec.getExtractionFn();
            if (dimensionName.equals("dim")) {
                return dimensionSpec.decorate(new DimensionSelector() {

                    @Override
                    public IndexedInts getRow() {
                        if (selector.getIndex() % 3 == 2) {
                            return ArrayBasedIndexedInts.of(new int[] { 1 });
                        } else {
                            return ArrayBasedIndexedInts.of(new int[] { 0 });
                        }
                    }

                    @Override
                    public ValueMatcher makeValueMatcher(String value) {
                        return DimensionSelectorUtils.makeValueMatcherGeneric(this, value);
                    }

                    @Override
                    public ValueMatcher makeValueMatcher(Predicate<String> predicate) {
                        return DimensionSelectorUtils.makeValueMatcherGeneric(this, predicate);
                    }

                    @Override
                    public int getValueCardinality() {
                        return 2;
                    }

                    @Override
                    public String lookupName(int id) {
                        switch(id) {
                            case 0:
                                return "a";
                            case 1:
                                return "b";
                            default:
                                throw new IllegalArgumentException();
                        }
                    }

                    @Override
                    public boolean nameLookupPossibleInAdvance() {
                        return true;
                    }

                    @Nullable
                    @Override
                    public IdLookup idLookup() {
                        return new IdLookup() {

                            @Override
                            public int lookupId(String name) {
                                switch(name) {
                                    case "a":
                                        return 0;
                                    case "b":
                                        return 1;
                                    default:
                                        throw new IllegalArgumentException();
                                }
                            }
                        };
                    }

                    @Override
                    public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
                    }
                });
            } else {
                throw new UnsupportedOperationException();
            }
        }

        @Override
        public LongColumnSelector makeLongColumnSelector(String columnName) {
            throw new UnsupportedOperationException();
        }

        @Override
        public FloatColumnSelector makeFloatColumnSelector(String columnName) {
            if (columnName.equals("value")) {
                return selector;
            } else {
                throw new UnsupportedOperationException();
            }
        }

        @Override
        public ObjectColumnSelector makeObjectColumnSelector(String columnName) {
            throw new UnsupportedOperationException();
        }

        @Override
        public ColumnCapabilities getColumnCapabilities(String columnName) {
            ColumnCapabilitiesImpl caps;
            if (columnName.equals("value")) {
                caps = new ColumnCapabilitiesImpl();
                caps.setType(ValueType.FLOAT);
                caps.setDictionaryEncoded(false);
                caps.setHasBitmapIndexes(false);
            } else {
                caps = new ColumnCapabilitiesImpl();
                caps.setType(ValueType.STRING);
                caps.setDictionaryEncoded(true);
                caps.setHasBitmapIndexes(true);
            }
            return caps;
        }
    };
}
Also used : DimensionSpec(io.druid.query.dimension.DimensionSpec) DimensionSelector(io.druid.segment.DimensionSelector) ColumnSelectorFactory(io.druid.segment.ColumnSelectorFactory) ValueMatcher(io.druid.query.filter.ValueMatcher) RuntimeShapeInspector(io.druid.query.monomorphicprocessing.RuntimeShapeInspector) IdLookup(io.druid.segment.IdLookup) JavaScriptExtractionFn(io.druid.query.extraction.JavaScriptExtractionFn) ExtractionFn(io.druid.query.extraction.ExtractionFn) IndexedInts(io.druid.segment.data.IndexedInts) ArrayBasedIndexedInts(io.druid.segment.data.ArrayBasedIndexedInts) Nullable(javax.annotation.Nullable) ColumnCapabilitiesImpl(io.druid.segment.column.ColumnCapabilitiesImpl)

Example 18 with DimensionSpec

use of io.druid.query.dimension.DimensionSpec in project druid by druid-io.

the class GroupByQueryRunnerFailureTest method testNotEnoughMergeBuffersOnQueryable.

@Test(timeout = 10000)
public void testNotEnoughMergeBuffersOnQueryable() throws IOException {
    expectedException.expect(QueryInterruptedException.class);
    expectedException.expectCause(CoreMatchers.<Throwable>instanceOf(TimeoutException.class));
    final GroupByQuery query = GroupByQuery.builder().setDataSource(new QueryDataSource(GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setInterval(QueryRunnerTestHelper.firstToThird).setGranularity(Granularities.ALL).setDimensions(Lists.<DimensionSpec>newArrayList(new DefaultDimensionSpec("quality", "alias"))).setAggregatorSpecs(Lists.<AggregatorFactory>newArrayList(QueryRunnerTestHelper.rowsCount)).build())).setGranularity(Granularities.ALL).setInterval(QueryRunnerTestHelper.firstToThird).setAggregatorSpecs(Lists.<AggregatorFactory>newArrayList(new LongSumAggregatorFactory("rows", "rows"))).setContext(ImmutableMap.<String, Object>of(QueryContextKeys.TIMEOUT, Integers.valueOf(500))).build();
    GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
}
Also used : DimensionSpec(io.druid.query.dimension.DimensionSpec) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) QueryDataSource(io.druid.query.QueryDataSource) LongSumAggregatorFactory(io.druid.query.aggregation.LongSumAggregatorFactory) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 19 with DimensionSpec

use of io.druid.query.dimension.DimensionSpec in project druid by druid-io.

the class GroupByQueryRunnerFailureTest method testInsufficientResourcesOnBroker.

@Test(timeout = 10000, expected = InsufficientResourcesException.class)
public void testInsufficientResourcesOnBroker() throws IOException {
    final ReferenceCountingResourceHolder<List<ByteBuffer>> holder = mergeBufferPool.takeBatch(1, 10);
    final GroupByQuery query = GroupByQuery.builder().setDataSource(new QueryDataSource(GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setInterval(QueryRunnerTestHelper.firstToThird).setGranularity(Granularities.ALL).setDimensions(Lists.<DimensionSpec>newArrayList(new DefaultDimensionSpec("quality", "alias"))).setAggregatorSpecs(Lists.<AggregatorFactory>newArrayList(QueryRunnerTestHelper.rowsCount)).build())).setGranularity(Granularities.ALL).setInterval(QueryRunnerTestHelper.firstToThird).setAggregatorSpecs(Lists.<AggregatorFactory>newArrayList(new LongSumAggregatorFactory("rows", "rows"))).setContext(ImmutableMap.<String, Object>of(QueryContextKeys.TIMEOUT, Integers.valueOf(500))).build();
    try {
        GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
    } finally {
        holder.close();
    }
}
Also used : DimensionSpec(io.druid.query.dimension.DimensionSpec) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) QueryDataSource(io.druid.query.QueryDataSource) LongSumAggregatorFactory(io.druid.query.aggregation.LongSumAggregatorFactory) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 20 with DimensionSpec

use of io.druid.query.dimension.DimensionSpec in project druid by druid-io.

the class GroupByQueryRunnerTest method testSubqueryWithFirstLast.

@Test
public void testSubqueryWithFirstLast() {
    GroupByQuery subquery = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setQuerySegmentSpec(QueryRunnerTestHelper.fullOnInterval).setDimensions(ImmutableList.<DimensionSpec>of(new DefaultDimensionSpec("market", "market"))).setAggregatorSpecs(ImmutableList.<AggregatorFactory>of(QueryRunnerTestHelper.rowsCount, new LongFirstAggregatorFactory("innerfirst", "index"), new LongLastAggregatorFactory("innerlast", "index"))).setGranularity(QueryRunnerTestHelper.dayGran).setContext(ImmutableMap.<String, Object>of("finalize", true)).build();
    GroupByQuery query = GroupByQuery.builder().setDataSource(subquery).setQuerySegmentSpec(QueryRunnerTestHelper.fullOnInterval).setDimensions(Lists.<DimensionSpec>newArrayList()).setAggregatorSpecs(ImmutableList.<AggregatorFactory>of(new LongFirstAggregatorFactory("first", "innerfirst"), new LongLastAggregatorFactory("last", "innerlast"))).setGranularity(QueryRunnerTestHelper.monthGran).build();
    List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("2011-01-01", "first", 100L, "last", 943L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-02-01", "first", 132L, "last", 1101L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-03-01", "first", 153L, "last", 1063L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "first", 135L, "last", 780L));
    Iterable<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
    TestHelper.assertExpectedObjects(expectedResults, results, "");
}
Also used : LongLastAggregatorFactory(io.druid.query.aggregation.last.LongLastAggregatorFactory) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) RegexFilteredDimensionSpec(io.druid.query.dimension.RegexFilteredDimensionSpec) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) ListFilteredDimensionSpec(io.druid.query.dimension.ListFilteredDimensionSpec) DimensionSpec(io.druid.query.dimension.DimensionSpec) LongFirstAggregatorFactory(io.druid.query.aggregation.first.LongFirstAggregatorFactory) Row(io.druid.data.input.Row) DoubleMaxAggregatorFactory(io.druid.query.aggregation.DoubleMaxAggregatorFactory) LongMaxAggregatorFactory(io.druid.query.aggregation.LongMaxAggregatorFactory) DoubleSumAggregatorFactory(io.druid.query.aggregation.DoubleSumAggregatorFactory) LongFirstAggregatorFactory(io.druid.query.aggregation.first.LongFirstAggregatorFactory) FilteredAggregatorFactory(io.druid.query.aggregation.FilteredAggregatorFactory) JavaScriptAggregatorFactory(io.druid.query.aggregation.JavaScriptAggregatorFactory) CardinalityAggregatorFactory(io.druid.query.aggregation.cardinality.CardinalityAggregatorFactory) LongSumAggregatorFactory(io.druid.query.aggregation.LongSumAggregatorFactory) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) HyperUniquesAggregatorFactory(io.druid.query.aggregation.hyperloglog.HyperUniquesAggregatorFactory) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) LongLastAggregatorFactory(io.druid.query.aggregation.last.LongLastAggregatorFactory) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Aggregations

DimensionSpec (io.druid.query.dimension.DimensionSpec)113 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)85 Test (org.junit.Test)77 Row (io.druid.data.input.Row)65 ExtractionDimensionSpec (io.druid.query.dimension.ExtractionDimensionSpec)61 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)60 ListFilteredDimensionSpec (io.druid.query.dimension.ListFilteredDimensionSpec)59 RegexFilteredDimensionSpec (io.druid.query.dimension.RegexFilteredDimensionSpec)57 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)18 OrderByColumnSpec (io.druid.query.groupby.orderby.OrderByColumnSpec)15 LookupExtractionFn (io.druid.query.lookup.LookupExtractionFn)13 HashMap (java.util.HashMap)13 DateTime (org.joda.time.DateTime)13 Interval (org.joda.time.Interval)13 PostAggregator (io.druid.query.aggregation.PostAggregator)12 CardinalityAggregatorFactory (io.druid.query.aggregation.cardinality.CardinalityAggregatorFactory)11 JavaScriptDimFilter (io.druid.query.filter.JavaScriptDimFilter)11 CountAggregatorFactory (io.druid.query.aggregation.CountAggregatorFactory)10 DefaultLimitSpec (io.druid.query.groupby.orderby.DefaultLimitSpec)10 ISE (io.druid.java.util.common.ISE)9