Github user jihoonson commented on a diff in the pull request:

    https://github.com/apache/tajo/pull/402#discussion_r26296284
  
    --- Diff: 
tajo-core/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java
 ---
    @@ -1371,32 +1373,57 @@ public LogicalNode visitUnion(GlobalPlanContext 
context, LogicalPlan plan, Logic
           LogicalPlan.QueryBlock rightQueryBlock = 
plan.getBlock(node.getRightChild());
           LogicalNode rightChild = visit(context, plan, rightQueryBlock, 
rightQueryBlock.getRoot(), stack);
           stack.pop();
    +      
    +      MasterPlan masterPlan = context.getPlan();
     
           List<ExecutionBlock> unionBlocks = Lists.newArrayList();
           List<ExecutionBlock> queryBlockBlocks = Lists.newArrayList();
     
           ExecutionBlock leftBlock = 
context.execBlockMap.remove(leftChild.getPID());
           ExecutionBlock rightBlock = 
context.execBlockMap.remove(rightChild.getPID());
    +      
    +      boolean leftUnion = (leftChild.getType() == NodeType.TABLE_SUBQUERY) 
&&
    +          (((TableSubQueryNode)leftChild).getSubQuery().getType() == 
NodeType.UNION);
    +      boolean rightUnion = (rightChild.getType() == 
NodeType.TABLE_SUBQUERY) &&
    +          (((TableSubQueryNode)rightChild).getSubQuery().getType() == 
NodeType.UNION);
           if (leftChild.getType() == NodeType.UNION) {
             unionBlocks.add(leftBlock);
           } else {
    -        queryBlockBlocks.add(leftBlock);
    +        if (leftUnion) {
    +          node.setLeftChild(
    +              createScanNodeWithTableSubQuery(masterPlan, 
    +                  (TableSubQueryNode)leftChild, leftBlock, leftBlock, 
    +                  rightUnion? null: rightBlock, true));
    +        } else {
    +          queryBlockBlocks.add(leftBlock);
    +        }
           }
           if (rightChild.getType() == NodeType.UNION) {
             unionBlocks.add(rightBlock);
           } else {
    -        queryBlockBlocks.add(rightBlock);
    +        if (rightUnion) {
    +          node.setRightChild(
    +              createScanNodeWithTableSubQuery(masterPlan, 
    +                  (TableSubQueryNode)rightChild, rightBlock, leftUnion? 
leftBlock: rightBlock, 
    +                      leftUnion? null: leftBlock, false));
    +        } else {
    +          queryBlockBlocks.add(rightBlock);
    +        }
           }
     
           ExecutionBlock execBlock;
           if (unionBlocks.size() == 0) {
    -        execBlock = context.plan.newExecutionBlock();
    +        if (leftUnion || rightUnion) {
    +          execBlock = (!leftUnion && rightUnion)? rightBlock: leftBlock;
    --- End diff --
    
    Would you add some descriptions for this line?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to