Search in sources :

Example 6 with ValueMatcher

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

the class OrFilter method makeMatcher.

@Override
public ValueMatcher makeMatcher(BitmapIndexSelector selector, ColumnSelectorFactory columnSelectorFactory, RowOffsetMatcherFactory rowOffsetMatcherFactory) {
    final List<ValueMatcher> matchers = new ArrayList<>();
    final List<ImmutableBitmap> bitmaps = new ArrayList<>();
    for (Filter filter : filters) {
        if (filter.supportsBitmapIndex(selector)) {
            bitmaps.add(filter.getBitmapIndex(selector));
        } else {
            ValueMatcher matcher = filter.makeMatcher(columnSelectorFactory);
            matchers.add(matcher);
        }
    }
    if (bitmaps.size() > 0) {
        ImmutableBitmap combinedBitmap = selector.getBitmapFactory().union(bitmaps);
        ValueMatcher offsetMatcher = rowOffsetMatcherFactory.makeRowOffsetMatcher(combinedBitmap);
        matchers.add(0, offsetMatcher);
    }
    return new ValueMatcher() {

        @Override
        public boolean matches() {
            for (ValueMatcher valueMatcher : matchers) {
                if (valueMatcher.matches()) {
                    return true;
                }
            }
            return false;
        }
    };
}
Also used : ValueMatcher(io.druid.query.filter.ValueMatcher) ImmutableBitmap(io.druid.collections.bitmap.ImmutableBitmap) BooleanFilter(io.druid.query.filter.BooleanFilter) Filter(io.druid.query.filter.Filter) ArrayList(java.util.ArrayList)

Example 7 with ValueMatcher

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

the class AndFilter method makeMatcher.

@Override
public ValueMatcher makeMatcher(BitmapIndexSelector selector, ColumnSelectorFactory columnSelectorFactory, RowOffsetMatcherFactory rowOffsetMatcherFactory) {
    final List<ValueMatcher> matchers = new ArrayList<>();
    final List<ImmutableBitmap> bitmaps = new ArrayList<>();
    for (Filter filter : filters) {
        if (filter.supportsBitmapIndex(selector)) {
            bitmaps.add(filter.getBitmapIndex(selector));
        } else {
            ValueMatcher matcher = filter.makeMatcher(columnSelectorFactory);
            matchers.add(matcher);
        }
    }
    if (bitmaps.size() > 0) {
        ImmutableBitmap combinedBitmap = selector.getBitmapFactory().intersection(bitmaps);
        ValueMatcher offsetMatcher = rowOffsetMatcherFactory.makeRowOffsetMatcher(combinedBitmap);
        matchers.add(0, offsetMatcher);
    }
    return new ValueMatcher() {

        @Override
        public boolean matches() {
            for (ValueMatcher valueMatcher : matchers) {
                if (!valueMatcher.matches()) {
                    return false;
                }
            }
            return true;
        }
    };
}
Also used : ValueMatcher(io.druid.query.filter.ValueMatcher) ImmutableBitmap(io.druid.collections.bitmap.ImmutableBitmap) BooleanFilter(io.druid.query.filter.BooleanFilter) Filter(io.druid.query.filter.Filter) ArrayList(java.util.ArrayList)

Example 8 with ValueMatcher

use of io.druid.query.filter.ValueMatcher 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 9 with ValueMatcher

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

the class BaseFilterTest method selectColumnValuesMatchingFilterUsingRowBasedColumnSelectorFactory.

private List<String> selectColumnValuesMatchingFilterUsingRowBasedColumnSelectorFactory(final DimFilter filter, final String selectColumn) {
    // Generate rowType
    final Map<String, ValueType> rowSignature = Maps.newHashMap();
    for (String columnName : Iterables.concat(adapter.getAvailableDimensions(), adapter.getAvailableMetrics())) {
        rowSignature.put(columnName, adapter.getColumnCapabilities(columnName).getType());
    }
    // Perform test
    final SettableSupplier<InputRow> rowSupplier = new SettableSupplier<>();
    final ValueMatcher matcher = makeFilter(filter).makeMatcher(VIRTUAL_COLUMNS.wrap(RowBasedColumnSelectorFactory.create(rowSupplier, rowSignature)));
    final List<String> values = Lists.newArrayList();
    for (InputRow row : rows) {
        rowSupplier.set(row);
        if (matcher.matches()) {
            values.add((String) row.getRaw(selectColumn));
        }
    }
    return values;
}
Also used : SettableSupplier(io.druid.common.guava.SettableSupplier) ValueMatcher(io.druid.query.filter.ValueMatcher) ValueType(io.druid.segment.column.ValueType) InputRow(io.druid.data.input.InputRow)

Example 10 with ValueMatcher

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

the class DimensionSelectorUtils method makeNonDictionaryEncodedValueMatcherGeneric.

private static ValueMatcher makeNonDictionaryEncodedValueMatcherGeneric(final DimensionSelector selector, final Predicate<String> predicate) {
    final boolean matchNull = predicate.apply(null);
    return new ValueMatcher() {

        @Override
        public boolean matches() {
            final IndexedInts row = selector.getRow();
            final int size = row.size();
            if (size == 0) {
                // null should match empty rows in multi-value columns
                return matchNull;
            } else {
                for (int i = 0; i < size; ++i) {
                    if (predicate.apply(selector.lookupName(row.get(i)))) {
                        return true;
                    }
                }
                return false;
            }
        }
    };
}
Also used : ValueMatcher(io.druid.query.filter.ValueMatcher) BooleanValueMatcher(io.druid.segment.filter.BooleanValueMatcher) IndexedInts(io.druid.segment.data.IndexedInts)

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