use of org.apache.drill.exec.planner.physical.ScanPrel in project drill by apache.
the class ParquetPushDownFilter method doOnMatch.
protected void doOnMatch(RelOptRuleCall call, FilterPrel filter, ProjectPrel project, ScanPrel scan) {
ParquetGroupScan groupScan = (ParquetGroupScan) scan.getGroupScan();
if (groupScan.getFilter() != null && !groupScan.getFilter().equals(ValueExpressions.BooleanExpression.TRUE)) {
return;
}
RexNode condition = null;
if (project == null) {
condition = filter.getCondition();
} else {
// get the filter as if it were below the projection.
condition = RelOptUtil.pushFilterPastProject(filter.getCondition(), project);
}
if (condition == null || condition.equals(ValueExpressions.BooleanExpression.TRUE)) {
return;
}
// get a conjunctions of the filter condition. For each conjunction, if it refers to ITEM or FLATTEN expression
// then we could not pushed down. Otherwise, it's qualified to be pushed down.
final List<RexNode> predList = RelOptUtil.conjunctions(condition);
final List<RexNode> qualifiedPredList = Lists.newArrayList();
for (final RexNode pred : predList) {
if (DrillRelOptUtil.findItemOrFlatten(pred, ImmutableList.<RexNode>of()) == null) {
qualifiedPredList.add(pred);
}
}
final RexNode qualifedPred = RexUtil.composeConjunction(filter.getCluster().getRexBuilder(), qualifiedPredList, true);
if (qualifedPred == null) {
return;
}
LogicalExpression conditionExp = DrillOptiq.toDrill(new DrillParseContext(PrelUtil.getPlannerSettings(call.getPlanner())), scan, qualifedPred);
Stopwatch timer = Stopwatch.createStarted();
final GroupScan newGroupScan = groupScan.applyFilter(conditionExp, optimizerContext, optimizerContext.getFunctionRegistry(), optimizerContext.getPlannerSettings().getOptions());
logger.info("Took {} ms to apply filter on parquet row groups. ", timer.elapsed(TimeUnit.MILLISECONDS));
if (newGroupScan == null) {
return;
}
final ScanPrel newScanRel = ScanPrel.create(scan, scan.getTraitSet(), newGroupScan, scan.getRowType());
RelNode inputRel = newScanRel;
if (project != null) {
inputRel = project.copy(project.getTraitSet(), ImmutableList.of(inputRel));
}
final RelNode newFilter = filter.copy(filter.getTraitSet(), ImmutableList.<RelNode>of(inputRel));
call.transformTo(newFilter);
}
use of org.apache.drill.exec.planner.physical.ScanPrel in project drill by apache.
the class ParquetPushDownFilter method getFilterOnScan.
public static StoragePluginOptimizerRule getFilterOnScan(OptimizerRulesContext optimizerContext) {
return new ParquetPushDownFilter(RelOptHelper.some(FilterPrel.class, RelOptHelper.any(ScanPrel.class)), "ParquetPushDownFilter:Filter_On_Scan", optimizerContext) {
@Override
public boolean matches(RelOptRuleCall call) {
final ScanPrel scan = call.rel(1);
if (scan.getGroupScan() instanceof ParquetGroupScan) {
return super.matches(call);
}
return false;
}
@Override
public void onMatch(RelOptRuleCall call) {
final FilterPrel filterRel = call.rel(0);
final ScanPrel scanRel = call.rel(1);
doOnMatch(call, filterRel, null, scanRel);
}
};
}
Aggregations