Examples of QueryBlock


Examples of org.apache.tajo.engine.planner.LogicalPlan.QueryBlock

    LogicalPlan plan = new LogicalPlan(this);
    LogicalNode subroot;

    Stack<OpType> stack = new Stack<OpType>();

    QueryBlock rootBlock = plan.newAndGetBlock(LogicalPlan.ROOT_BLOCK);
    PlanContext context = new PlanContext(plan, rootBlock);
    subroot = visitChild(context, stack, expr);

    LogicalRootNode root = new LogicalRootNode(plan.newPID());
    root.setInSchema(subroot.getOutSchema());
View Full Code Here

Examples of org.apache.tajo.engine.planner.LogicalPlan.QueryBlock

  /**
   * It checks if the first node in this query block. If not, it creates and adds a new query block.
   * In addition, it always returns the query block corresponding to the block name.
   */
  private QueryBlock checkIfNewBlockOrGet(LogicalPlan plan, String blockName) {
    QueryBlock block = plan.getBlock(blockName);
    if (block == null) {
      return plan.newAndGetBlock(blockName);
    } else {
      return block;
    }
View Full Code Here

Examples of org.apache.tajo.engine.planner.LogicalPlan.QueryBlock

    }
  }

  public TableSubQueryNode visitTableSubQuery(PlanContext context, Stack<OpType> stack, TablePrimarySubQuery expr)
      throws PlanningException {
    QueryBlock newBlock = context.plan.newAndGetBlock(expr.getName());
    PlanContext newContext = new PlanContext(context.plan, newBlock);
    Stack<OpType> newStack = new Stack<OpType>();
    LogicalNode child = visitChild(newContext, newStack, expr.getSubQuery());
    context.plan.connectBlocks(newContext.block, context.block, BlockType.TableSubQuery);
    return new TableSubQueryNode(context.plan.newPID(), expr.getName(), child);
View Full Code Here

Examples of org.apache.tajo.engine.planner.LogicalPlan.QueryBlock

  @Override
  public LogicalNode visitJoin(PlanContext context, Stack<OpType> stack, Join join)
      throws PlanningException {
    // Phase 1: Init
    LogicalPlan plan = context.plan;
    QueryBlock block = context.block;

    // Phase 2: build child plans
    stack.push(OpType.Join);
    LogicalNode left = visitChild(context, stack, join.getLeft());
    LogicalNode right = visitChild(context, stack, join.getRight());
View Full Code Here

Examples of org.apache.tajo.engine.planner.LogicalPlan.QueryBlock

  private LogicalNode buildSetPlan(PlanContext context, Stack<OpType> stack, SetOperation setOperation)
      throws PlanningException {

    // 1. Init Phase
    LogicalPlan plan = context.plan;
    QueryBlock block = context.block;

    // 2. Build Child Plans
    PlanContext leftContext = new PlanContext(plan, plan.newNoNameBlock());
    Stack<OpType> leftStack = new Stack<OpType>();
    LogicalNode left = visitChild(leftContext, leftStack, setOperation.getLeft());
    TableSubQueryNode leftSubQuery = new TableSubQueryNode(plan.newPID(), leftContext.block.getName(), left);
    context.plan.connectBlocks(leftContext.block, context.block, BlockType.TableSubQuery);

    PlanContext rightContext = new PlanContext(plan, plan.newNoNameBlock());
    Stack<OpType> rightStack = new Stack<OpType>();
    LogicalNode right = visitChild(rightContext, rightStack, setOperation.getRight());
    TableSubQueryNode rightSubQuery = new TableSubQueryNode(plan.newPID(), rightContext.block.getName(), right);
    context.plan.connectBlocks(rightContext.block, context.block, BlockType.TableSubQuery);

    BinaryNode setOp;
    if (setOperation.getType() == OpType.Union) {
      setOp = new UnionNode(plan.newPID(), leftSubQuery, rightSubQuery);
    } else if (setOperation.getType() == OpType.Except) {
      setOp = new ExceptNode(plan.newPID(), leftSubQuery, rightSubQuery);
    } else if (setOperation.getType() == OpType.Intersect) {
      setOp = new IntersectNode(plan.newPID(), leftSubQuery, rightSubQuery);
    } else {
      throw new VerifyException("Invalid Type: " + setOperation.getType());
    }

    // Strip the table names from the targets of the both blocks
    // in order to check the equivalence the schemas of both blocks.
    Target [] leftStrippedTargets = PlannerUtil.stripTarget(leftContext.block.getCurrentTargets());

    Schema outSchema = PlannerUtil.targetToSchema(leftStrippedTargets);
    setOp.setInSchema(leftSubQuery.getOutSchema());
    setOp.setOutSchema(outSchema);

    if (isNoUpperProjection(stack)) {
      block.targetListManager = new TargetListManager(plan, leftStrippedTargets);
      block.targetListManager.resolveAll();
      block.setSchema(block.targetListManager.getUpdatedSchema());
    }

    return setOp;
  }
View Full Code Here

Examples of org.apache.tajo.engine.planner.LogicalPlan.QueryBlock

  @Override
  public SelectionNode visitFilter(PlanContext context, Stack<OpType> stack, Selection selection)
      throws PlanningException {
    // 1. init phase:
    LogicalPlan plan = context.plan;
    QueryBlock block = context.block;

    // 2. build child plans:
    stack.push(OpType.Filter);
    LogicalNode child = visitChild(context, stack, selection.getChild());
    stack.pop();

    // 3. build this plan:
    EvalNode searchCondition = createEvalTree(plan, block, selection.getQual());
    SelectionNode selectionNode = new SelectionNode(plan.newPID(), searchCondition);

    // 4. set child plan, update input/output schemas:
    selectionNode.setChild(child);
    selectionNode.setInSchema(child.getOutSchema());
    selectionNode.setOutSchema(child.getOutSchema());

    // 5. update block information:
    block.setSelectionNode(selectionNode);

    return selectionNode;
  }
View Full Code Here

Examples of org.apache.tajo.engine.planner.LogicalPlan.QueryBlock

  public LogicalNode visitGroupBy(PlanContext context, Stack<OpType> stack, Aggregation aggregation)
      throws PlanningException {

    // 1. Initialization Phase:
    LogicalPlan plan = context.plan;
    QueryBlock block = context.block;

    // 2. Build Child Plan Phase:
    stack.push(OpType.Aggregation);
    LogicalNode child = visitChild(context, stack, aggregation.getChild());
    stack.pop();

    // 3. Build This Plan:
    Aggregation.GroupElement [] groupElements = aggregation.getGroupSet();

    if (groupElements[0].getType() == GroupType.OrdinaryGroup) { // for group-by
      GroupElement annotatedElements [] = new GroupElement[groupElements.length];
      for (int i = 0; i < groupElements.length; i++) {
        annotatedElements[i] = new GroupElement(
            groupElements[i].getType(),
            annotateGroupingColumn(plan, block, groupElements[i].getColumns(), null));
      }
      GroupbyNode groupingNode = new GroupbyNode(plan.newPID(), annotatedElements[0].getColumns());
      if (aggregation.hasHavingCondition()) {
        groupingNode.setHavingCondition(
            createEvalTree(plan, block, aggregation.getHavingCondition()));
      }

      // 4. Set Child Plan and Update Input Schemes Phase
      groupingNode.setChild(child);
      block.setGroupbyNode(groupingNode);
      groupingNode.setInSchema(child.getOutSchema());

      // 5. Update Output Schema and Targets for Upper Plan

      return groupingNode;

    } else if (groupElements[0].getType() == GroupType.Cube) { // for cube by
      List<Column[]> cuboids  = generateCuboids(annotateGroupingColumn(plan, block,
          groupElements[0].getColumns(), null));
      UnionNode topUnion = createGroupByUnion(plan, block, child, cuboids, 0);
      block.resolveGroupingRequired();
      block.getTargetListManager().resolveAll();

      return topUnion;
    } else {
      throw new InvalidQueryException("Not support grouping");
    }
View Full Code Here

Examples of org.apache.tajo.engine.planner.LogicalPlan.QueryBlock

  @Override
  public SortNode visitSort(PlanContext context, Stack<OpType> stack, Sort sort) throws PlanningException {

    // 1. Initialization Phase:
    LogicalPlan plan = context.plan;
    QueryBlock block = context.block;

    // 2. Build Child Plans:
    stack.push(OpType.Sort);
    LogicalNode child = visitChild(context, stack, sort.getChild());
    child = insertGroupbyNodeIfUnresolved(plan, block, child, stack);
View Full Code Here

Examples of org.apache.tajo.engine.planner.LogicalPlan.QueryBlock

  @Override
  public LimitNode visitLimit(PlanContext context, Stack<OpType> stack, Limit limit) throws PlanningException {
    // 1. Init Phase:
    LogicalPlan plan = context.plan;
    QueryBlock block = context.block;

    // build child plans
    stack.push(OpType.Limit);
    LogicalNode child = visitChild(context, stack, limit.getChild());
    stack.pop();
View Full Code Here

Examples of org.apache.tajo.engine.planner.LogicalPlan.QueryBlock

  public LogicalNode visitProjection(PlanContext context, Stack<OpType> stack, Projection projection)
      throws PlanningException {

    //1: init Phase
    LogicalPlan plan = context.plan;
    QueryBlock block = context.block;

    if (!projection.isAllProjected()) {
      block.targetListManager = new TargetListManager(plan, projection);
    }

    if (!projection.hasChild()) {
      EvalExprNode evalOnly =
          new EvalExprNode(context.plan.newPID(), annotateTargets(plan, block, projection.getTargets()));
      evalOnly.setOutSchema(getProjectedSchema(plan, evalOnly.getExprs()));
      block.setProjectionNode(evalOnly);
      for (int i = 0; i < evalOnly.getTargets().length; i++) {
        block.targetListManager.fill(i, evalOnly.getTargets()[i]);
      }
      return evalOnly;
    }

    // 2: Build Child Plans
    stack.push(OpType.Projection);
    LogicalNode child = visitChild(context, stack, projection.getChild());
    child = insertGroupbyNodeIfUnresolved(plan, block, child, stack);
    stack.pop();

    // All targets must be evaluable before the projection.
    Preconditions.checkState(block.getTargetListManager().isAllResolved(),
        "Some targets cannot be evaluated in the query block \"%s\"", block.getName());

    ProjectionNode projectionNode;
    if (projection.isAllProjected()) {
      projectionNode = new ProjectionNode(context.plan.newPID(), PlannerUtil.schemaToTargets(child.getOutSchema()));
    } else {
      projectionNode = new ProjectionNode(context.plan.newPID(), block.getCurrentTargets());
    }

    block.setProjectionNode(projectionNode);
    projectionNode.setOutSchema(getProjectedSchema(plan, projectionNode.getTargets()));
    projectionNode.setInSchema(child.getOutSchema());
    projectionNode.setChild(child);

    if (projection.isDistinct() && block.hasGrouping()) {
      throw new VerifyException("Cannot support grouping and distinct at the same time");
    } else {
      if (projection.isDistinct()) {
        Schema outSchema = projectionNode.getOutSchema();
        GroupbyNode dupRemoval = new GroupbyNode(plan.newPID(), outSchema.toArray());
        dupRemoval.setTargets(block.getTargetListManager().getTargets());
        dupRemoval.setInSchema(child.getOutSchema());
        dupRemoval.setOutSchema(outSchema);
        dupRemoval.setChild(child);
        projectionNode.setChild(dupRemoval);
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.