Search in sources :

Example 1 with VirtualizedColumnSelectorFactory

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

the class ExpressionTestHelper method testFilter.

void testFilter(final SqlOperator op, final List<? extends RexNode> exprs, final List<VirtualColumn> expectedVirtualColumns, final DimFilter expectedFilter, final boolean expectedResult) {
    final RexNode rexNode = rexBuilder.makeCall(op, exprs);
    final VirtualColumnRegistry virtualColumnRegistry = VirtualColumnRegistry.create(rowSignature, TestExprMacroTable.INSTANCE);
    final DimFilter filter = Expressions.toFilter(PLANNER_CONTEXT, rowSignature, virtualColumnRegistry, rexNode);
    Assert.assertEquals("Filter for: " + rexNode, expectedFilter, filter);
    final List<VirtualColumn> virtualColumns = filter.getRequiredColumns().stream().map(virtualColumnRegistry::getVirtualColumn).filter(Objects::nonNull).sorted(Comparator.comparing(VirtualColumn::getOutputName)).collect(Collectors.toList());
    Assert.assertEquals("Virtual columns for: " + rexNode, expectedVirtualColumns.stream().sorted(Comparator.comparing(VirtualColumn::getOutputName)).collect(Collectors.toList()), virtualColumns);
    final ValueMatcher matcher = expectedFilter.toFilter().makeMatcher(new VirtualizedColumnSelectorFactory(RowBasedColumnSelectorFactory.create(RowAdapters.standardRow(), () -> new MapBasedRow(0L, bindings), rowSignature, false), VirtualColumns.create(virtualColumns)));
    Assert.assertEquals("Result for: " + rexNode, expectedResult, matcher.matches());
}
Also used : MapBasedRow(org.apache.druid.data.input.MapBasedRow) VirtualColumnRegistry(org.apache.druid.sql.calcite.rel.VirtualColumnRegistry) ValueMatcher(org.apache.druid.query.filter.ValueMatcher) Objects(java.util.Objects) VirtualColumn(org.apache.druid.segment.VirtualColumn) DimFilter(org.apache.druid.query.filter.DimFilter) VirtualizedColumnSelectorFactory(org.apache.druid.segment.virtual.VirtualizedColumnSelectorFactory) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

Objects (java.util.Objects)1 RexNode (org.apache.calcite.rex.RexNode)1 MapBasedRow (org.apache.druid.data.input.MapBasedRow)1 DimFilter (org.apache.druid.query.filter.DimFilter)1 ValueMatcher (org.apache.druid.query.filter.ValueMatcher)1 VirtualColumn (org.apache.druid.segment.VirtualColumn)1 VirtualizedColumnSelectorFactory (org.apache.druid.segment.virtual.VirtualizedColumnSelectorFactory)1 VirtualColumnRegistry (org.apache.druid.sql.calcite.rel.VirtualColumnRegistry)1