Search in sources :

Example 1 with ColumnsFilter

use of org.apache.druid.data.input.ColumnsFilter in project druid by druid-io.

the class InputRowSchemasTest method test_createColumnsFilter_normal.

@Test
public void test_createColumnsFilter_normal() {
    final ColumnsFilter columnsFilter = InputRowSchemas.createColumnsFilter(new TimestampSpec("ts", "auto", null), new DimensionsSpec(ImmutableList.of(StringDimensionSchema.create("foo"))), new TransformSpec(new SelectorDimFilter("bar", "x", null), ImmutableList.of(new ExpressionTransform("baz", "qux + 3", ExprMacroTable.nil()))), new AggregatorFactory[] { new LongSumAggregatorFactory("billy", "bob") });
    Assert.assertEquals(ColumnsFilter.inclusionBased(ImmutableSet.of("ts", "foo", "bar", "qux", "bob")), columnsFilter);
}
Also used : SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) TimestampSpec(org.apache.druid.data.input.impl.TimestampSpec) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) ColumnsFilter(org.apache.druid.data.input.ColumnsFilter) DimensionsSpec(org.apache.druid.data.input.impl.DimensionsSpec) ExpressionTransform(org.apache.druid.segment.transform.ExpressionTransform) TransformSpec(org.apache.druid.segment.transform.TransformSpec) Test(org.junit.Test) NullHandlingTest(org.apache.druid.common.config.NullHandlingTest)

Example 2 with ColumnsFilter

use of org.apache.druid.data.input.ColumnsFilter in project druid by druid-io.

the class InputRowSchemasTest method test_createColumnsFilter_schemaless.

@Test
public void test_createColumnsFilter_schemaless() {
    final ColumnsFilter columnsFilter = InputRowSchemas.createColumnsFilter(new TimestampSpec("ts", "auto", null), DimensionsSpec.builder().setDimensionExclusions(ImmutableList.of("ts", "foo", "bar", "qux", "bob")).build(), new TransformSpec(new SelectorDimFilter("bar", "x", null), ImmutableList.of(new ExpressionTransform("baz", "qux + 3", ExprMacroTable.nil()))), new AggregatorFactory[] { new LongSumAggregatorFactory("billy", "bob") });
    Assert.assertEquals(ColumnsFilter.exclusionBased(ImmutableSet.of("foo")), columnsFilter);
}
Also used : SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) TimestampSpec(org.apache.druid.data.input.impl.TimestampSpec) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) ColumnsFilter(org.apache.druid.data.input.ColumnsFilter) ExpressionTransform(org.apache.druid.segment.transform.ExpressionTransform) TransformSpec(org.apache.druid.segment.transform.TransformSpec) Test(org.junit.Test) NullHandlingTest(org.apache.druid.common.config.NullHandlingTest)

Example 3 with ColumnsFilter

use of org.apache.druid.data.input.ColumnsFilter in project druid by druid-io.

the class DruidSegmentReader method intermediateRowIterator.

@Override
protected CloseableIterator<Map<String, Object>> intermediateRowIterator() throws IOException {
    final CleanableFile segmentFile = source.fetch(temporaryDirectory, null);
    final WindowedStorageAdapter storageAdapter = new WindowedStorageAdapter(new QueryableIndexStorageAdapter(indexIO.loadIndex(segmentFile.file())), source.getIntervalFilter());
    final Sequence<Cursor> cursors = storageAdapter.getAdapter().makeCursors(Filters.toFilter(dimFilter), storageAdapter.getInterval(), VirtualColumns.EMPTY, Granularities.ALL, false, null);
    // Retain order of columns from the original segments. Useful for preserving dimension order if we're in
    // schemaless mode.
    final Set<String> columnsToRead = Sets.newLinkedHashSet(Iterables.filter(storageAdapter.getAdapter().getRowSignature().getColumnNames(), columnsFilter::apply));
    final Sequence<Map<String, Object>> sequence = Sequences.concat(Sequences.map(cursors, cursor -> cursorToSequence(cursor, columnsToRead)));
    return makeCloseableIteratorFromSequenceAndSegmentFile(sequence, segmentFile);
}
Also used : TimestampSpec(org.apache.druid.data.input.impl.TimestampSpec) IndexedInts(org.apache.druid.segment.data.IndexedInts) ColumnProcessors(org.apache.druid.segment.ColumnProcessors) BaseFloatColumnValueSelector(org.apache.druid.segment.BaseFloatColumnValueSelector) Map(java.util.Map) CloseableIterator(org.apache.druid.java.util.common.parsers.CloseableIterator) BaseObjectColumnValueSelector(org.apache.druid.segment.BaseObjectColumnValueSelector) Sequence(org.apache.druid.java.util.common.guava.Sequence) ColumnsFilter(org.apache.druid.data.input.ColumnsFilter) Set(java.util.Set) Sets(com.google.common.collect.Sets) InputRow(org.apache.druid.data.input.InputRow) List(java.util.List) IntermediateRowParsingReader(org.apache.druid.data.input.IntermediateRowParsingReader) DimFilter(org.apache.druid.query.filter.DimFilter) Entry(java.util.Map.Entry) BaseDoubleColumnValueSelector(org.apache.druid.segment.BaseDoubleColumnValueSelector) Iterables(com.google.common.collect.Iterables) ParseException(org.apache.druid.java.util.common.parsers.ParseException) Supplier(com.google.common.base.Supplier) CollectionUtils(org.apache.druid.utils.CollectionUtils) InputRowSchema(org.apache.druid.data.input.InputRowSchema) ArrayList(java.util.ArrayList) Yielders(org.apache.druid.java.util.common.guava.Yielders) CleanableFile(org.apache.druid.data.input.InputEntity.CleanableFile) DimensionSelector(org.apache.druid.segment.DimensionSelector) Yielder(org.apache.druid.java.util.common.guava.Yielder) NoSuchElementException(java.util.NoSuchElementException) Sequences(org.apache.druid.java.util.common.guava.Sequences) QueryableIndexStorageAdapter(org.apache.druid.segment.QueryableIndexStorageAdapter) VirtualColumns(org.apache.druid.segment.VirtualColumns) Iterator(java.util.Iterator) MapInputRowParser(org.apache.druid.data.input.impl.MapInputRowParser) WindowedStorageAdapter(org.apache.druid.segment.realtime.firehose.WindowedStorageAdapter) DimensionsSpec(org.apache.druid.data.input.impl.DimensionsSpec) IOException(java.io.IOException) ColumnProcessorFactory(org.apache.druid.segment.ColumnProcessorFactory) File(java.io.File) Granularities(org.apache.druid.java.util.common.granularity.Granularities) BaseLongColumnValueSelector(org.apache.druid.segment.BaseLongColumnValueSelector) Cursor(org.apache.druid.segment.Cursor) ColumnType(org.apache.druid.segment.column.ColumnType) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) InputEntity(org.apache.druid.data.input.InputEntity) IndexIO(org.apache.druid.segment.IndexIO) Filters(org.apache.druid.segment.filter.Filters) CloseableUtils(org.apache.druid.utils.CloseableUtils) Collections(java.util.Collections) QueryableIndexStorageAdapter(org.apache.druid.segment.QueryableIndexStorageAdapter) CleanableFile(org.apache.druid.data.input.InputEntity.CleanableFile) Cursor(org.apache.druid.segment.Cursor) WindowedStorageAdapter(org.apache.druid.segment.realtime.firehose.WindowedStorageAdapter) Map(java.util.Map)

Aggregations

ColumnsFilter (org.apache.druid.data.input.ColumnsFilter)3 TimestampSpec (org.apache.druid.data.input.impl.TimestampSpec)3 NullHandlingTest (org.apache.druid.common.config.NullHandlingTest)2 DimensionsSpec (org.apache.druid.data.input.impl.DimensionsSpec)2 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)2 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)2 ExpressionTransform (org.apache.druid.segment.transform.ExpressionTransform)2 TransformSpec (org.apache.druid.segment.transform.TransformSpec)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Supplier (com.google.common.base.Supplier)1 Iterables (com.google.common.collect.Iterables)1 Sets (com.google.common.collect.Sets)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 List (java.util.List)1