use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.
the class RewriteAggregationIfToFilter method canUnwrapIf.
private boolean canUnwrapIf(SpecialFormExpression ifExpression, AggregationIfToFilterRewriteStrategy rewriteStrategy) {
if (rewriteStrategy == FILTER_WITH_IF) {
return false;
}
// Some use cases use IF expression to avoid returning errors when evaluating the true branch. For example, IF(CARDINALITY(array) > 0, array[1])).
// We shouldn't unwrap the IF for those cases.
// But if the condition expression doesn't reference any variables referenced in the true branch, unwrapping the if should not cause exceptions for the true branch.
Set<VariableReferenceExpression> ifConditionReferences = VariablesExtractor.extractUnique(ifExpression.getArguments().get(0));
Set<VariableReferenceExpression> ifResultReferences = VariablesExtractor.extractUnique(ifExpression.getArguments().get(1));
if (ifConditionReferences.stream().noneMatch(ifResultReferences::contains)) {
return true;
}
if (rewriteStrategy != UNWRAP_IF) {
return false;
}
AtomicBoolean result = new AtomicBoolean(true);
ifExpression.getArguments().get(1).accept(new DefaultRowExpressionTraversalVisitor<AtomicBoolean>() {
@Override
public Void visitLambda(LambdaDefinitionExpression lambda, AtomicBoolean result) {
// Unwrapping the IF expression in the aggregate might cause issues if the true branch return errors for rows not matching the filters.
// To be safe, we don't unwrap the IF expressions when the true branch has lambdas.
result.set(false);
return null;
}
@Override
public Void visitCall(CallExpression call, AtomicBoolean result) {
Optional<OperatorType> operatorType = functionAndTypeManager.getFunctionMetadata(call.getFunctionHandle()).getOperatorType();
// For example, array[1] could return out of bound error and a / b could return DIVISION_BY_ZERO error. So we doesn't unwrap the IF expression in these cases.
if (operatorType.isPresent() && (operatorType.get() == OperatorType.DIVIDE || operatorType.get() == OperatorType.SUBSCRIPT)) {
result.set(false);
return null;
}
return super.visitCall(call, result);
}
}, result);
return result.get();
}
use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.
the class PushPartialAggregationThroughJoin method pushPartialToLeftChild.
private PlanNode pushPartialToLeftChild(AggregationNode node, JoinNode child, Context context) {
Set<VariableReferenceExpression> joinLeftChildVariables = ImmutableSet.copyOf(child.getLeft().getOutputVariables());
List<VariableReferenceExpression> groupingSet = getPushedDownGroupingSet(node, joinLeftChildVariables, intersection(getJoinRequiredVariables(child), joinLeftChildVariables));
AggregationNode pushedAggregation = replaceAggregationSource(node, child.getLeft(), groupingSet);
return pushPartialToJoin(node, child, pushedAggregation, child.getRight(), context);
}
use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.
the class PushPartialAggregationThroughJoin method pushPartialToRightChild.
private PlanNode pushPartialToRightChild(AggregationNode node, JoinNode child, Context context) {
Set<VariableReferenceExpression> joinRightChildVariables = ImmutableSet.copyOf(child.getRight().getOutputVariables());
List<VariableReferenceExpression> groupingSet = getPushedDownGroupingSet(node, joinRightChildVariables, intersection(getJoinRequiredVariables(child), joinRightChildVariables));
AggregationNode pushedAggregation = replaceAggregationSource(node, child.getRight(), groupingSet);
return pushPartialToJoin(node, child, child.getLeft(), pushedAggregation, context);
}
use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.
the class TestPhasedExecutionSchedule method createBroadcastJoinPlanFragment.
private static PlanFragment createBroadcastJoinPlanFragment(String name, PlanFragment buildFragment) {
VariableReferenceExpression variable = new VariableReferenceExpression(Optional.empty(), "column", BIGINT);
PlanNode tableScan = new TableScanNode(Optional.empty(), new PlanNodeId(name), new TableHandle(new ConnectorId("test"), new TestingTableHandle(), TestingTransactionHandle.create(), Optional.empty()), ImmutableList.of(variable), ImmutableMap.of(variable, new TestingColumnHandle("column")), TupleDomain.all(), TupleDomain.all());
RemoteSourceNode remote = new RemoteSourceNode(Optional.empty(), new PlanNodeId("build_id"), buildFragment.getId(), ImmutableList.of(), false, Optional.empty(), REPLICATE);
PlanNode join = new JoinNode(Optional.empty(), new PlanNodeId(name + "_id"), INNER, tableScan, remote, ImmutableList.of(), ImmutableList.<VariableReferenceExpression>builder().addAll(tableScan.getOutputVariables()).addAll(remote.getOutputVariables()).build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(REPLICATED), ImmutableMap.of());
return createFragment(join);
}
use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.
the class TestPhasedExecutionSchedule method createTableScanPlanFragment.
private static PlanFragment createTableScanPlanFragment(String name) {
VariableReferenceExpression variable = new VariableReferenceExpression(Optional.empty(), "column", BIGINT);
PlanNode planNode = new TableScanNode(Optional.empty(), new PlanNodeId(name), new TableHandle(new ConnectorId("test"), new TestingTableHandle(), TestingTransactionHandle.create(), Optional.empty()), ImmutableList.of(variable), ImmutableMap.of(variable, new TestingColumnHandle("column")), TupleDomain.all(), TupleDomain.all());
return createFragment(planNode);
}
Aggregations