Search in sources :

Example 11 with ColumnCapabilitiesImpl

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

the class VectorizedVirtualColumnTest method testGroupByMultiValueString.

@Test
public void testGroupByMultiValueString() {
    // cannot currently group by string columns that might be multi valued
    cannotVectorize();
    testGroupBy(new ColumnCapabilitiesImpl().setType(ColumnType.STRING).setDictionaryEncoded(true).setDictionaryValuesUnique(true).setHasMultipleValues(true));
}
Also used : ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) Test(org.junit.Test)

Example 12 with ColumnCapabilitiesImpl

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

the class StringDimensionIndexer method getColumnCapabilities.

@Override
public ColumnCapabilities getColumnCapabilities() {
    ColumnCapabilitiesImpl capabilites = new ColumnCapabilitiesImpl().setType(ColumnType.STRING).setHasBitmapIndexes(hasBitmapIndexes).setHasSpatialIndexes(hasSpatialIndexes).setDictionaryValuesUnique(true).setDictionaryValuesSorted(false);
    // how to handle this.
    if (hasMultipleValues) {
        capabilites.setHasMultipleValues(true);
    }
    // Likewise, only set dictionaryEncoded if explicitly if true for a similar reason as multi-valued handling. The
    // dictionary is populated as rows are processed, but there might be implicit default values not accounted for in
    // the dictionary yet. We can be certain that the dictionary has an entry for every value if either of
    // a) we have already processed an explitic default (null) valued row for this column
    // b) the processing was not 'sparse', meaning that this indexer has processed an explict value for every row
    // is true.
    final boolean allValuesEncoded = dictionaryEncodesAllValues();
    if (allValuesEncoded) {
        capabilites.setDictionaryEncoded(true);
    }
    if (isSparse || dimLookup.getIdForNull() != DimensionDictionary.ABSENT_VALUE_ID) {
        capabilites.setHasNulls(true);
    }
    return capabilites;
}
Also used : ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl)

Example 13 with ColumnCapabilitiesImpl

use of org.apache.druid.segment.column.ColumnCapabilitiesImpl 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();
            if ("dim".equals(dimensionName)) {
                return dimensionSpec.decorate(new AbstractDimensionSelector() {

                    @Override
                    public IndexedInts getRow() {
                        SingleIndexedInt row = new SingleIndexedInt();
                        if (selector.getIndex() % 3 == 2) {
                            row.setValue(1);
                        } else {
                            row.setValue(0);
                        }
                        return row;
                    }

                    @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 Class classOfObject() {
                        return Object.class;
                    }

                    @Override
                    public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
                    // Don't care about runtime shape in tests
                    }
                });
            } else {
                throw new UnsupportedOperationException();
            }
        }

        @Override
        public ColumnValueSelector<?> makeColumnValueSelector(String columnName) {
            if ("value".equals(columnName)) {
                return selector;
            } else {
                throw new UnsupportedOperationException();
            }
        }

        @Override
        public ColumnCapabilities getColumnCapabilities(String columnName) {
            ColumnCapabilitiesImpl caps;
            if ("value".equals(columnName)) {
                caps = new ColumnCapabilitiesImpl();
                caps.setType(ColumnType.FLOAT);
                caps.setDictionaryEncoded(false);
                caps.setHasBitmapIndexes(false);
            } else {
                caps = new ColumnCapabilitiesImpl();
                caps.setType(ColumnType.STRING);
                caps.setDictionaryEncoded(true);
                caps.setHasBitmapIndexes(true);
            }
            return caps;
        }
    };
}
Also used : DimensionSpec(org.apache.druid.query.dimension.DimensionSpec) ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) ValueMatcher(org.apache.druid.query.filter.ValueMatcher) SingleIndexedInt(org.apache.druid.segment.data.SingleIndexedInt) RuntimeShapeInspector(org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector) IdLookup(org.apache.druid.segment.IdLookup) AbstractDimensionSelector(org.apache.druid.segment.AbstractDimensionSelector) IndexedInts(org.apache.druid.segment.data.IndexedInts) Nullable(javax.annotation.Nullable) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl)

Example 14 with ColumnCapabilitiesImpl

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

the class LongMaxAggregationTest method setup.

@Before
public void setup() {
    NullHandling.initializeForTests();
    selector = new TestLongColumnSelector(values);
    colSelectorFactory = EasyMock.createMock(ColumnSelectorFactory.class);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("nilly")).andReturn(selector);
    EasyMock.expect(colSelectorFactory.getColumnCapabilities("nilly")).andReturn(null);
    EasyMock.replay(colSelectorFactory);
    VectorValueSelector vectorValueSelector = EasyMock.createMock(VectorValueSelector.class);
    EasyMock.expect(vectorValueSelector.getLongVector()).andReturn(longValues1).anyTimes();
    EasyMock.expect(vectorValueSelector.getNullVector()).andReturn(null).anyTimes();
    EasyMock.replay(vectorValueSelector);
    vectorColumnSelectorFactory = EasyMock.createMock(VectorColumnSelectorFactory.class);
    EasyMock.expect(vectorColumnSelectorFactory.getColumnCapabilities("lngFld")).andReturn(new ColumnCapabilitiesImpl().setType(ColumnType.LONG).setDictionaryEncoded(true)).anyTimes();
    EasyMock.expect(vectorColumnSelectorFactory.makeValueSelector("lngFld")).andReturn(vectorValueSelector).anyTimes();
    EasyMock.replay(vectorColumnSelectorFactory);
}
Also used : ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) VectorColumnSelectorFactory(org.apache.druid.segment.vector.VectorColumnSelectorFactory) VectorValueSelector(org.apache.druid.segment.vector.VectorValueSelector) VectorColumnSelectorFactory(org.apache.druid.segment.vector.VectorColumnSelectorFactory) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) Before(org.junit.Before)

Example 15 with ColumnCapabilitiesImpl

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

the class ApproximateHistogramVectorAggregatorTest method setup.

@Before
public void setup() {
    NullHandling.initializeForTests();
    VectorValueSelector vectorValueSelector_1 = createMock(VectorValueSelector.class);
    expect(vectorValueSelector_1.getFloatVector()).andReturn(FLOATS).anyTimes();
    expect(vectorValueSelector_1.getNullVector()).andReturn(NULL_VECTOR).anyTimes();
    VectorValueSelector vectorValueSelector_2 = createMock(VectorValueSelector.class);
    expect(vectorValueSelector_2.getFloatVector()).andReturn(FLOATS).anyTimes();
    expect(vectorValueSelector_2.getNullVector()).andReturn(null).anyTimes();
    EasyMock.replay(vectorValueSelector_1);
    EasyMock.replay(vectorValueSelector_2);
    ColumnCapabilities columnCapabilities = ColumnCapabilitiesImpl.createSimpleNumericColumnCapabilities(ColumnType.DOUBLE);
    vectorColumnSelectorFactory = createMock(VectorColumnSelectorFactory.class);
    expect(vectorColumnSelectorFactory.getColumnCapabilities("field_1")).andReturn(columnCapabilities).anyTimes();
    expect(vectorColumnSelectorFactory.makeValueSelector("field_1")).andReturn(vectorValueSelector_1).anyTimes();
    expect(vectorColumnSelectorFactory.getColumnCapabilities("field_2")).andReturn(columnCapabilities).anyTimes();
    expect(vectorColumnSelectorFactory.makeValueSelector("field_2")).andReturn(vectorValueSelector_2).anyTimes();
    expect(vectorColumnSelectorFactory.getColumnCapabilities("string_field")).andReturn(new ColumnCapabilitiesImpl().setType(ColumnType.STRING));
    expect(vectorColumnSelectorFactory.getColumnCapabilities("complex_field")).andReturn(new ColumnCapabilitiesImpl().setType(ApproximateHistogramAggregatorFactory.TYPE));
    EasyMock.replay(vectorColumnSelectorFactory);
}
Also used : VectorValueSelector(org.apache.druid.segment.vector.VectorValueSelector) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) VectorColumnSelectorFactory(org.apache.druid.segment.vector.VectorColumnSelectorFactory) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) Before(org.junit.Before)

Aggregations

ColumnCapabilitiesImpl (org.apache.druid.segment.column.ColumnCapabilitiesImpl)34 Test (org.junit.Test)20 ColumnSelectorFactory (org.apache.druid.segment.ColumnSelectorFactory)11 Before (org.junit.Before)10 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)9 ColumnCapabilities (org.apache.druid.segment.column.ColumnCapabilities)8 VectorColumnSelectorFactory (org.apache.druid.segment.vector.VectorColumnSelectorFactory)8 VectorValueSelector (org.apache.druid.segment.vector.VectorValueSelector)7 IdLookup (org.apache.druid.segment.IdLookup)5 SingleValueDimensionVectorSelector (org.apache.druid.segment.vector.SingleValueDimensionVectorSelector)4 Nullable (javax.annotation.Nullable)3 ColumnType (org.apache.druid.segment.column.ColumnType)3 ByteBuffer (java.nio.ByteBuffer)2 BufferAggregator (org.apache.druid.query.aggregation.BufferAggregator)2 TestLongColumnSelector (org.apache.druid.query.aggregation.TestLongColumnSelector)2 DimensionSpec (org.apache.druid.query.dimension.DimensionSpec)2 ValueMatcher (org.apache.druid.query.filter.ValueMatcher)2 RuntimeShapeInspector (org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector)2 IndexedInts (org.apache.druid.segment.data.IndexedInts)2 Predicate (com.google.common.base.Predicate)1