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);
}
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();
}
}
}
}
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)));
}
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());
}
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;
}
}
Aggregations