@Override public LogicalNode visitJoin(StringBuilder sb, LogicalPlan plan, LogicalPlan.QueryBlock block, JoinNode joinNode, Stack<LogicalNode> stack) throws TajoException { stack.push(joinNode); sb.append("("); visit(sb, plan, block, joinNode.getLeftChild(), stack); sb.append(" ").append(getJoinNotation(joinNode.getJoinType())).append(" "); visit(sb, plan, block, joinNode.getRightChild(), stack); sb.append(")"); stack.pop(); return joinNode; }
@Override public RESULT visitJoin(CONTEXT context, LogicalPlan plan, LogicalPlan.QueryBlock block, JoinNode node, Stack<LogicalNode> stack) throws TajoException { stack.push(node); RESULT result = visit(context, plan, block, node.getLeftChild(), stack); visit(context, plan, block, node.getRightChild(), stack); stack.pop(); return result; }
@Override public LogicalNode visitJoin(StringBuilder sb, LogicalPlan plan, LogicalPlan.QueryBlock block, JoinNode joinNode, Stack<LogicalNode> stack) throws TajoException { stack.push(joinNode); sb.append("("); visit(sb, plan, block, joinNode.getLeftChild(), stack); sb.append(" ").append(getJoinNotation(joinNode.getJoinType())).append(" "); visit(sb, plan, block, joinNode.getRightChild(), stack); sb.append(")"); stack.pop(); return joinNode; }
@Override public RESULT visitJoin(CONTEXT context, LogicalPlan plan, LogicalPlan.QueryBlock block, JoinNode node, Stack<LogicalNode> stack) throws TajoException { stack.push(node); RESULT result = visit(context, plan, block, node.getLeftChild(), stack); visit(context, plan, block, node.getRightChild(), stack); stack.pop(); return result; }
@Override public LogicalNode visitJoin(RelationNodeFinderContext context, LogicalPlan plan, LogicalPlan.QueryBlock block, JoinNode node, Stack<LogicalNode> stack) throws TajoException { stack.push(node); LogicalNode result = null; if (context.findMostLeft) { result = visit(context, plan, block, node.getLeftChild(), stack); } if (context.findMostRight) { result = visit(context, plan, block, node.getRightChild(), stack); } stack.pop(); return result; } }
@Override public LogicalNode visitJoin(RelationNodeFinderContext context, LogicalPlan plan, LogicalPlan.QueryBlock block, JoinNode node, Stack<LogicalNode> stack) throws TajoException { stack.push(node); LogicalNode result = null; if (context.findMostLeft) { result = visit(context, plan, block, node.getLeftChild(), stack); } if (context.findMostRight) { result = visit(context, plan, block, node.getRightChild(), stack); } stack.pop(); return result; } }
private PhysicalExec createBestRightJoinPlan(TaskAttemptContext context, JoinNode plan, PhysicalExec leftExec, PhysicalExec rightExec) throws IOException { //if the left operand is small enough => implement it as a left outer hash join with exchanged operators (note: // blocking, but merge join is blocking as well) if (isHashOuterJoinFeasible(context, plan.getLeftChild())){ LOG.info("Right Outer Join (" + plan.getPID() +") chooses [Hash Join]."); return new HashLeftOuterJoinExec(context, plan, rightExec, leftExec); } else { return createRightOuterMergeJoinPlan(context, plan, leftExec, rightExec); } }
private PhysicalExec createBestRightJoinPlan(TaskAttemptContext context, JoinNode plan, PhysicalExec leftExec, PhysicalExec rightExec) throws IOException { //if the left operand is small enough => implement it as a left outer hash join with exchanged operators (note: // blocking, but merge join is blocking as well) if (isHashOuterJoinFeasible(context, plan.getLeftChild())){ LOG.info("Right Outer Join (" + plan.getPID() +") chooses [Hash Join]."); return new HashLeftOuterJoinExec(context, plan, rightExec, leftExec); } else { return createRightOuterMergeJoinPlan(context, plan, leftExec, rightExec); } }
public static boolean isNonEquiThetaJoinQual(final LogicalPlan.QueryBlock block, final JoinNode joinNode, final EvalNode evalNode) { if (EvalTreeUtil.isJoinQual(block, joinNode.getLeftChild().getOutSchema(), joinNode.getRightChild().getOutSchema(), evalNode, true) && evalNode.getType() != EvalType.EQUAL) { return true; } else { return false; } }
private static boolean isNonEquiThetaJoinQual(final LogicalPlan.QueryBlock block, final JoinNode joinNode, final EvalNode evalNode) { if (EvalTreeUtil.isJoinQual(block, joinNode.getLeftChild().getOutSchema(), joinNode.getRightChild().getOutSchema(), evalNode, true) && evalNode.getType() != EvalType.EQUAL) { return true; } else { return false; } }
public static boolean isNonEquiThetaJoinQual(final LogicalPlan.QueryBlock block, final JoinNode joinNode, final EvalNode evalNode) { if (EvalTreeUtil.isJoinQual(block, joinNode.getLeftChild().getOutSchema(), joinNode.getRightChild().getOutSchema(), evalNode, true) && evalNode.getType() != EvalType.EQUAL) { return true; } else { return false; } }
private static boolean isNonEquiThetaJoinQual(final LogicalPlan.QueryBlock block, final JoinNode joinNode, final EvalNode evalNode) { if (EvalTreeUtil.isJoinQual(block, joinNode.getLeftChild().getOutSchema(), joinNode.getRightChild().getOutSchema(), evalNode, true) && evalNode.getType() != EvalType.EQUAL) { return true; } else { return false; } }
private PhysicalExec createBestInnerJoinPlan(TaskAttemptContext context, JoinNode plan, PhysicalExec leftExec, PhysicalExec rightExec) throws IOException { boolean inMemoryHashJoin = false; if (checkIfInMemoryInnerJoinIsPossible(context, plan.getLeftChild(), true) || checkIfInMemoryInnerJoinIsPossible(context, plan.getRightChild(), false)) { inMemoryHashJoin = true; } if (inMemoryHashJoin) { LOG.info("Join (" + plan.getPID() +") chooses [In-memory Hash Join]"); // returns two PhysicalExec. smaller one is 0, and larger one is 1. PhysicalExec [] orderedChilds = switchJoinSidesIfNecessary(context, plan, leftExec, rightExec); return new HashJoinExec(context, plan, orderedChilds[1], orderedChilds[0]); } else { return createMergeInnerJoin(context, plan, leftExec, rightExec); } }
private PhysicalExec createBestInnerJoinPlan(TaskAttemptContext context, JoinNode plan, PhysicalExec leftExec, PhysicalExec rightExec) throws IOException { boolean inMemoryHashJoin = false; if (checkIfInMemoryInnerJoinIsPossible(context, plan.getLeftChild(), true) || checkIfInMemoryInnerJoinIsPossible(context, plan.getRightChild(), false)) { inMemoryHashJoin = true; } if (inMemoryHashJoin) { LOG.info("Join (" + plan.getPID() +") chooses [In-memory Hash Join]"); // returns two PhysicalExec. smaller one is 0, and larger one is 1. PhysicalExec [] orderedChilds = switchJoinSidesIfNecessary(context, plan, leftExec, rightExec); return new HashJoinExec(context, plan, orderedChilds[1], orderedChilds[0]); } else { return createMergeInnerJoin(context, plan, leftExec, rightExec); } }
private HashFullOuterJoinExec createFullOuterHashJoinPlan(TaskAttemptContext context, JoinNode plan, PhysicalExec leftExec, PhysicalExec rightExec) throws IOException { String [] leftLineage = PlannerUtil.getRelationLineage(plan.getLeftChild()); String [] rightLineage = PlannerUtil.getRelationLineage(plan.getRightChild()); long outerSize2 = estimateSizeRecursive(context, leftLineage); long innerSize2 = estimateSizeRecursive(context, rightLineage); PhysicalExec selectedRight; PhysicalExec selectedLeft; // HashJoinExec loads the smaller relation to memory. if (outerSize2 <= innerSize2) { selectedLeft = leftExec; selectedRight = rightExec; } else { selectedLeft = rightExec; selectedRight = leftExec; } LOG.info("Full Outer Join (" + plan.getPID() + ") chooses [Hash Join]"); return new HashFullOuterJoinExec(context, plan, selectedRight, selectedLeft); }
@Override public LogicalNode visitJoin(Context context, LogicalPlan plan, LogicalPlan.QueryBlock block, JoinNode node, Stack<LogicalNode> stack) throws TajoException { visit(context, plan, block, node.getLeftChild(), stack); visit(context, plan, block, node.getRightChild(), stack); if (node.hasJoinQual()) { ExprsVerifier.verify(context.state, node, node.getJoinQual()); } verifyProjectableOutputSchema(context, node); return node; }
@Override public LogicalNode visitJoin(Context context, LogicalPlan plan, LogicalPlan.QueryBlock block, JoinNode node, Stack<LogicalNode> stack) throws TajoException { visit(context, plan, block, node.getLeftChild(), stack); visit(context, plan, block, node.getRightChild(), stack); if (node.hasJoinQual()) { ExprsVerifier.verify(context.state, node, node.getJoinQual()); } verifyProjectableOutputSchema(context, node); return node; }
@Override public LogicalNode visitJoin(GlobalPlanContext context, LogicalPlan plan, LogicalPlan.QueryBlock block, JoinNode node, Stack<LogicalNode> stack) throws TajoException { LogicalNode leftChild = visit(context, plan, block, node.getLeftChild(), stack); ExecutionBlock leftChildBlock = context.execBlockMap.get(leftChild.getPID()); LogicalNode rightChild = visit(context, plan, block, node.getRightChild(), stack); ExecutionBlock rightChildBlock = context.execBlockMap.get(rightChild.getPID()); if (node.getJoinType() == JoinType.LEFT_OUTER) { leftChildBlock.setPreservedRow(); rightChildBlock.setNullSuppllying(); } else if (node.getJoinType() == JoinType.RIGHT_OUTER) { leftChildBlock.setNullSuppllying(); rightChildBlock.setPreservedRow(); } else if (node.getJoinType() == JoinType.FULL_OUTER) { leftChildBlock.setPreservedRow(); leftChildBlock.setNullSuppllying(); rightChildBlock.setPreservedRow(); rightChildBlock.setNullSuppllying(); } ExecutionBlock newExecBlock = buildJoinPlan(context, node, leftChildBlock, rightChildBlock); context.execBlockMap.put(node.getPID(), newExecBlock); return node; }
private void assertJoinNode(LogicalNode node, String left, String right) { assertEquals(NodeType.JOIN, node.getType()); JoinNode joinNode = (JoinNode)node; if (left != null) { assertEquals(left, ((ScanNode)joinNode.getLeftChild()).getCanonicalName()); } else { assertEquals(NodeType.JOIN, joinNode.getLeftChild().getType()); } if (right != null) { assertEquals(right, ((ScanNode)joinNode.getRightChild()).getCanonicalName()); } else { assertEquals(NodeType.JOIN, joinNode.getRightChild().getType()); } } }
static void testQuery7(LogicalNode plan) { assertEquals(NodeType.PROJECTION, plan.getType()); ProjectionNode projNode = (ProjectionNode) plan; assertEquals(NodeType.GROUP_BY, projNode.getChild().getType()); GroupbyNode groupByNode = projNode.getChild(); assertEquals(NodeType.JOIN, groupByNode.getChild().getType()); JoinNode joinNode = groupByNode.getChild(); assertEquals(NodeType.SCAN, joinNode.getLeftChild().getType()); ScanNode leftNode = joinNode.getLeftChild(); assertEquals(IdentifierUtil.buildFQName(DEFAULT_DATABASE_NAME, "dept"), leftNode.getTableName()); assertEquals(NodeType.SCAN, joinNode.getRightChild().getType()); ScanNode rightNode = joinNode.getRightChild(); assertEquals(IdentifierUtil.buildFQName(DEFAULT_DATABASE_NAME, "score"), rightNode.getTableName()); }