Search in sources :

Example 1 with SimpleAscendingOffset

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

the class BroadcastSegmentIndexedTableTest method checkColumnSelectorFactory.

private void checkColumnSelectorFactory(String columnName) {
    try (final Closer closer = Closer.create()) {
        final int numRows = backingSegment.asStorageAdapter().getNumRows();
        final SimpleAscendingOffset offset = new SimpleAscendingOffset(numRows);
        final BaseColumn theColumn = backingSegment.asQueryableIndex().getColumnHolder(columnName).getColumn();
        closer.register(theColumn);
        final BaseObjectColumnValueSelector<?> selector = theColumn.makeColumnValueSelector(offset);
        ColumnSelectorFactory tableFactory = broadcastTable.makeColumnSelectorFactory(offset, false, closer);
        final BaseObjectColumnValueSelector<?> tableSelector = tableFactory.makeColumnValueSelector(columnName);
        // compare with base segment selector to make sure tables selector can read correct values
        for (int row = 0; row < numRows; row++) {
            offset.setCurrentOffset(row);
            Assert.assertEquals(selector.getObject(), tableSelector.getObject());
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : Closer(org.apache.druid.java.util.common.io.Closer) ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) SimpleAscendingOffset(org.apache.druid.segment.SimpleAscendingOffset) BaseColumn(org.apache.druid.segment.column.BaseColumn) IOException(java.io.IOException)

Example 2 with SimpleAscendingOffset

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

the class PredicateValueMatcherFactoryTest method testDimensionProcessorMultiValuedDimensionMatchingValue.

@Test
public void testDimensionProcessorMultiValuedDimensionMatchingValue() {
    // Emulate multi-valued dimension
    final DictionaryEncodedColumnSupplier columnSupplier = new DictionaryEncodedColumnSupplier(GenericIndexed.fromIterable(ImmutableList.of("v1", "v2", "v3"), GenericIndexed.STRING_STRATEGY), GenericIndexed.fromIterable(ImmutableList.of(ByteBuffer.wrap(StringUtils.toUtf8("v1")), ByteBuffer.wrap(StringUtils.toUtf8("v2")), ByteBuffer.wrap(StringUtils.toUtf8("v3"))), GenericIndexed.BYTE_BUFFER_STRATEGY), null, () -> VSizeColumnarMultiInts.fromIterable(ImmutableList.of(VSizeColumnarInts.fromArray(new int[] { 1 }))), 0);
    final ValueMatcher matcher = forSelector("v2").makeDimensionProcessor(columnSupplier.get().makeDimensionSelector(new SimpleAscendingOffset(1), null), true);
    Assert.assertTrue(matcher.matches());
}
Also used : ValueMatcher(org.apache.druid.query.filter.ValueMatcher) DictionaryEncodedColumnSupplier(org.apache.druid.segment.serde.DictionaryEncodedColumnSupplier) SimpleAscendingOffset(org.apache.druid.segment.SimpleAscendingOffset) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 3 with SimpleAscendingOffset

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

the class BaseColumnarLongsBenchmark method setupFilters.

void setupFilters(int rows, double filteredRowCountPercentage, String filterDistribution) {
    final int filteredRowCount = (int) Math.floor(rows * filteredRowCountPercentage);
    if (filteredRowCount < rows) {
        switch(filterDistribution) {
            case "random":
                setupRandomFilter(rows, filteredRowCount);
                break;
            case "contiguous-start":
                offset = new SimpleAscendingOffset(rows);
                vectorOffset = new NoFilterVectorOffset(VECTOR_SIZE, 0, filteredRowCount);
                break;
            case "contiguous-end":
                offset = new SimpleAscendingOffset(rows);
                vectorOffset = new NoFilterVectorOffset(VECTOR_SIZE, rows - filteredRowCount, rows);
                break;
            case "contiguous-bitmap-start":
                setupContiguousBitmapFilter(rows, filteredRowCount, 0);
                break;
            case "contiguous-bitmap-end":
                setupContiguousBitmapFilter(rows, filteredRowCount, rows - filteredRowCount);
                break;
            case "chunky-1000":
                setupChunkyFilter(rows, filteredRowCount, 1000);
                break;
            case "chunky-10000":
                setupChunkyFilter(rows, filteredRowCount, 10000);
                break;
            default:
                throw new IllegalArgumentException("unknown filter distribution");
        }
    } else {
        offset = new SimpleAscendingOffset(rows);
        vectorOffset = new NoFilterVectorOffset(VECTOR_SIZE, 0, rows);
    }
}
Also used : SimpleAscendingOffset(org.apache.druid.segment.SimpleAscendingOffset) NoFilterVectorOffset(org.apache.druid.segment.vector.NoFilterVectorOffset)

Example 4 with SimpleAscendingOffset

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

the class BroadcastSegmentIndexedTableTest method checkNonIndexedReader.

private void checkNonIndexedReader(String columnName) {
    checkColumnSelectorFactory(columnName);
    try (final Closer closer = Closer.create()) {
        final int columnIndex = columnNames.indexOf(columnName);
        final int numRows = backingSegment.asStorageAdapter().getNumRows();
        final IndexedTable.Reader reader = broadcastTable.columnReader(columnIndex);
        closer.register(reader);
        final SimpleAscendingOffset offset = new SimpleAscendingOffset(numRows);
        final BaseColumn theColumn = backingSegment.asQueryableIndex().getColumnHolder(columnName).getColumn();
        closer.register(theColumn);
        final BaseObjectColumnValueSelector<?> selector = theColumn.makeColumnValueSelector(offset);
        // compare with selector make sure reader can read correct values
        for (int row = 0; row < numRows; row++) {
            offset.setCurrentOffset(row);
            Assert.assertEquals(selector.getObject(), reader.read(row));
        }
        // make sure it doesn't have an index since it isn't a key column
        try {
            Assert.assertEquals(null, broadcastTable.columnIndex(columnIndex));
        } catch (IAE iae) {
            Assert.assertEquals(StringUtils.format("Column[%d] is not a key column", columnIndex), iae.getMessage());
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : Closer(org.apache.druid.java.util.common.io.Closer) SimpleAscendingOffset(org.apache.druid.segment.SimpleAscendingOffset) BaseColumn(org.apache.druid.segment.column.BaseColumn) IOException(java.io.IOException) IAE(org.apache.druid.java.util.common.IAE)

Example 5 with SimpleAscendingOffset

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

the class PredicateValueMatcherFactoryTest method testDimensionProcessorMultiValuedDimensionNotMatchingValue.

@Test
public void testDimensionProcessorMultiValuedDimensionNotMatchingValue() {
    // Emulate multi-valued dimension
    final DictionaryEncodedColumnSupplier columnSupplier = new DictionaryEncodedColumnSupplier(GenericIndexed.fromIterable(ImmutableList.of("v1", "v2", "v3"), GenericIndexed.STRING_STRATEGY), GenericIndexed.fromIterable(ImmutableList.of(ByteBuffer.wrap(StringUtils.toUtf8("v1")), ByteBuffer.wrap(StringUtils.toUtf8("v2")), ByteBuffer.wrap(StringUtils.toUtf8("v3"))), GenericIndexed.BYTE_BUFFER_STRATEGY), null, () -> VSizeColumnarMultiInts.fromIterable(ImmutableList.of(VSizeColumnarInts.fromArray(new int[] { 1 }))), 0);
    final ValueMatcher matcher = forSelector("v3").makeDimensionProcessor(columnSupplier.get().makeDimensionSelector(new SimpleAscendingOffset(1), null), true);
    Assert.assertFalse(matcher.matches());
}
Also used : ValueMatcher(org.apache.druid.query.filter.ValueMatcher) DictionaryEncodedColumnSupplier(org.apache.druid.segment.serde.DictionaryEncodedColumnSupplier) SimpleAscendingOffset(org.apache.druid.segment.SimpleAscendingOffset) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

SimpleAscendingOffset (org.apache.druid.segment.SimpleAscendingOffset)6 BaseColumn (org.apache.druid.segment.column.BaseColumn)3 IOException (java.io.IOException)2 IAE (org.apache.druid.java.util.common.IAE)2 Closer (org.apache.druid.java.util.common.io.Closer)2 ValueMatcher (org.apache.druid.query.filter.ValueMatcher)2 DictionaryEncodedColumnSupplier (org.apache.druid.segment.serde.DictionaryEncodedColumnSupplier)2 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)2 Test (org.junit.Test)2 ColumnSelectorFactory (org.apache.druid.segment.ColumnSelectorFactory)1 NoFilterVectorOffset (org.apache.druid.segment.vector.NoFilterVectorOffset)1