Search in sources :

Example 1 with DimensionSelector

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

the class IncrementalIndexStorageAdapterTest method testCursoringAndIndexUpdationInterleaving.

@Test
public void testCursoringAndIndexUpdationInterleaving() throws Exception {
    final IncrementalIndex index = indexCreator.createIndex();
    final long timestamp = System.currentTimeMillis();
    for (int i = 0; i < 2; i++) {
        index.add(new MapBasedInputRow(timestamp, Lists.newArrayList("billy"), ImmutableMap.<String, Object>of("billy", "v1" + i)));
    }
    final StorageAdapter sa = new IncrementalIndexStorageAdapter(index);
    Sequence<Cursor> cursors = sa.makeCursors(null, new Interval(timestamp - 60_000, timestamp + 60_000), VirtualColumns.EMPTY, Granularities.ALL, false);
    Sequences.toList(Sequences.map(cursors, new Function<Cursor, Object>() {

        @Nullable
        @Override
        public Object apply(Cursor cursor) {
            DimensionSelector dimSelector = cursor.makeDimensionSelector(new DefaultDimensionSpec("billy", "billy"));
            int cardinality = dimSelector.getValueCardinality();
            //index gets more rows at this point, while other thread is iterating over the cursor
            try {
                for (int i = 0; i < 1; i++) {
                    index.add(new MapBasedInputRow(timestamp, Lists.newArrayList("billy"), ImmutableMap.<String, Object>of("billy", "v2" + i)));
                }
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
            // and then, cursoring continues in the other thread
            while (!cursor.isDone()) {
                IndexedInts row = dimSelector.getRow();
                for (int i : row) {
                    Assert.assertTrue(i < cardinality);
                }
                cursor.advance();
            }
            return null;
        }
    }), new ArrayList<>());
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) StorageAdapter(io.druid.segment.StorageAdapter) Cursor(io.druid.segment.Cursor) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) IOException(java.io.IOException) Function(com.google.common.base.Function) IndexedInts(io.druid.segment.data.IndexedInts) MapBasedInputRow(io.druid.data.input.MapBasedInputRow) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 2 with DimensionSelector

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

the class VirtualColumnsTest method testMakeSelectors.

@Test
public void testMakeSelectors() {
    final VirtualColumns virtualColumns = makeVirtualColumns();
    final ObjectColumnSelector objectSelector = virtualColumns.makeObjectColumnSelector("expr", null);
    final DimensionSelector dimensionSelector = virtualColumns.makeDimensionSelector(new DefaultDimensionSpec("expr", "x"), null);
    final DimensionSelector extractionDimensionSelector = virtualColumns.makeDimensionSelector(new ExtractionDimensionSpec("expr", "x", new BucketExtractionFn(1.0, 0.5)), null);
    final FloatColumnSelector floatSelector = virtualColumns.makeFloatColumnSelector("expr", null);
    final LongColumnSelector longSelector = virtualColumns.makeLongColumnSelector("expr", null);
    Assert.assertEquals(1L, objectSelector.get());
    Assert.assertEquals("1", dimensionSelector.lookupName(dimensionSelector.getRow().get(0)));
    Assert.assertEquals("0.5", extractionDimensionSelector.lookupName(extractionDimensionSelector.getRow().get(0)));
    Assert.assertEquals(1.0f, floatSelector.get(), 0.0f);
    Assert.assertEquals(1L, longSelector.get());
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) BucketExtractionFn(io.druid.query.extraction.BucketExtractionFn) TestLongColumnSelector(io.druid.segment.TestLongColumnSelector) LongColumnSelector(io.druid.segment.LongColumnSelector) TestFloatColumnSelector(io.druid.segment.TestFloatColumnSelector) FloatColumnSelector(io.druid.segment.FloatColumnSelector) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) VirtualColumns(io.druid.segment.VirtualColumns) ObjectColumnSelector(io.druid.segment.ObjectColumnSelector) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 3 with DimensionSelector

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

the class VirtualColumnsTest method testMakeSelectorsWithDotSupport.

@Test
public void testMakeSelectorsWithDotSupport() {
    final VirtualColumns virtualColumns = makeVirtualColumns();
    final ObjectColumnSelector objectSelector = virtualColumns.makeObjectColumnSelector("foo.5", null);
    final DimensionSelector dimensionSelector = virtualColumns.makeDimensionSelector(new DefaultDimensionSpec("foo.5", "x"), null);
    final FloatColumnSelector floatSelector = virtualColumns.makeFloatColumnSelector("foo.5", null);
    final LongColumnSelector longSelector = virtualColumns.makeLongColumnSelector("foo.5", null);
    Assert.assertEquals(5L, objectSelector.get());
    Assert.assertEquals("5", dimensionSelector.lookupName(dimensionSelector.getRow().get(0)));
    Assert.assertEquals(5.0f, floatSelector.get(), 0.0f);
    Assert.assertEquals(5L, longSelector.get());
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) TestLongColumnSelector(io.druid.segment.TestLongColumnSelector) LongColumnSelector(io.druid.segment.LongColumnSelector) TestFloatColumnSelector(io.druid.segment.TestFloatColumnSelector) FloatColumnSelector(io.druid.segment.FloatColumnSelector) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) VirtualColumns(io.druid.segment.VirtualColumns) ObjectColumnSelector(io.druid.segment.ObjectColumnSelector) Test(org.junit.Test)

Example 4 with DimensionSelector

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

the class DumpSegment method makeSelector.

private static ObjectColumnSelector makeSelector(final String columnName, final Column column, final ColumnSelectorFactory columnSelectorFactory) {
    final ObjectColumnSelector selector;
    if (column.getDictionaryEncoding() != null) {
        // Special case for dimensions -> always wrap multi-value in arrays
        final DimensionSelector dimensionSelector = columnSelectorFactory.makeDimensionSelector(new DefaultDimensionSpec(columnName, columnName));
        if (column.getDictionaryEncoding().hasMultipleValues()) {
            return new ObjectColumnSelector<List>() {

                @Override
                public Class<List> classOfObject() {
                    return List.class;
                }

                @Override
                public List<String> get() {
                    final IndexedInts row = dimensionSelector.getRow();
                    if (row.size() == 0) {
                        return null;
                    } else {
                        final List<String> retVal = Lists.newArrayList();
                        for (int i = 0; i < row.size(); i++) {
                            retVal.add(dimensionSelector.lookupName(row.get(i)));
                        }
                        return retVal;
                    }
                }
            };
        } else {
            return new ObjectColumnSelector<String>() {

                @Override
                public Class<String> classOfObject() {
                    return String.class;
                }

                @Override
                public String get() {
                    final IndexedInts row = dimensionSelector.getRow();
                    return row.size() == 0 ? null : dimensionSelector.lookupName(row.get(0));
                }
            };
        }
    } else {
        final ObjectColumnSelector maybeSelector = columnSelectorFactory.makeObjectColumnSelector(columnName);
        if (maybeSelector != null) {
            selector = maybeSelector;
        } else {
            // Selector failed to create (unrecognized column type?)
            log.warn("Could not create selector for column[%s], returning null.", columnName);
            selector = new ObjectColumnSelector() {

                @Override
                public Class classOfObject() {
                    return Object.class;
                }

                @Override
                public Object get() {
                    return null;
                }
            };
        }
    }
    return selector;
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) IndexedInts(io.druid.segment.data.IndexedInts) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) ObjectColumnSelector(io.druid.segment.ObjectColumnSelector)

Example 5 with DimensionSelector

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

the class IncrementalIndexReadBenchmark method read.

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void read(Blackhole blackhole) throws Exception {
    IncrementalIndexStorageAdapter sa = new IncrementalIndexStorageAdapter(incIndex);
    Sequence<Cursor> cursors = makeCursors(sa, null);
    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 : DimensionSelector(io.druid.segment.DimensionSelector) IndexedInts(io.druid.segment.data.IndexedInts) IncrementalIndexStorageAdapter(io.druid.segment.incremental.IncrementalIndexStorageAdapter) ArrayList(java.util.ArrayList) Cursor(io.druid.segment.Cursor) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit)

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