Search in sources :

Example 21 with IndexedInts

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

the class RegexFilteredDimensionSpecTest method testDecorator.

@Test
public void testDecorator() {
    RegexFilteredDimensionSpec spec = new RegexFilteredDimensionSpec(new DefaultDimensionSpec("foo", "bar"), "[c,g]");
    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(io.druid.segment.DimensionSelector) IndexedInts(io.druid.segment.data.IndexedInts) Test(org.junit.Test)

Example 22 with IndexedInts

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

the class NullDimensionSelectorTest method testGetRow.

@Test
public void testGetRow() throws Exception {
    IndexedInts row = selector.getRow();
    Assert.assertEquals(1, row.size());
    Assert.assertEquals(0, row.get(0));
    Iterator<Integer> iter = row.iterator();
    Assert.assertEquals(true, iter.hasNext());
    Assert.assertEquals(0, iter.next().intValue());
    Assert.assertEquals(false, iter.hasNext());
}
Also used : IndexedInts(io.druid.segment.data.IndexedInts) Test(org.junit.Test)

Example 23 with IndexedInts

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

the class RowBasedGrouperHelper method getValueSuppliersForDimensions.

@SuppressWarnings("unchecked")
private static Supplier<Comparable>[] getValueSuppliersForDimensions(final ColumnSelectorFactory columnSelectorFactory, final List<DimensionSpec> dimensions, final Map<String, ValueType> rawInputRowSignature) {
    final Supplier[] inputRawSuppliers = new Supplier[dimensions.size()];
    for (int i = 0; i < dimensions.size(); i++) {
        final ColumnValueSelector selector = DimensionHandlerUtils.getColumnValueSelectorFromDimensionSpec(dimensions.get(i), columnSelectorFactory);
        ValueType type = rawInputRowSignature.get(dimensions.get(i).getDimension());
        if (type == null) {
            // Subquery post-aggs aren't added to the rowSignature (see rowSignatureFor() in GroupByQueryHelper) because
            // their types aren't known, so default to String handling.
            type = ValueType.STRING;
        }
        switch(type) {
            case STRING:
                inputRawSuppliers[i] = new Supplier<Comparable>() {

                    @Override
                    public Comparable get() {
                        final String value;
                        IndexedInts index = ((DimensionSelector) selector).getRow();
                        value = index.size() == 0 ? "" : ((DimensionSelector) selector).lookupName(index.get(0));
                        return Strings.nullToEmpty(value);
                    }
                };
                break;
            case LONG:
                inputRawSuppliers[i] = new Supplier<Comparable>() {

                    @Override
                    public Comparable get() {
                        return ((LongColumnSelector) selector).get();
                    }
                };
                break;
            case FLOAT:
                inputRawSuppliers[i] = new Supplier<Comparable>() {

                    @Override
                    public Comparable get() {
                        return ((FloatColumnSelector) selector).get();
                    }
                };
                break;
            default:
                throw new IAE("invalid type: [%s]", type);
        }
    }
    return inputRawSuppliers;
}
Also used : ValueType(io.druid.segment.column.ValueType) IndexedInts(io.druid.segment.data.IndexedInts) Supplier(com.google.common.base.Supplier) IAE(io.druid.java.util.common.IAE) ColumnValueSelector(io.druid.segment.ColumnValueSelector)

Example 24 with IndexedInts

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

the class StringGroupByColumnSelectorStrategy method initColumnValues.

@Override
public void initColumnValues(ColumnValueSelector selector, int columnIndex, Object[] valuess) {
    DimensionSelector dimSelector = (DimensionSelector) selector;
    IndexedInts row = dimSelector.getRow();
    valuess[columnIndex] = row;
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) IndexedInts(io.druid.segment.data.IndexedInts)

Example 25 with IndexedInts

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

the class ForwardingFilteredDimensionSelector method makeValueMatcher.

@Override
public ValueMatcher makeValueMatcher(final String value) {
    IdLookup idLookup = idLookup();
    if (idLookup != null) {
        final int valueId = idLookup.lookupId(value);
        if (valueId >= 0 || value == null) {
            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++) {
                        int forwardedValue = forwardMapping.get(baseRow.get(i));
                        if (forwardedValue >= 0) {
                            // valueId is -1, we don't want to return true from matches().
                            if (forwardedValue == valueId) {
                                return true;
                            }
                            nullRow = false;
                        }
                    }
                    // null should match empty rows in multi-value columns
                    return nullRow && value == null;
                }
            };
        } else {
            return BooleanValueMatcher.of(false);
        }
    } else {
        // Employ precomputed BitSet optimization
        return makeValueMatcher(Predicates.equalTo(value));
    }
}
Also used : IdLookup(io.druid.segment.IdLookup) BooleanValueMatcher(io.druid.segment.filter.BooleanValueMatcher) ValueMatcher(io.druid.query.filter.ValueMatcher) ArrayBasedIndexedInts(io.druid.segment.data.ArrayBasedIndexedInts) IndexedInts(io.druid.segment.data.IndexedInts)

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