use of org.apache.drill.exec.planner.common.DrillProjectRelBase in project drill by apache.
the class IndexPlanUtils method updateSortExpression.
/**
* generate logical expressions for sort rexNodes in SortRel, the result is store to IndexPlanCallContext
* @param indexContext the index call context
* @param coll list of field collations
*/
public static void updateSortExpression(IndexCallContext indexContext, List<RelFieldCollation> coll) {
if (coll == null) {
return;
}
DrillParseContext parserContext = new DrillParseContext(PrelUtil.getPlannerSettings(indexContext.getCall().rel(0).getCluster()));
indexContext.createSortExprs();
for (RelFieldCollation collation : coll) {
int idx = collation.getFieldIndex();
DrillProjectRelBase oneProject;
if (indexContext.getUpperProject() != null && indexContext.getLowerProject() != null) {
LogicalExpression expr = RexToExpression.toDrill(parserContext, indexContext.getLowerProject(), indexContext.getScan(), indexContext.getUpperProject().getProjects().get(idx));
indexContext.getSortExprs().add(expr);
} else {
// one project is null now
oneProject = (indexContext.getUpperProject() != null) ? indexContext.getUpperProject() : indexContext.getLowerProject();
if (oneProject != null) {
LogicalExpression expr = RexToExpression.toDrill(parserContext, null, indexContext.getScan(), getProjects(oneProject).get(idx));
indexContext.getSortExprs().add(expr);
} else {
// two projects are null
SchemaPath path;
RelDataTypeField f = indexContext.getScan().getRowType().getFieldList().get(idx);
String pathSeg = f.getName().replaceAll("`", "");
final String[] segs = pathSeg.split("\\.");
path = SchemaPath.getCompoundPath(segs);
indexContext.getSortExprs().add(path);
}
}
}
}
use of org.apache.drill.exec.planner.common.DrillProjectRelBase in project drill by apache.
the class FindLimit0Visitor method addLimitOnTopOfLeafNodes.
public static DrillRel addLimitOnTopOfLeafNodes(final DrillRel rel) {
final Pointer<Boolean> isUnsupported = new Pointer<>(false);
// to visit unsupported functions
final RexShuttle unsupportedFunctionsVisitor = new RexShuttle() {
@Override
public RexNode visitCall(RexCall call) {
final SqlOperator operator = call.getOperator();
if (isUnsupportedScalarFunction(operator)) {
isUnsupported.value = true;
return call;
}
return super.visitCall(call);
}
};
// to visit unsupported operators
final RelShuttle unsupportedOperationsVisitor = new RelShuttleImpl() {
@Override
public RelNode visit(RelNode other) {
if (other instanceof DrillUnionRelBase) {
isUnsupported.value = true;
return other;
} else if (other instanceof DrillProjectRelBase) {
if (!isUnsupported.value) {
other.accept(unsupportedFunctionsVisitor);
}
if (isUnsupported.value) {
return other;
}
}
return super.visit(other);
}
};
rel.accept(unsupportedOperationsVisitor);
if (isUnsupported.value) {
return rel;
}
// to add LIMIT (0) on top of leaf nodes
final RelShuttle addLimitOnScanVisitor = new RelShuttleImpl() {
private RelNode addLimitAsParent(RelNode node) {
final RexBuilder builder = node.getCluster().getRexBuilder();
final RexLiteral offset = builder.makeExactLiteral(BigDecimal.ZERO);
final RexLiteral fetch = builder.makeExactLiteral(BigDecimal.ZERO);
return new DrillLimitRel(node.getCluster(), node.getTraitSet(), node, offset, fetch);
}
@Override
public RelNode visit(LogicalValues values) {
return addLimitAsParent(values);
}
@Override
public RelNode visit(TableScan scan) {
return addLimitAsParent(scan);
}
@Override
public RelNode visit(RelNode other) {
if (other.getInputs().isEmpty()) {
// leaf operator
return addLimitAsParent(other);
}
return super.visit(other);
}
};
return (DrillRel) rel.accept(addLimitOnScanVisitor);
}
Aggregations