Search in sources :

Example 16 with DimensionSelector

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

the class ListFilteredVirtualColumnSelectorTest method testListFilteredVirtualColumnDenyListDimensionSelector.

@Test
public void testListFilteredVirtualColumnDenyListDimensionSelector() {
    ListFilteredVirtualColumn virtualColumn = new ListFilteredVirtualColumn(DENY_VIRTUAL_NAME, new DefaultDimensionSpec(COLUMN_NAME, COLUMN_NAME, ColumnType.STRING), ImmutableSet.of("a", "b"), false);
    VirtualizedColumnSelectorFactory selectorFactory = makeSelectorFactory(virtualColumn);
    DimensionSelector selector = selectorFactory.makeDimensionSelector(DefaultDimensionSpec.of(DENY_VIRTUAL_NAME));
    Assert.assertEquals(ImmutableList.of("c", "d"), selector.getObject());
    assertCapabilities(selectorFactory, DENY_VIRTUAL_NAME);
}
Also used : DimensionSelector(org.apache.druid.segment.DimensionSelector) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 17 with DimensionSelector

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

the class ExpressionSelectorsTest method test_multi_value_string_bindings.

@Test
public void test_multi_value_string_bindings() {
    final String columnName = "multi-string3";
    for (StorageAdapter adapter : ADAPTERS) {
        Sequence<Cursor> cursorSequence = adapter.makeCursors(null, adapter.getInterval(), VirtualColumns.EMPTY, Granularities.ALL, false, null);
        List<Cursor> flatten = cursorSequence.toList();
        for (Cursor cursor : flatten) {
            ColumnSelectorFactory factory = cursor.getColumnSelectorFactory();
            // identifier, uses dimension selector supplier supplier, no null coercion
            ExpressionPlan plan = ExpressionPlanner.plan(adapter, Parser.parse("\"multi-string3\"", TestExprMacroTable.INSTANCE));
            // array output, uses object selector supplier, no null coercion
            ExpressionPlan plan2 = ExpressionPlanner.plan(adapter, Parser.parse("array_append(\"multi-string3\", 'foo')", TestExprMacroTable.INSTANCE));
            // array input, uses dimension selector supplier, no null coercion
            ExpressionPlan plan3 = ExpressionPlanner.plan(adapter, Parser.parse("array_length(\"multi-string3\")", TestExprMacroTable.INSTANCE));
            // used as scalar, has null coercion
            ExpressionPlan plan4 = ExpressionPlanner.plan(adapter, Parser.parse("concat(\"multi-string3\", 'foo')", TestExprMacroTable.INSTANCE));
            Expr.ObjectBinding bindings = ExpressionSelectors.createBindings(factory, plan);
            Expr.ObjectBinding bindings2 = ExpressionSelectors.createBindings(factory, plan2);
            Expr.ObjectBinding bindings3 = ExpressionSelectors.createBindings(factory, plan3);
            Expr.ObjectBinding bindings4 = ExpressionSelectors.createBindings(factory, plan4);
            DimensionSelector dimSelector = factory.makeDimensionSelector(DefaultDimensionSpec.of(columnName));
            ColumnValueSelector valueSelector = factory.makeColumnValueSelector(columnName);
            while (!cursor.isDone()) {
                Object dimSelectorVal = dimSelector.getObject();
                Object valueSelectorVal = valueSelector.getObject();
                Object bindingVal = bindings.get(columnName);
                Object bindingVal2 = bindings2.get(columnName);
                Object bindingVal3 = bindings3.get(columnName);
                Object bindingVal4 = bindings4.get(columnName);
                if (dimSelectorVal == null) {
                    Assert.assertNull(dimSelectorVal);
                    Assert.assertNull(valueSelectorVal);
                    Assert.assertNull(bindingVal);
                    Assert.assertNull(bindingVal2);
                    Assert.assertNull(bindingVal3);
                    // binding4 has null coercion
                    Assert.assertArrayEquals(new Object[] { null }, (Object[]) bindingVal4);
                } else {
                    Assert.assertArrayEquals(((List) dimSelectorVal).toArray(), (Object[]) bindingVal);
                    Assert.assertArrayEquals(((List) valueSelectorVal).toArray(), (Object[]) bindingVal);
                    Assert.assertArrayEquals(((List) dimSelectorVal).toArray(), (Object[]) bindingVal2);
                    Assert.assertArrayEquals(((List) valueSelectorVal).toArray(), (Object[]) bindingVal2);
                    Assert.assertArrayEquals(((List) dimSelectorVal).toArray(), (Object[]) bindingVal3);
                    Assert.assertArrayEquals(((List) valueSelectorVal).toArray(), (Object[]) bindingVal3);
                }
                cursor.advance();
            }
        }
    }
}
Also used : BaseSingleValueDimensionSelector(org.apache.druid.segment.BaseSingleValueDimensionSelector) DimensionSelector(org.apache.druid.segment.DimensionSelector) ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) Expr(org.apache.druid.math.expr.Expr) StorageAdapter(org.apache.druid.segment.StorageAdapter) IncrementalIndexStorageAdapter(org.apache.druid.segment.incremental.IncrementalIndexStorageAdapter) QueryableIndexStorageAdapter(org.apache.druid.segment.QueryableIndexStorageAdapter) Cursor(org.apache.druid.segment.Cursor) ColumnValueSelector(org.apache.druid.segment.ColumnValueSelector) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 18 with DimensionSelector

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

the class ExpressionVirtualColumnTest method testDimensionSelector.

@Test
public void testDimensionSelector() {
    final DimensionSelector selector = X_PLUS_Y.makeDimensionSelector(new DefaultDimensionSpec("expr", "expr"), COLUMN_SELECTOR_FACTORY);
    final ValueMatcher nullMatcher = selector.makeValueMatcher((String) null);
    final ValueMatcher fiveMatcher = selector.makeValueMatcher("5");
    final ValueMatcher nonNullMatcher = selector.makeValueMatcher(Predicates.notNull());
    CURRENT_ROW.set(ROW0);
    Assert.assertEquals(true, nullMatcher.matches());
    Assert.assertEquals(false, fiveMatcher.matches());
    Assert.assertEquals(false, nonNullMatcher.matches());
    Assert.assertEquals(null, selector.lookupName(selector.getRow().get(0)));
    CURRENT_ROW.set(ROW1);
    if (NullHandling.replaceWithDefault()) {
        Assert.assertEquals(false, nullMatcher.matches());
        Assert.assertEquals(false, fiveMatcher.matches());
        Assert.assertEquals(true, nonNullMatcher.matches());
        Assert.assertEquals("4", selector.lookupName(selector.getRow().get(0)));
    } else {
        // y is null in row1
        Assert.assertEquals(true, nullMatcher.matches());
        Assert.assertEquals(false, fiveMatcher.matches());
        Assert.assertEquals(false, nonNullMatcher.matches());
        Assert.assertEquals(null, selector.lookupName(selector.getRow().get(0)));
    }
    CURRENT_ROW.set(ROW2);
    Assert.assertEquals(false, nullMatcher.matches());
    Assert.assertEquals(false, fiveMatcher.matches());
    Assert.assertEquals(true, nonNullMatcher.matches());
    Assert.assertEquals("5.1", selector.lookupName(selector.getRow().get(0)));
    CURRENT_ROW.set(ROW3);
    Assert.assertEquals(false, nullMatcher.matches());
    Assert.assertEquals(true, fiveMatcher.matches());
    Assert.assertEquals(true, nonNullMatcher.matches());
    Assert.assertEquals("5", selector.lookupName(selector.getRow().get(0)));
}
Also used : ConstantMultiValueDimensionSelector(org.apache.druid.segment.ConstantMultiValueDimensionSelector) DimensionSelector(org.apache.druid.segment.DimensionSelector) ConstantDimensionSelector(org.apache.druid.segment.ConstantDimensionSelector) ValueMatcher(org.apache.druid.query.filter.ValueMatcher) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 19 with DimensionSelector

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

the class ExpressionVirtualColumnTest method testConstantDimensionSelectors.

@Test
public void testConstantDimensionSelectors() {
    ExpressionVirtualColumn constant = new ExpressionVirtualColumn("constant", Parser.parse("1 + 2", TestExprMacroTable.INSTANCE), ColumnType.LONG);
    DimensionSelector constantSelector = constant.makeDimensionSelector(DefaultDimensionSpec.of("constant"), COLUMN_SELECTOR_FACTORY);
    Assert.assertTrue(constantSelector instanceof ConstantDimensionSelector);
    Assert.assertEquals("3", constantSelector.getObject());
    ExpressionVirtualColumn multiConstant = new ExpressionVirtualColumn("multi", Parser.parse("string_to_array('a,b,c', ',')", TestExprMacroTable.INSTANCE), ColumnType.STRING);
    DimensionSelector multiConstantSelector = multiConstant.makeDimensionSelector(DefaultDimensionSpec.of("multiConstant"), COLUMN_SELECTOR_FACTORY);
    Assert.assertTrue(multiConstantSelector instanceof ConstantMultiValueDimensionSelector);
    Assert.assertEquals(ImmutableList.of("a", "b", "c"), multiConstantSelector.getObject());
}
Also used : ConstantMultiValueDimensionSelector(org.apache.druid.segment.ConstantMultiValueDimensionSelector) DimensionSelector(org.apache.druid.segment.DimensionSelector) ConstantDimensionSelector(org.apache.druid.segment.ConstantDimensionSelector) ConstantMultiValueDimensionSelector(org.apache.druid.segment.ConstantMultiValueDimensionSelector) ConstantDimensionSelector(org.apache.druid.segment.ConstantDimensionSelector) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 20 with DimensionSelector

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

the class DummyStringVirtualColumn method makeDimensionSelector.

@Override
public DimensionSelector makeDimensionSelector(DimensionSpec dimensionSpec, ColumnSelector columnSelector, ReadableOffset offset) {
    if (enableColumnBasedMethods) {
        ColumnHolder holder = columnSelector.getColumnHolder(baseColumnName);
        if (holder == null) {
            return DimensionSelector.constant(null);
        }
        StringDictionaryEncodedColumn stringCol = toStringDictionaryEncodedColumn(holder.getColumn());
        DimensionSelector baseDimensionSelector = stringCol.makeDimensionSelector(offset, dimensionSpec.getExtractionFn());
        if (disableValueMatchers) {
            baseDimensionSelector = disableValueMatchers(baseDimensionSelector);
        }
        return dimensionSpec.decorate(baseDimensionSelector);
    } else {
        return null;
    }
}
Also used : ColumnHolder(org.apache.druid.segment.column.ColumnHolder) DimensionSelector(org.apache.druid.segment.DimensionSelector) StringDictionaryEncodedColumn(org.apache.druid.segment.column.StringDictionaryEncodedColumn)

Aggregations

DimensionSelector (org.apache.druid.segment.DimensionSelector)66 Test (org.junit.Test)36 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)31 Cursor (org.apache.druid.segment.Cursor)24 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)24 IndexedInts (org.apache.druid.segment.data.IndexedInts)22 List (java.util.List)14 VirtualColumns (org.apache.druid.segment.VirtualColumns)14 ImmutableList (com.google.common.collect.ImmutableList)12 StorageAdapter (org.apache.druid.segment.StorageAdapter)12 ArrayList (java.util.ArrayList)11 Intervals (org.apache.druid.java.util.common.Intervals)11 Granularities (org.apache.druid.java.util.common.granularity.Granularities)11 Sequence (org.apache.druid.java.util.common.guava.Sequence)11 QueryableIndexStorageAdapter (org.apache.druid.segment.QueryableIndexStorageAdapter)11 NullHandling (org.apache.druid.common.config.NullHandling)10 ColumnSelectorFactory (org.apache.druid.segment.ColumnSelectorFactory)9 DataSegment (org.apache.druid.timeline.DataSegment)9 ConstantDimensionSelector (org.apache.druid.segment.ConstantDimensionSelector)8 ValueMatcher (org.apache.druid.query.filter.ValueMatcher)7