Search in sources :

Example 6 with DimensionSelector

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

the class SettableDimensionValueSelector method setValueFrom.

@Override
public void setValueFrom(ColumnValueSelector<?> selector) {
    DimensionSelector dimensionSelector = (DimensionSelector) selector;
    keptSelector = dimensionSelector;
    IndexedInts row = dimensionSelector.getRow();
    int rowSize = row.size();
    keptRow.ensureSize(rowSize);
    for (int i = 0; i < rowSize; i++) {
        keptRow.setValue(i, row.get(i));
    }
    keptRow.setSize(rowSize);
}
Also used : DimensionSelector(org.apache.druid.segment.DimensionSelector) ArrayBasedIndexedInts(org.apache.druid.segment.data.ArrayBasedIndexedInts) IndexedInts(org.apache.druid.segment.data.IndexedInts)

Example 7 with DimensionSelector

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

the class ListFilteredDimensionSpecDimensionSelectorTest method testAllowList.

private void testAllowList(boolean unknownCardinality, boolean validIdLookup, boolean nameLookupPossibleInAdvance, Class<? extends DimensionSelector> expectedDimensionSelectorClass) {
    RowSupplier rowSupplier = new RowSupplier();
    NonnullPair<Object2IntMap<String>, Int2ObjectMap<String>> dictionaries = createDictionaries(data);
    DimensionSelector selector = targetWithAllowList.decorate(new StringDimensionSelectorForTest(rowSupplier, dictionaries.lhs, dictionaries.rhs, unknownCardinality, validIdLookup, nameLookupPossibleInAdvance));
    Assert.assertSame(expectedDimensionSelectorClass, selector.getClass());
    assertAllowListFiltering(rowSupplier, selector);
}
Also used : DimensionSelector(org.apache.druid.segment.DimensionSelector) Object2IntMap(it.unimi.dsi.fastutil.objects.Object2IntMap) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap)

Example 8 with DimensionSelector

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

the class ListFilteredDimensionSpecDimensionSelectorTest method testDenyList.

private void testDenyList(boolean unknownCardinality, boolean validIdLookup, boolean nameLookupPossibleInAdvance, Class<? extends DimensionSelector> expectedDimensionSelectorClass) {
    RowSupplier rowSupplier = new RowSupplier();
    NonnullPair<Object2IntMap<String>, Int2ObjectMap<String>> dictionaries = createDictionaries(data);
    DimensionSelector selector = targetWithDenyList.decorate(new StringDimensionSelectorForTest(rowSupplier, dictionaries.lhs, dictionaries.rhs, unknownCardinality, validIdLookup, nameLookupPossibleInAdvance));
    Assert.assertSame(expectedDimensionSelectorClass, selector.getClass());
    assertDenyListFiltering(rowSupplier, selector);
}
Also used : DimensionSelector(org.apache.druid.segment.DimensionSelector) Object2IntMap(it.unimi.dsi.fastutil.objects.Object2IntMap) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap)

Example 9 with DimensionSelector

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

the class PrefixFilteredDimensionSpecTest method testDecorator.

@Test
public void testDecorator() {
    PrefixFilteredDimensionSpec spec = new PrefixFilteredDimensionSpec(new DefaultDimensionSpec("foo", "far"), "c");
    DimensionSelector selector = spec.decorate(TestDimensionSelector.INSTANCE);
    Assert.assertEquals(1, selector.getValueCardinality());
    IndexedInts row = selector.getRow();
    Assert.assertEquals(1, row.size());
    Assert.assertEquals(0, row.get(0));
    Assert.assertEquals("c", selector.lookupName(0));
    Assert.assertEquals(0, selector.idLookup().lookupId("c"));
}
Also used : DimensionSelector(org.apache.druid.segment.DimensionSelector) IndexedInts(org.apache.druid.segment.data.IndexedInts) Test(org.junit.Test)

Example 10 with DimensionSelector

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

the class ListFilteredDimensionSpecTest method testDecoratorWithWhitelist.

@Test
public void testDecoratorWithWhitelist() {
    ListFilteredDimensionSpec spec = new ListFilteredDimensionSpec(new DefaultDimensionSpec("foo", "bar"), ImmutableSet.of("c", "g"), true);
    DimensionSelector selector = spec.decorate(TestDimensionSelector.INSTANCE);
    Assert.assertEquals(2, selector.getValueCardinality());
    IndexedInts row = selector.getRow();
    Assert.assertEquals(2, row.size());
    Assert.assertEquals(0, row.get(0));
    Assert.assertEquals(1, row.get(1));
    Assert.assertEquals("c", selector.lookupName(0));
    Assert.assertEquals("g", selector.lookupName(1));
    Assert.assertEquals(0, selector.idLookup().lookupId("c"));
    Assert.assertEquals(1, selector.idLookup().lookupId("g"));
}
Also used : DimensionSelector(org.apache.druid.segment.DimensionSelector) IndexedInts(org.apache.druid.segment.data.IndexedInts) Test(org.junit.Test)

Aggregations

DimensionSelector (org.apache.druid.segment.DimensionSelector)66 Test (org.junit.Test)36 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)31 Cursor (org.apache.druid.segment.Cursor)24 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)24 IndexedInts (org.apache.druid.segment.data.IndexedInts)22 List (java.util.List)14 VirtualColumns (org.apache.druid.segment.VirtualColumns)14 ImmutableList (com.google.common.collect.ImmutableList)12 StorageAdapter (org.apache.druid.segment.StorageAdapter)12 ArrayList (java.util.ArrayList)11 Intervals (org.apache.druid.java.util.common.Intervals)11 Granularities (org.apache.druid.java.util.common.granularity.Granularities)11 Sequence (org.apache.druid.java.util.common.guava.Sequence)11 QueryableIndexStorageAdapter (org.apache.druid.segment.QueryableIndexStorageAdapter)11 NullHandling (org.apache.druid.common.config.NullHandling)10 ColumnSelectorFactory (org.apache.druid.segment.ColumnSelectorFactory)9 DataSegment (org.apache.druid.timeline.DataSegment)9 ConstantDimensionSelector (org.apache.druid.segment.ConstantDimensionSelector)8 ValueMatcher (org.apache.druid.query.filter.ValueMatcher)7