Search in sources :

Example 1 with ExternalCallExpressionChecker

use of com.facebook.presto.sql.planner.optimizations.ExternalCallExpressionChecker in project presto by prestodb.

the class PlanRemotePojections method apply.

@Override
public Result apply(ProjectNode node, Captures captures, Rule.Context context) {
    if (!node.getLocality().equals(UNKNOWN)) {
        // Already planned
        return Result.empty();
    }
    // Fast check for remote functions
    if (node.getAssignments().getExpressions().stream().noneMatch(expression -> expression.accept(new ExternalCallExpressionChecker(functionAndTypeManager), null))) {
        // No remote function
        return Result.ofPlanNode(new ProjectNode(node.getSourceLocation(), node.getId(), node.getSource(), node.getAssignments(), LOCAL));
    }
    if (!isRemoteFunctionsEnabled(context.getSession())) {
        throw new PrestoException(GENERIC_USER_ERROR, "Remote functions are not enabled");
    }
    List<ProjectionContext> projectionContexts = planRemoteAssignments(node.getAssignments(), context.getVariableAllocator());
    checkState(!projectionContexts.isEmpty(), "Expect non-empty projectionContexts");
    PlanNode rewritten = node.getSource();
    for (ProjectionContext projectionContext : projectionContexts) {
        rewritten = new ProjectNode(node.getSourceLocation(), context.getIdAllocator().getNextId(), rewritten, Assignments.builder().putAll(projectionContext.getProjections()).build(), projectionContext.remote ? REMOTE : LOCAL);
    }
    return Result.ofPlanNode(rewritten);
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) ExternalCallExpressionChecker(com.facebook.presto.sql.planner.optimizations.ExternalCallExpressionChecker) ProjectNode(com.facebook.presto.spi.plan.ProjectNode) PrestoException(com.facebook.presto.spi.PrestoException)

Example 2 with ExternalCallExpressionChecker

use of com.facebook.presto.sql.planner.optimizations.ExternalCallExpressionChecker in project presto by prestodb.

the class RewriteFilterWithExternalFunctionToProject method apply.

@Override
public Result apply(FilterNode node, Captures captures, Context context) {
    if (!node.getPredicate().accept(new ExternalCallExpressionChecker(functionAndTypeManager), null)) {
        // No remote function in predicate
        return Result.empty();
    }
    VariableReferenceExpression predicateVariable = context.getVariableAllocator().newVariable(node.getPredicate());
    Assignments.Builder assignments = Assignments.builder();
    node.getOutputVariables().forEach(variable -> assignments.put(variable, variable));
    Assignments identityAssignments = assignments.build();
    assignments.put(predicateVariable, node.getPredicate());
    return Result.ofPlanNode(new ProjectNode(node.getSourceLocation(), context.getIdAllocator().getNextId(), new FilterNode(node.getSourceLocation(), context.getIdAllocator().getNextId(), new ProjectNode(context.getIdAllocator().getNextId(), node.getSource(), assignments.build()), predicateVariable), identityAssignments, LOCAL));
}
Also used : ExternalCallExpressionChecker(com.facebook.presto.sql.planner.optimizations.ExternalCallExpressionChecker) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) FilterNode(com.facebook.presto.spi.plan.FilterNode) Assignments(com.facebook.presto.spi.plan.Assignments) ProjectNode(com.facebook.presto.spi.plan.ProjectNode)

Aggregations

ProjectNode (com.facebook.presto.spi.plan.ProjectNode)2 ExternalCallExpressionChecker (com.facebook.presto.sql.planner.optimizations.ExternalCallExpressionChecker)2 PrestoException (com.facebook.presto.spi.PrestoException)1 Assignments (com.facebook.presto.spi.plan.Assignments)1 FilterNode (com.facebook.presto.spi.plan.FilterNode)1 PlanNode (com.facebook.presto.spi.plan.PlanNode)1 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)1