Search in sources :

Example 16 with ValueMatcher

use of io.druid.query.filter.ValueMatcher in project druid by druid-io.

the class PredicateFilteredDimensionSelector method makeValueMatcher.

@Override
public ValueMatcher makeValueMatcher(final String value) {
    return new ValueMatcher() {

        @Override
        public boolean matches() {
            final IndexedInts baseRow = selector.getRow();
            final int baseRowSize = baseRow.size();
            boolean nullRow = true;
            for (int i = 0; i < baseRowSize; i++) {
                String rowValue = lookupName(baseRow.get(i));
                if (predicate.apply(rowValue)) {
                    if (Objects.equals(rowValue, value)) {
                        return true;
                    }
                    nullRow = false;
                }
            }
            // null should match empty rows in multi-value columns
            return nullRow && value == null;
        }
    };
}
Also used : ValueMatcher(io.druid.query.filter.ValueMatcher) ArrayBasedIndexedInts(io.druid.segment.data.ArrayBasedIndexedInts) IndexedInts(io.druid.segment.data.IndexedInts)

Example 17 with ValueMatcher

use of io.druid.query.filter.ValueMatcher in project druid by druid-io.

the class ExpressionVirtualColumnTest method testDimensionSelector.

@Test
public void testDimensionSelector() {
    final DimensionSelector selector = XPLUSY.makeDimensionSelector(new DefaultDimensionSpec("expr", "x"), COLUMN_SELECTOR_FACTORY);
    final ValueMatcher nullMatcher = selector.makeValueMatcher((String) null);
    final ValueMatcher fiveMatcher = selector.makeValueMatcher("5");
    final ValueMatcher nonNullMatcher = selector.makeValueMatcher(Predicates.<String>notNull());
    COLUMN_SELECTOR_FACTORY.setRow(ROW0);
    Assert.assertEquals(true, nullMatcher.matches());
    Assert.assertEquals(false, fiveMatcher.matches());
    Assert.assertEquals(false, nonNullMatcher.matches());
    Assert.assertEquals(null, selector.lookupName(selector.getRow().get(0)));
    COLUMN_SELECTOR_FACTORY.setRow(ROW1);
    Assert.assertEquals(true, nullMatcher.matches());
    Assert.assertEquals(false, fiveMatcher.matches());
    Assert.assertEquals(false, nonNullMatcher.matches());
    Assert.assertEquals(null, selector.lookupName(selector.getRow().get(0)));
    COLUMN_SELECTOR_FACTORY.setRow(ROW2);
    Assert.assertEquals(false, nullMatcher.matches());
    Assert.assertEquals(false, fiveMatcher.matches());
    Assert.assertEquals(true, nonNullMatcher.matches());
    Assert.assertEquals("5.1", selector.lookupName(selector.getRow().get(0)));
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) ValueMatcher(io.druid.query.filter.ValueMatcher) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 18 with ValueMatcher

use of io.druid.query.filter.ValueMatcher in project druid by druid-io.

the class ExpressionVirtualColumnTest method testDimensionSelectorWithExtraction.

@Test
public void testDimensionSelectorWithExtraction() {
    final DimensionSelector selector = XPLUSY.makeDimensionSelector(new ExtractionDimensionSpec("expr", "x", new BucketExtractionFn(1.0, 0.0)), COLUMN_SELECTOR_FACTORY);
    final ValueMatcher nullMatcher = selector.makeValueMatcher((String) null);
    final ValueMatcher fiveMatcher = selector.makeValueMatcher("5");
    final ValueMatcher nonNullMatcher = selector.makeValueMatcher(Predicates.<String>notNull());
    COLUMN_SELECTOR_FACTORY.setRow(ROW0);
    Assert.assertEquals(true, nullMatcher.matches());
    Assert.assertEquals(false, fiveMatcher.matches());
    Assert.assertEquals(false, nonNullMatcher.matches());
    Assert.assertEquals(null, selector.lookupName(selector.getRow().get(0)));
    COLUMN_SELECTOR_FACTORY.setRow(ROW1);
    Assert.assertEquals(true, nullMatcher.matches());
    Assert.assertEquals(false, fiveMatcher.matches());
    Assert.assertEquals(false, nonNullMatcher.matches());
    Assert.assertEquals(null, selector.lookupName(selector.getRow().get(0)));
    COLUMN_SELECTOR_FACTORY.setRow(ROW2);
    Assert.assertEquals(false, nullMatcher.matches());
    Assert.assertEquals(true, fiveMatcher.matches());
    Assert.assertEquals(true, nonNullMatcher.matches());
    Assert.assertEquals("5", selector.lookupName(selector.getRow().get(0)));
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) BucketExtractionFn(io.druid.query.extraction.BucketExtractionFn) ValueMatcher(io.druid.query.filter.ValueMatcher) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Aggregations

ValueMatcher (io.druid.query.filter.ValueMatcher)18 IndexedInts (io.druid.segment.data.IndexedInts)9 BooleanValueMatcher (io.druid.segment.filter.BooleanValueMatcher)9 DimensionSelector (io.druid.segment.DimensionSelector)5 ArrayBasedIndexedInts (io.druid.segment.data.ArrayBasedIndexedInts)5 ExtractionFn (io.druid.query.extraction.ExtractionFn)4 RuntimeShapeInspector (io.druid.query.monomorphicprocessing.RuntimeShapeInspector)4 Filter (io.druid.query.filter.Filter)3 BitSet (java.util.BitSet)3 Predicate (com.google.common.base.Predicate)2 ImmutableBitmap (io.druid.collections.bitmap.ImmutableBitmap)2 SettableSupplier (io.druid.common.guava.SettableSupplier)2 DimensionSpec (io.druid.query.dimension.DimensionSpec)2 BooleanFilter (io.druid.query.filter.BooleanFilter)2 IdLookup (io.druid.segment.IdLookup)2 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 DateTime (org.joda.time.DateTime)2 Interval (org.joda.time.Interval)2 Test (org.junit.Test)2