Search in sources :

Example 26 with IndexedInts

use of io.druid.segment.data.IndexedInts in project druid by druid-io.

the class PredicateFilteredDimensionSelector method getRow.

@Override
public IndexedInts getRow() {
    IndexedInts baseRow = selector.getRow();
    int baseRowSize = baseRow.size();
    int[] result = new int[baseRowSize];
    int resultSize = 0;
    for (int i = 0; i < baseRowSize; i++) {
        if (predicate.apply(selector.lookupName(baseRow.get(i)))) {
            result[resultSize++] = i;
        }
    }
    return ArrayBasedIndexedInts.of(result, resultSize);
}
Also used : ArrayBasedIndexedInts(io.druid.segment.data.ArrayBasedIndexedInts) IndexedInts(io.druid.segment.data.IndexedInts)

Example 27 with IndexedInts

use of io.druid.segment.data.IndexedInts 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 28 with IndexedInts

use of io.druid.segment.data.IndexedInts in project druid by druid-io.

the class StringCardinalityAggregatorColumnSelectorStrategy method hashRow.

@Override
public void hashRow(DimensionSelector dimSelector, Hasher hasher) {
    final IndexedInts row = dimSelector.getRow();
    final int size = row.size();
    // nothing to add to hasher if size == 0, only handle size == 1 and size != 0 cases.
    if (size == 1) {
        final String value = dimSelector.lookupName(row.get(0));
        hasher.putUnencodedChars(nullToSpecial(value));
    } else if (size != 0) {
        final String[] values = new String[size];
        for (int i = 0; i < size; ++i) {
            final String value = dimSelector.lookupName(row.get(i));
            values[i] = nullToSpecial(value);
        }
        // Values need to be sorted to ensure consistent multi-value ordering across different segments
        Arrays.sort(values);
        for (int i = 0; i < size; ++i) {
            if (i != 0) {
                hasher.putChar(CARDINALITY_AGG_SEPARATOR);
            }
            hasher.putUnencodedChars(values[i]);
        }
    }
}
Also used : IndexedInts(io.druid.segment.data.IndexedInts)

Example 29 with IndexedInts

use of io.druid.segment.data.IndexedInts 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 30 with IndexedInts

use of io.druid.segment.data.IndexedInts in project druid by druid-io.

the class MapVirtualColumn method makeObjectColumnSelector.

@Override
public ObjectColumnSelector makeObjectColumnSelector(String dimension, ColumnSelectorFactory factory) {
    final DimensionSelector keySelector = factory.makeDimensionSelector(DefaultDimensionSpec.of(keyDimension));
    final DimensionSelector valueSelector = factory.makeDimensionSelector(DefaultDimensionSpec.of(valueDimension));
    final String subColumnName = VirtualColumns.splitColumnName(dimension).rhs;
    if (subColumnName == null) {
        return new ObjectColumnSelector<Map>() {

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

            @Override
            public Map get() {
                final IndexedInts keyIndices = keySelector.getRow();
                final IndexedInts valueIndices = valueSelector.getRow();
                if (keyIndices == null || valueIndices == null) {
                    return null;
                }
                final int limit = Math.min(keyIndices.size(), valueIndices.size());
                final Map<String, String> map = Maps.newHashMapWithExpectedSize(limit);
                for (int i = 0; i < limit; i++) {
                    map.put(keySelector.lookupName(keyIndices.get(i)), valueSelector.lookupName(valueIndices.get(i)));
                }
                return map;
            }
        };
    }
    IdLookup keyIdLookup = keySelector.idLookup();
    if (keyIdLookup != null) {
        final int keyId = keyIdLookup.lookupId(subColumnName);
        if (keyId < 0) {
            return NullStringObjectColumnSelector.instance();
        }
        return new ObjectColumnSelector<String>() {

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

            @Override
            public String get() {
                final IndexedInts keyIndices = keySelector.getRow();
                final IndexedInts valueIndices = valueSelector.getRow();
                if (keyIndices == null || valueIndices == null) {
                    return null;
                }
                final int limit = Math.min(keyIndices.size(), valueIndices.size());
                for (int i = 0; i < limit; i++) {
                    if (keyIndices.get(i) == keyId) {
                        return valueSelector.lookupName(valueIndices.get(i));
                    }
                }
                return null;
            }
        };
    } else {
        return new ObjectColumnSelector<String>() {

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

            @Override
            public String get() {
                final IndexedInts keyIndices = keySelector.getRow();
                final IndexedInts valueIndices = valueSelector.getRow();
                if (keyIndices == null || valueIndices == null) {
                    return null;
                }
                final int limit = Math.min(keyIndices.size(), valueIndices.size());
                for (int i = 0; i < limit; i++) {
                    if (Objects.equals(keySelector.lookupName(keyIndices.get(i)), subColumnName)) {
                        return valueSelector.lookupName(valueIndices.get(i));
                    }
                }
                return null;
            }
        };
    }
}
Also used : IndexedInts(io.druid.segment.data.IndexedInts) Map(java.util.Map)

Aggregations

IndexedInts (io.druid.segment.data.IndexedInts)41 DimensionSelector (io.druid.segment.DimensionSelector)14 ValueMatcher (io.druid.query.filter.ValueMatcher)9 ArrayBasedIndexedInts (io.druid.segment.data.ArrayBasedIndexedInts)8 Test (org.junit.Test)8 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)6 Cursor (io.druid.segment.Cursor)6 BooleanValueMatcher (io.druid.segment.filter.BooleanValueMatcher)6 ArrayList (java.util.ArrayList)5 ByteBuffer (java.nio.ByteBuffer)3 BitSet (java.util.BitSet)3 Function (com.google.common.base.Function)2 ImmutableList (com.google.common.collect.ImmutableList)2 IAE (io.druid.java.util.common.IAE)2 Aggregator (io.druid.query.aggregation.Aggregator)2 DimFilter (io.druid.query.filter.DimFilter)2 ColumnSelectorFactory (io.druid.segment.ColumnSelectorFactory)2 IdLookup (io.druid.segment.IdLookup)2 CompressedVSizeIntsIndexedSupplier (io.druid.segment.data.CompressedVSizeIntsIndexedSupplier)2 IncrementalIndexTest (io.druid.segment.data.IncrementalIndexTest)2