Search in sources :

Example 16 with DimensionSelector

use of io.druid.segment.DimensionSelector in project druid by druid-io.

the class SegmentAnalyzer method analyzeStringColumn.

private ColumnAnalysis analyzeStringColumn(final ColumnCapabilities capabilities, final StorageAdapter storageAdapter, final String columnName) {
    int cardinality = 0;
    long size = 0;
    Comparable min = null;
    Comparable max = null;
    if (analyzingCardinality()) {
        cardinality = storageAdapter.getDimensionCardinality(columnName);
    }
    if (analyzingSize()) {
        final long start = storageAdapter.getMinTime().getMillis();
        final long end = storageAdapter.getMaxTime().getMillis();
        final Sequence<Cursor> cursors = storageAdapter.makeCursors(null, new Interval(start, end), VirtualColumns.EMPTY, Granularities.ALL, false);
        size = cursors.accumulate(0L, new Accumulator<Long, Cursor>() {

            @Override
            public Long accumulate(Long accumulated, Cursor cursor) {
                DimensionSelector selector = cursor.makeDimensionSelector(new DefaultDimensionSpec(columnName, columnName));
                if (selector == null) {
                    return accumulated;
                }
                long current = accumulated;
                while (!cursor.isDone()) {
                    final IndexedInts vals = selector.getRow();
                    for (int i = 0; i < vals.size(); ++i) {
                        final String dimVal = selector.lookupName(vals.get(i));
                        if (dimVal != null && !dimVal.isEmpty()) {
                            current += StringUtils.estimatedBinaryLengthAsUTF8(dimVal);
                        }
                    }
                    cursor.advance();
                }
                return current;
            }
        });
    }
    if (analyzingMinMax()) {
        min = storageAdapter.getMinValue(columnName);
        max = storageAdapter.getMaxValue(columnName);
    }
    return new ColumnAnalysis(capabilities.getType().name(), capabilities.hasMultipleValues(), size, cardinality, min, max, null);
}
Also used : Accumulator(io.druid.java.util.common.guava.Accumulator) DimensionSelector(io.druid.segment.DimensionSelector) Cursor(io.druid.segment.Cursor) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) IndexedInts(io.druid.segment.data.IndexedInts) ColumnAnalysis(io.druid.query.metadata.metadata.ColumnAnalysis) Interval(org.joda.time.Interval)

Example 17 with DimensionSelector

use of io.druid.segment.DimensionSelector in project druid by druid-io.

the class CardinalityAggregatorBenchmark method setUp.

protected void setUp() {
    Iterable<String[]> values = FluentIterable.from(ContiguousSet.create(Range.closedOpen(0, 500), DiscreteDomain.integers())).transform(new Function<Integer, String[]>() {

        @Override
        public String[] apply(Integer input) {
            if (multivaluedSized == 1) {
                return new String[] { input.toString() };
            } else {
                String[] res = new String[multivaluedSized];
                String value = input.toString();
                for (int i = 0; i < multivaluedSized; ++i) {
                    res[i] = value + i;
                }
                return res;
            }
        }
    }).cycle().limit(MAX);
    final DimensionSpec dimSpec1 = new DefaultDimensionSpec("dim1", "dim1");
    final CardinalityAggregatorTest.TestDimensionSelector dim1 = new CardinalityAggregatorTest.TestDimensionSelector(values, null);
    final ColumnSelectorPlus<CardinalityAggregatorColumnSelectorStrategy> dimInfo1 = new ColumnSelectorPlus(dimSpec1.getDimension(), dimSpec1.getOutputName(), new StringCardinalityAggregatorColumnSelectorStrategy(), dim1);
    selectorList = Lists.newArrayList((DimensionSelector) dim1);
    dimInfos = new ColumnSelectorPlus[] { dimInfo1 };
    agg = new CardinalityBufferAggregator(dimInfos, byRow);
    CardinalityAggregatorFactory factory = new CardinalityAggregatorFactory("billy", Lists.<DimensionSpec>newArrayList(new DefaultDimensionSpec("dim1", "dim1")), byRow);
    int maxSize = factory.getMaxIntermediateSize();
    buf = ByteBuffer.allocate(maxSize + 64);
    pos = 10;
    buf.limit(pos + maxSize);
    agg.init(buf, pos);
}
Also used : DimensionSpec(io.druid.query.dimension.DimensionSpec) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) ColumnSelectorPlus(io.druid.query.ColumnSelectorPlus) DimensionSelector(io.druid.segment.DimensionSelector) StringCardinalityAggregatorColumnSelectorStrategy(io.druid.query.aggregation.cardinality.types.StringCardinalityAggregatorColumnSelectorStrategy) CardinalityAggregatorColumnSelectorStrategy(io.druid.query.aggregation.cardinality.types.CardinalityAggregatorColumnSelectorStrategy) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) StringCardinalityAggregatorColumnSelectorStrategy(io.druid.query.aggregation.cardinality.types.StringCardinalityAggregatorColumnSelectorStrategy)

Example 18 with DimensionSelector

use of io.druid.segment.DimensionSelector in project druid by druid-io.

the class IncrementalIndexReadBenchmark method readWithFilters.

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void readWithFilters(Blackhole blackhole) throws Exception {
    DimFilter filter = new OrDimFilter(Arrays.asList(new BoundDimFilter("dimSequential", "-1", "-1", true, true, null, null, StringComparators.ALPHANUMERIC), new JavaScriptDimFilter("dimSequential", "function(x) { return false }", null, JavaScriptConfig.getEnabledInstance()), new RegexDimFilter("dimSequential", "X", null), new SearchQueryDimFilter("dimSequential", new ContainsSearchQuerySpec("X", false), null), new InDimFilter("dimSequential", Arrays.asList("X"), null)));
    IncrementalIndexStorageAdapter sa = new IncrementalIndexStorageAdapter(incIndex);
    Sequence<Cursor> cursors = makeCursors(sa, filter);
    Cursor cursor = Sequences.toList(Sequences.limit(cursors, 1), Lists.<Cursor>newArrayList()).get(0);
    List<DimensionSelector> selectors = new ArrayList<>();
    selectors.add(cursor.makeDimensionSelector(new DefaultDimensionSpec("dimSequential", null)));
    selectors.add(cursor.makeDimensionSelector(new DefaultDimensionSpec("dimZipf", null)));
    selectors.add(cursor.makeDimensionSelector(new DefaultDimensionSpec("dimUniform", null)));
    selectors.add(cursor.makeDimensionSelector(new DefaultDimensionSpec("dimSequentialHalfNull", null)));
    cursor.reset();
    while (!cursor.isDone()) {
        for (DimensionSelector selector : selectors) {
            IndexedInts row = selector.getRow();
            blackhole.consume(selector.lookupName(row.get(0)));
        }
        cursor.advance();
    }
}
Also used : RegexDimFilter(io.druid.query.filter.RegexDimFilter) DimensionSelector(io.druid.segment.DimensionSelector) BoundDimFilter(io.druid.query.filter.BoundDimFilter) ContainsSearchQuerySpec(io.druid.query.search.search.ContainsSearchQuerySpec) ArrayList(java.util.ArrayList) Cursor(io.druid.segment.Cursor) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) IndexedInts(io.druid.segment.data.IndexedInts) OrDimFilter(io.druid.query.filter.OrDimFilter) InDimFilter(io.druid.query.filter.InDimFilter) IncrementalIndexStorageAdapter(io.druid.segment.incremental.IncrementalIndexStorageAdapter) SearchQueryDimFilter(io.druid.query.filter.SearchQueryDimFilter) JavaScriptDimFilter(io.druid.query.filter.JavaScriptDimFilter) JavaScriptDimFilter(io.druid.query.filter.JavaScriptDimFilter) RegexDimFilter(io.druid.query.filter.RegexDimFilter) SearchQueryDimFilter(io.druid.query.filter.SearchQueryDimFilter) BoundDimFilter(io.druid.query.filter.BoundDimFilter) InDimFilter(io.druid.query.filter.InDimFilter) OrDimFilter(io.druid.query.filter.OrDimFilter) DimFilter(io.druid.query.filter.DimFilter) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit)

Example 19 with DimensionSelector

use of io.druid.segment.DimensionSelector in project druid by druid-io.

the class BaseFilterTest method selectColumnValuesMatchingFilterUsingPostFiltering.

private List<String> selectColumnValuesMatchingFilterUsingPostFiltering(final DimFilter filter, final String selectColumn) {
    final Filter theFilter = makeFilter(filter);
    final Filter postFilteringFilter = new Filter() {

        @Override
        public ImmutableBitmap getBitmapIndex(BitmapIndexSelector selector) {
            throw new UnsupportedOperationException();
        }

        @Override
        public ValueMatcher makeMatcher(ColumnSelectorFactory factory) {
            return theFilter.makeMatcher(factory);
        }

        @Override
        public boolean supportsBitmapIndex(BitmapIndexSelector selector) {
            return false;
        }

        @Override
        public boolean supportsSelectivityEstimation(ColumnSelector columnSelector, BitmapIndexSelector indexSelector) {
            return false;
        }

        @Override
        public double estimateSelectivity(BitmapIndexSelector indexSelector) {
            return 1.0;
        }
    };
    final Sequence<Cursor> cursors = makeCursorSequence(postFilteringFilter);
    Sequence<List<String>> seq = Sequences.map(cursors, new Function<Cursor, List<String>>() {

        @Override
        public List<String> apply(Cursor input) {
            final DimensionSelector selector = input.makeDimensionSelector(new DefaultDimensionSpec(selectColumn, selectColumn));
            final List<String> values = Lists.newArrayList();
            while (!input.isDone()) {
                IndexedInts row = selector.getRow();
                Preconditions.checkState(row.size() == 1);
                values.add(selector.lookupName(row.get(0)));
                input.advance();
            }
            return values;
        }
    });
    return Sequences.toList(seq, new ArrayList<List<String>>()).get(0);
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) RowBasedColumnSelectorFactory(io.druid.query.groupby.RowBasedColumnSelectorFactory) ColumnSelectorFactory(io.druid.segment.ColumnSelectorFactory) ArrayList(java.util.ArrayList) Cursor(io.druid.segment.Cursor) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) DimFilter(io.druid.query.filter.DimFilter) Filter(io.druid.query.filter.Filter) ColumnSelector(io.druid.segment.ColumnSelector) IndexedInts(io.druid.segment.data.IndexedInts) BitmapIndexSelector(io.druid.query.filter.BitmapIndexSelector) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList)

Example 20 with DimensionSelector

use of io.druid.segment.DimensionSelector in project druid by druid-io.

the class IncrementalIndexStorageAdapterTest method testResetSanity.

@Test
public void testResetSanity() throws IOException {
    IncrementalIndex index = indexCreator.createIndex();
    DateTime t = DateTime.now();
    Interval interval = new Interval(t.minusMinutes(1), t.plusMinutes(1));
    index.add(new MapBasedInputRow(t.minus(1).getMillis(), Lists.newArrayList("billy"), ImmutableMap.<String, Object>of("billy", "hi")));
    index.add(new MapBasedInputRow(t.minus(1).getMillis(), Lists.newArrayList("sally"), ImmutableMap.<String, Object>of("sally", "bo")));
    IncrementalIndexStorageAdapter adapter = new IncrementalIndexStorageAdapter(index);
    for (boolean descending : Arrays.asList(false, true)) {
        Sequence<Cursor> cursorSequence = adapter.makeCursors(new SelectorFilter("sally", "bo"), interval, VirtualColumns.EMPTY, Granularities.NONE, descending);
        Cursor cursor = Sequences.toList(Sequences.limit(cursorSequence, 1), Lists.<Cursor>newArrayList()).get(0);
        DimensionSelector dimSelector;
        dimSelector = cursor.makeDimensionSelector(new DefaultDimensionSpec("sally", "sally"));
        Assert.assertEquals("bo", dimSelector.lookupName(dimSelector.getRow().get(0)));
        index.add(new MapBasedInputRow(t.minus(1).getMillis(), Lists.newArrayList("sally"), ImmutableMap.<String, Object>of("sally", "ah")));
        // Cursor reset should not be affected by out of order values
        cursor.reset();
        dimSelector = cursor.makeDimensionSelector(new DefaultDimensionSpec("sally", "sally"));
        Assert.assertEquals("bo", dimSelector.lookupName(dimSelector.getRow().get(0)));
    }
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) Cursor(io.druid.segment.Cursor) DateTime(org.joda.time.DateTime) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) SelectorFilter(io.druid.segment.filter.SelectorFilter) MapBasedInputRow(io.druid.data.input.MapBasedInputRow) Interval(org.joda.time.Interval) Test(org.junit.Test)

Aggregations

DimensionSelector (io.druid.segment.DimensionSelector)26 IndexedInts (io.druid.segment.data.IndexedInts)14 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)12 Test (org.junit.Test)11 Cursor (io.druid.segment.Cursor)9 ValueMatcher (io.druid.query.filter.ValueMatcher)5 ObjectColumnSelector (io.druid.segment.ObjectColumnSelector)5 FloatColumnSelector (io.druid.segment.FloatColumnSelector)4 LongColumnSelector (io.druid.segment.LongColumnSelector)4 Interval (org.joda.time.Interval)4 DimensionSpec (io.druid.query.dimension.DimensionSpec)3 ExtractionFn (io.druid.query.extraction.ExtractionFn)3 RuntimeShapeInspector (io.druid.query.monomorphicprocessing.RuntimeShapeInspector)3 TestFloatColumnSelector (io.druid.segment.TestFloatColumnSelector)3 TestLongColumnSelector (io.druid.segment.TestLongColumnSelector)3 VirtualColumns (io.druid.segment.VirtualColumns)3 ByteBuffer (java.nio.ByteBuffer)3 ImmutableList (com.google.common.collect.ImmutableList)2 MapBasedInputRow (io.druid.data.input.MapBasedInputRow)2 ExtractionDimensionSpec (io.druid.query.dimension.ExtractionDimensionSpec)2