Search in sources :

Example 1 with ColumnInspector

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

the class TimeseriesQueryEngine method process.

/**
 * Run a single-segment, single-interval timeseries query on a particular adapter. The query must have been
 * scoped down to a single interval before calling this method.
 */
public Sequence<Result<TimeseriesResultValue>> process(final TimeseriesQuery query, final StorageAdapter adapter) {
    if (adapter == null) {
        throw new SegmentMissingException("Null storage adapter found. Probably trying to issue a query against a segment being memory unmapped.");
    }
    final Filter filter = Filters.convertToCNFFromQueryContext(query, Filters.toFilter(query.getFilter()));
    final Interval interval = Iterables.getOnlyElement(query.getIntervals());
    final Granularity gran = query.getGranularity();
    final boolean descending = query.isDescending();
    final ColumnInspector inspector = query.getVirtualColumns().wrapInspector(adapter);
    final boolean doVectorize = QueryContexts.getVectorize(query).shouldVectorize(adapter.canVectorize(filter, query.getVirtualColumns(), descending) && VirtualColumns.shouldVectorize(query, query.getVirtualColumns(), adapter) && query.getAggregatorSpecs().stream().allMatch(aggregatorFactory -> aggregatorFactory.canVectorize(inspector)));
    final Sequence<Result<TimeseriesResultValue>> result;
    if (doVectorize) {
        result = processVectorized(query, adapter, filter, interval, gran, descending);
    } else {
        result = processNonVectorized(query, adapter, filter, interval, gran, descending);
    }
    final int limit = query.getLimit();
    if (limit < Integer.MAX_VALUE) {
        return result.limit(limit);
    } else {
        return result;
    }
}
Also used : Filter(org.apache.druid.query.filter.Filter) SegmentMissingException(org.apache.druid.segment.SegmentMissingException) ColumnInspector(org.apache.druid.segment.ColumnInspector) Granularity(org.apache.druid.java.util.common.granularity.Granularity) Interval(org.joda.time.Interval) Result(org.apache.druid.query.Result)

Example 2 with ColumnInspector

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

the class ExpressionVectorSelectorsTest method setup.

@Before
public void setup() {
    Expr parsed = Parser.parse(expression, ExprMacroTable.nil());
    outputType = parsed.getOutputType(new ColumnInspector() {

        @Nullable
        @Override
        public ColumnCapabilities getColumnCapabilities(String column) {
            return QueryableIndexStorageAdapter.getColumnCapabilities(INDEX, column);
        }
    });
    if (outputType == null) {
        outputType = ExpressionType.STRING;
    }
}
Also used : Expr(org.apache.druid.math.expr.Expr) ColumnInspector(org.apache.druid.segment.ColumnInspector) Before(org.junit.Before)

Example 3 with ColumnInspector

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

the class VirtualColumnsTest method testGetColumnCapabilitiesWithFallbackNilBase.

@Test
public void testGetColumnCapabilitiesWithFallbackNilBase() {
    final VirtualColumns virtualColumns = makeVirtualColumns();
    final ColumnInspector baseInspector = column -> null;
    Assert.assertEquals(ValueType.FLOAT, virtualColumns.getColumnCapabilitiesWithFallback(baseInspector, "expr").getType());
    Assert.assertEquals(ValueType.LONG, virtualColumns.getColumnCapabilitiesWithFallback(baseInspector, "expr2").getType());
    Assert.assertNull(virtualColumns.getColumnCapabilitiesWithFallback(baseInspector, REAL_COLUMN_NAME));
}
Also used : Arrays(java.util.Arrays) RuntimeShapeInspector(org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector) ExtractionFn(org.apache.druid.query.extraction.ExtractionFn) ColumnValueSelector(org.apache.druid.segment.ColumnValueSelector) IdLookup(org.apache.druid.segment.IdLookup) IndexedInts(org.apache.druid.segment.data.IndexedInts) BaseFloatColumnValueSelector(org.apache.druid.segment.BaseFloatColumnValueSelector) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) ImmutableList(com.google.common.collect.ImmutableList) DimensionSelector(org.apache.druid.segment.DimensionSelector) TestLongColumnSelector(org.apache.druid.segment.TestLongColumnSelector) BucketExtractionFn(org.apache.druid.query.extraction.BucketExtractionFn) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) BaseObjectColumnValueSelector(org.apache.druid.segment.BaseObjectColumnValueSelector) ExpectedException(org.junit.rules.ExpectedException) Nullable(javax.annotation.Nullable) ValueMatcher(org.apache.druid.query.filter.ValueMatcher) ColumnInspector(org.apache.druid.segment.ColumnInspector) Longs(com.google.common.primitives.Longs) VirtualColumns(org.apache.druid.segment.VirtualColumns) VirtualColumn(org.apache.druid.segment.VirtualColumn) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ValueType(org.apache.druid.segment.column.ValueType) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test) TestExprMacroTable(org.apache.druid.query.expression.TestExprMacroTable) DimensionDictionarySelector(org.apache.druid.segment.DimensionDictionarySelector) DimensionSelectorUtils(org.apache.druid.segment.DimensionSelectorUtils) ZeroIndexedInts(org.apache.druid.segment.data.ZeroIndexedInts) TestHelper(org.apache.druid.segment.TestHelper) List(java.util.List) BaseLongColumnValueSelector(org.apache.druid.segment.BaseLongColumnValueSelector) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) Rule(org.junit.Rule) Predicate(com.google.common.base.Predicate) DimensionSpec(org.apache.druid.query.dimension.DimensionSpec) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) ColumnType(org.apache.druid.segment.column.ColumnType) Assert(org.junit.Assert) ColumnInspector(org.apache.druid.segment.ColumnInspector) VirtualColumns(org.apache.druid.segment.VirtualColumns) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 4 with ColumnInspector

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

the class VirtualColumnsTest method testGetColumnCapabilitiesNilBase.

@Test
public void testGetColumnCapabilitiesNilBase() {
    final VirtualColumns virtualColumns = makeVirtualColumns();
    final ColumnInspector baseInspector = column -> null;
    Assert.assertEquals(ValueType.FLOAT, virtualColumns.getColumnCapabilities(baseInspector, "expr").getType());
    Assert.assertEquals(ValueType.LONG, virtualColumns.getColumnCapabilities(baseInspector, "expr2").getType());
    Assert.assertNull(virtualColumns.getColumnCapabilities(baseInspector, REAL_COLUMN_NAME));
}
Also used : Arrays(java.util.Arrays) RuntimeShapeInspector(org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector) ExtractionFn(org.apache.druid.query.extraction.ExtractionFn) ColumnValueSelector(org.apache.druid.segment.ColumnValueSelector) IdLookup(org.apache.druid.segment.IdLookup) IndexedInts(org.apache.druid.segment.data.IndexedInts) BaseFloatColumnValueSelector(org.apache.druid.segment.BaseFloatColumnValueSelector) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) ImmutableList(com.google.common.collect.ImmutableList) DimensionSelector(org.apache.druid.segment.DimensionSelector) TestLongColumnSelector(org.apache.druid.segment.TestLongColumnSelector) BucketExtractionFn(org.apache.druid.query.extraction.BucketExtractionFn) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) BaseObjectColumnValueSelector(org.apache.druid.segment.BaseObjectColumnValueSelector) ExpectedException(org.junit.rules.ExpectedException) Nullable(javax.annotation.Nullable) ValueMatcher(org.apache.druid.query.filter.ValueMatcher) ColumnInspector(org.apache.druid.segment.ColumnInspector) Longs(com.google.common.primitives.Longs) VirtualColumns(org.apache.druid.segment.VirtualColumns) VirtualColumn(org.apache.druid.segment.VirtualColumn) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ValueType(org.apache.druid.segment.column.ValueType) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test) TestExprMacroTable(org.apache.druid.query.expression.TestExprMacroTable) DimensionDictionarySelector(org.apache.druid.segment.DimensionDictionarySelector) DimensionSelectorUtils(org.apache.druid.segment.DimensionSelectorUtils) ZeroIndexedInts(org.apache.druid.segment.data.ZeroIndexedInts) TestHelper(org.apache.druid.segment.TestHelper) List(java.util.List) BaseLongColumnValueSelector(org.apache.druid.segment.BaseLongColumnValueSelector) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) Rule(org.junit.Rule) Predicate(com.google.common.base.Predicate) DimensionSpec(org.apache.druid.query.dimension.DimensionSpec) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) ColumnType(org.apache.druid.segment.column.ColumnType) Assert(org.junit.Assert) ColumnInspector(org.apache.druid.segment.ColumnInspector) VirtualColumns(org.apache.druid.segment.VirtualColumns) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 5 with ColumnInspector

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

the class VirtualColumnsTest method testWrapInspectorNilBase.

@Test
public void testWrapInspectorNilBase() {
    final VirtualColumns virtualColumns = makeVirtualColumns();
    final ColumnInspector baseInspector = column -> null;
    final ColumnInspector wrappedInspector = virtualColumns.wrapInspector(baseInspector);
    Assert.assertEquals(ValueType.FLOAT, wrappedInspector.getColumnCapabilities("expr").getType());
    Assert.assertEquals(ValueType.LONG, wrappedInspector.getColumnCapabilities("expr2").getType());
    Assert.assertNull(wrappedInspector.getColumnCapabilities(REAL_COLUMN_NAME));
}
Also used : Arrays(java.util.Arrays) RuntimeShapeInspector(org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector) ExtractionFn(org.apache.druid.query.extraction.ExtractionFn) ColumnValueSelector(org.apache.druid.segment.ColumnValueSelector) IdLookup(org.apache.druid.segment.IdLookup) IndexedInts(org.apache.druid.segment.data.IndexedInts) BaseFloatColumnValueSelector(org.apache.druid.segment.BaseFloatColumnValueSelector) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) ImmutableList(com.google.common.collect.ImmutableList) DimensionSelector(org.apache.druid.segment.DimensionSelector) TestLongColumnSelector(org.apache.druid.segment.TestLongColumnSelector) BucketExtractionFn(org.apache.druid.query.extraction.BucketExtractionFn) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) BaseObjectColumnValueSelector(org.apache.druid.segment.BaseObjectColumnValueSelector) ExpectedException(org.junit.rules.ExpectedException) Nullable(javax.annotation.Nullable) ValueMatcher(org.apache.druid.query.filter.ValueMatcher) ColumnInspector(org.apache.druid.segment.ColumnInspector) Longs(com.google.common.primitives.Longs) VirtualColumns(org.apache.druid.segment.VirtualColumns) VirtualColumn(org.apache.druid.segment.VirtualColumn) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ValueType(org.apache.druid.segment.column.ValueType) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test) TestExprMacroTable(org.apache.druid.query.expression.TestExprMacroTable) DimensionDictionarySelector(org.apache.druid.segment.DimensionDictionarySelector) DimensionSelectorUtils(org.apache.druid.segment.DimensionSelectorUtils) ZeroIndexedInts(org.apache.druid.segment.data.ZeroIndexedInts) TestHelper(org.apache.druid.segment.TestHelper) List(java.util.List) BaseLongColumnValueSelector(org.apache.druid.segment.BaseLongColumnValueSelector) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) Rule(org.junit.Rule) Predicate(com.google.common.base.Predicate) DimensionSpec(org.apache.druid.query.dimension.DimensionSpec) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) ColumnType(org.apache.druid.segment.column.ColumnType) Assert(org.junit.Assert) ColumnInspector(org.apache.druid.segment.ColumnInspector) VirtualColumns(org.apache.druid.segment.VirtualColumns) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

ColumnInspector (org.apache.druid.segment.ColumnInspector)11 ColumnSelectorFactory (org.apache.druid.segment.ColumnSelectorFactory)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 Longs (com.google.common.primitives.Longs)7 Arrays (java.util.Arrays)7 List (java.util.List)7 Nullable (javax.annotation.Nullable)7 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)7 DimensionSpec (org.apache.druid.query.dimension.DimensionSpec)7 ValueMatcher (org.apache.druid.query.filter.ValueMatcher)7 BaseFloatColumnValueSelector (org.apache.druid.segment.BaseFloatColumnValueSelector)7 BaseLongColumnValueSelector (org.apache.druid.segment.BaseLongColumnValueSelector)7 ColumnValueSelector (org.apache.druid.segment.ColumnValueSelector)7 DimensionSelector (org.apache.druid.segment.DimensionSelector)7 ColumnCapabilities (org.apache.druid.segment.column.ColumnCapabilities)7 ColumnCapabilitiesImpl (org.apache.druid.segment.column.ColumnCapabilitiesImpl)7 ColumnType (org.apache.druid.segment.column.ColumnType)7 ValueType (org.apache.druid.segment.column.ValueType)7 IndexedInts (org.apache.druid.segment.data.IndexedInts)7 Predicate (com.google.common.base.Predicate)6