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);
}
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));
}
Aggregations