use of org.apache.druid.segment.DimensionSelector in project druid by druid-io.
the class ExpressionVirtualColumnTest method testDimensionSelectorUsingStringFunction.
@Test
public void testDimensionSelectorUsingStringFunction() {
final DimensionSelector selector = Z_CONCAT_X.makeDimensionSelector(new DefaultDimensionSpec("expr", "expr"), COLUMN_SELECTOR_FACTORY);
Assert.assertNotNull(selector);
CURRENT_ROW.set(ROW0);
Assert.assertEquals(1, selector.getRow().size());
Assert.assertEquals(null, selector.lookupName(selector.getRow().get(0)));
CURRENT_ROW.set(ROW1);
Assert.assertEquals(1, selector.getRow().size());
Assert.assertEquals(NullHandling.replaceWithDefault() ? "4" : null, selector.lookupName(selector.getRow().get(0)));
CURRENT_ROW.set(ROW2);
Assert.assertEquals(1, selector.getRow().size());
Assert.assertEquals("foobar2.1", selector.lookupName(selector.getRow().get(0)));
CURRENT_ROW.set(ROW3);
Assert.assertEquals(1, selector.getRow().size());
Assert.assertEquals("foobar2", selector.lookupName(selector.getRow().get(0)));
}
use of org.apache.druid.segment.DimensionSelector in project druid by druid-io.
the class ExpressionVirtualColumnTest method testDimensionSelectorWithExtraction.
@Test
public void testDimensionSelectorWithExtraction() {
final DimensionSelector selector = X_PLUS_Y.makeDimensionSelector(new ExtractionDimensionSpec("expr", "x", new BucketExtractionFn(1.0, 0.0)), 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(true, 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 testDimensionSelectorUsingNonexistentColumn.
@Test
public void testDimensionSelectorUsingNonexistentColumn() {
final DimensionSelector selector = Z_CONCAT_NONEXISTENT.makeDimensionSelector(new DefaultDimensionSpec("expr", "expr"), COLUMN_SELECTOR_FACTORY);
Assert.assertNotNull(selector);
CURRENT_ROW.set(ROW0);
Assert.assertEquals(1, selector.getRow().size());
Assert.assertNull(selector.lookupName(selector.getRow().get(0)));
CURRENT_ROW.set(ROW1);
Assert.assertEquals(1, selector.getRow().size());
Assert.assertNull(selector.lookupName(selector.getRow().get(0)));
CURRENT_ROW.set(ROW2);
Assert.assertEquals(1, selector.getRow().size());
Assert.assertEquals(NullHandling.replaceWithDefault() ? "foobar" : null, selector.lookupName(selector.getRow().get(0)));
CURRENT_ROW.set(ROW3);
Assert.assertEquals(1, selector.getRow().size());
Assert.assertEquals(NullHandling.replaceWithDefault() ? "foobar" : null, selector.lookupName(selector.getRow().get(0)));
}
use of org.apache.druid.segment.DimensionSelector in project druid by druid-io.
the class ListFilteredVirtualColumnSelectorTest method testListFilteredVirtualColumnAllowListDimensionSelector.
@Test
public void testListFilteredVirtualColumnAllowListDimensionSelector() {
ListFilteredVirtualColumn virtualColumn = new ListFilteredVirtualColumn(ALLOW_VIRTUAL_NAME, new DefaultDimensionSpec(COLUMN_NAME, COLUMN_NAME, ColumnType.STRING), ImmutableSet.of("a", "b"), true);
VirtualizedColumnSelectorFactory selectorFactory = makeSelectorFactory(virtualColumn);
DimensionSelector selector = selectorFactory.makeDimensionSelector(DefaultDimensionSpec.of(ALLOW_VIRTUAL_NAME));
Assert.assertEquals(ImmutableList.of("a", "b"), selector.getObject());
assertCapabilities(selectorFactory, ALLOW_VIRTUAL_NAME);
}
use of org.apache.druid.segment.DimensionSelector in project druid by druid-io.
the class VirtualColumnsTest method testMakeSelectorsWithDotSupportBaseNameOnly.
@Test
public void testMakeSelectorsWithDotSupportBaseNameOnly() {
final VirtualColumns virtualColumns = makeVirtualColumns();
final BaseObjectColumnValueSelector objectSelector = virtualColumns.makeColumnValueSelector("foo", null);
final DimensionSelector dimensionSelector = virtualColumns.makeDimensionSelector(new DefaultDimensionSpec("foo", "x"), null);
final BaseFloatColumnValueSelector floatSelector = virtualColumns.makeColumnValueSelector("foo", null);
final BaseLongColumnValueSelector longSelector = virtualColumns.makeColumnValueSelector("foo", null);
Assert.assertEquals(-1L, objectSelector.getObject());
Assert.assertEquals("-1", dimensionSelector.lookupName(dimensionSelector.getRow().get(0)));
Assert.assertEquals(-1.0f, floatSelector.getFloat(), 0.0f);
Assert.assertEquals(-1L, longSelector.getLong());
}
Aggregations