use of org.apache.drill.exec.planner.logical.DrillParseContext in project drill by apache.
the class IndexPlanUtils method buildCollationLowerProject.
/**
* Build collation property for the 'lower' project, the one closer to the Scan
* @param projectRexs list of row expressions
* @param input input as a relational expression
* @param indexInfo collects functional index information
* @return the output RelCollation
*/
public static RelCollation buildCollationLowerProject(List<RexNode> projectRexs, RelNode input, FunctionalIndexInfo indexInfo) {
// if leading fields of index are here, add them to RelCollation
List<RelFieldCollation> newFields = Lists.newArrayList();
if (!indexInfo.hasFunctional()) {
Map<LogicalExpression, Integer> projectExprs = Maps.newLinkedHashMap();
DrillParseContext parserContext = new DrillParseContext(PrelUtil.getPlannerSettings(input.getCluster()));
int idx = 0;
for (RexNode rex : projectRexs) {
projectExprs.put(DrillOptiq.toDrill(parserContext, input, rex), idx);
idx++;
}
int idxFieldCount = 0;
for (LogicalExpression expr : indexInfo.getIndexDesc().getIndexColumns()) {
if (!projectExprs.containsKey(expr)) {
break;
}
RelFieldCollation.Direction dir = indexInfo.getIndexDesc().getCollation().getFieldCollations().get(idxFieldCount).direction;
if (dir == null) {
break;
}
newFields.add(new RelFieldCollation(projectExprs.get(expr), dir, RelFieldCollation.NullDirection.UNSPECIFIED));
}
idxFieldCount++;
} else {
// TODO: handle functional index
}
return RelCollations.of(newFields);
}
use of org.apache.drill.exec.planner.logical.DrillParseContext in project drill by apache.
the class NestedLoopJoinPrel method getPhysicalOperator.
@Override
public PhysicalOperator getPhysicalOperator(PhysicalPlanCreator creator) throws IOException {
PhysicalOperator leftPop = ((Prel) left).getPhysicalOperator(creator);
PhysicalOperator rightPop = ((Prel) right).getPhysicalOperator(creator);
/*
Raw expression will be transformed into its logical representation. For example:
Query:
select t1.c1, t2.c1, t2.c2 from t1 inner join t2 on t1.c1 between t2.c1 and t2.c2
Raw expression:
AND(>=($0, $1), <=($0, $2))
Logical expression:
FunctionCall [func=booleanAnd,
args=[FunctionCall [func=greater_than_or_equal_to, args=[`i1`, `i10`]],
FunctionCall [func=less_than_or_equal_to, args=[`i1`, `i2`]]]
Both tables have the same column name thus duplicated column name in second table are renamed: i1 -> i10.
*/
LogicalExpression condition = DrillOptiq.toDrill(new DrillParseContext(PrelUtil.getSettings(getCluster())), getInputs(), getCondition());
NestedLoopJoinPOP nlj = new NestedLoopJoinPOP(leftPop, rightPop, getJoinType(), condition);
return creator.addMetadata(this, nlj);
}
use of org.apache.drill.exec.planner.logical.DrillParseContext 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.logical.DrillParseContext in project drill by axbaretto.
the class PruneScanRule method materializePruneExpr.
protected LogicalExpression materializePruneExpr(RexNode pruneCondition, PlannerSettings settings, RelNode scanRel, VectorContainer container) {
// materialize the expression
logger.debug("Attempting to prune {}", pruneCondition);
final LogicalExpression expr = DrillOptiq.toDrill(new DrillParseContext(settings), scanRel, pruneCondition);
final ErrorCollectorImpl errors = new ErrorCollectorImpl();
LogicalExpression materializedExpr = ExpressionTreeMaterializer.materialize(expr, container, errors, optimizerContext.getFunctionRegistry());
// it's same as the type of output vector.
if (materializedExpr.getMajorType().getMode() == TypeProtos.DataMode.REQUIRED) {
materializedExpr = ExpressionTreeMaterializer.convertToNullableType(materializedExpr, materializedExpr.getMajorType().getMinorType(), optimizerContext.getFunctionRegistry(), errors);
}
if (errors.getErrorCount() != 0) {
logger.warn("Failure while materializing expression [{}]. Errors: {}", expr, errors);
return null;
}
return materializedExpr;
}
use of org.apache.drill.exec.planner.logical.DrillParseContext in project drill by axbaretto.
the class NestedLoopJoinPrel method getPhysicalOperator.
@Override
public PhysicalOperator getPhysicalOperator(PhysicalPlanCreator creator) throws IOException {
PhysicalOperator leftPop = ((Prel) left).getPhysicalOperator(creator);
PhysicalOperator rightPop = ((Prel) right).getPhysicalOperator(creator);
/*
Raw expression will be transformed into its logical representation. For example:
Query:
select t1.c1, t2.c1, t2.c2 from t1 inner join t2 on t1.c1 between t2.c1 and t2.c2
Raw expression:
AND(>=($0, $1), <=($0, $2))
Logical expression:
FunctionCall [func=booleanAnd,
args=[FunctionCall [func=greater_than_or_equal_to, args=[`i1`, `i10`]],
FunctionCall [func=less_than_or_equal_to, args=[`i1`, `i2`]]]
Both tables have the same column name thus duplicated column name in second table are renamed: i1 -> i10.
*/
LogicalExpression condition = DrillOptiq.toDrill(new DrillParseContext(PrelUtil.getSettings(getCluster())), getInputs(), getCondition());
NestedLoopJoinPOP nlj = new NestedLoopJoinPOP(leftPop, rightPop, getJoinType(), condition);
return creator.addMetadata(this, nlj);
}
Aggregations