Search in sources :

Example 1 with BroadcastSide

use of org.apache.hyracks.algebricks.core.algebra.expressions.BroadcastExpressionAnnotation.BroadcastSide in project asterixdb by apache.

the class JoinUtils method setJoinAlgorithmAndExchangeAlgo.

public static void setJoinAlgorithmAndExchangeAlgo(AbstractBinaryJoinOperator op, IOptimizationContext context) throws AlgebricksException {
    List<LogicalVariable> sideLeft = new LinkedList<>();
    List<LogicalVariable> sideRight = new LinkedList<>();
    List<LogicalVariable> varsLeft = op.getInputs().get(0).getValue().getSchema();
    List<LogicalVariable> varsRight = op.getInputs().get(1).getValue().getSchema();
    if (isHashJoinCondition(op.getCondition().getValue(), varsLeft, varsRight, sideLeft, sideRight)) {
        BroadcastSide side = getBroadcastJoinSide(op.getCondition().getValue(), varsLeft, varsRight);
        if (side == null) {
            setHashJoinOp(op, JoinPartitioningType.PAIRWISE, sideLeft, sideRight, context);
        } else {
            switch(side) {
                case RIGHT:
                    setHashJoinOp(op, JoinPartitioningType.BROADCAST, sideLeft, sideRight, context);
                    break;
                case LEFT:
                    Mutable<ILogicalOperator> opRef0 = op.getInputs().get(0);
                    Mutable<ILogicalOperator> opRef1 = op.getInputs().get(1);
                    ILogicalOperator tmp = opRef0.getValue();
                    opRef0.setValue(opRef1.getValue());
                    opRef1.setValue(tmp);
                    setHashJoinOp(op, JoinPartitioningType.BROADCAST, sideRight, sideLeft, context);
                    break;
                default:
                    setHashJoinOp(op, JoinPartitioningType.PAIRWISE, sideLeft, sideRight, context);
            }
        }
    } else {
        setNestedLoopJoinOp(op, context);
    }
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) BroadcastSide(org.apache.hyracks.algebricks.core.algebra.expressions.BroadcastExpressionAnnotation.BroadcastSide) LinkedList(java.util.LinkedList)

Example 2 with BroadcastSide

use of org.apache.hyracks.algebricks.core.algebra.expressions.BroadcastExpressionAnnotation.BroadcastSide in project asterixdb by apache.

the class JoinUtils method getBroadcastJoinSide.

private static BroadcastSide getBroadcastJoinSide(ILogicalExpression e, List<LogicalVariable> varsLeft, List<LogicalVariable> varsRight) {
    if (e.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
        return null;
    }
    AbstractFunctionCallExpression fexp = (AbstractFunctionCallExpression) e;
    IExpressionAnnotation ann = fexp.getAnnotations().get(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY);
    if (ann == null) {
        return null;
    }
    BroadcastSide side = (BroadcastSide) ann.getObject();
    if (side == null) {
        return null;
    }
    int i;
    switch(side) {
        case LEFT:
            i = 0;
            break;
        case RIGHT:
            i = 1;
            break;
        default:
            return null;
    }
    ArrayList<LogicalVariable> vars = new ArrayList<>();
    fexp.getArguments().get(i).getValue().getUsedVariables(vars);
    if (varsLeft.containsAll(vars)) {
        return BroadcastSide.LEFT;
    } else if (varsRight.containsAll(vars)) {
        return BroadcastSide.RIGHT;
    } else {
        return null;
    }
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ArrayList(java.util.ArrayList) IExpressionAnnotation(org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation) BroadcastSide(org.apache.hyracks.algebricks.core.algebra.expressions.BroadcastExpressionAnnotation.BroadcastSide)

Aggregations

LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)2 BroadcastSide (org.apache.hyracks.algebricks.core.algebra.expressions.BroadcastExpressionAnnotation.BroadcastSide)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)1 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)1 IExpressionAnnotation (org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation)1