Examples of QueryBlock


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

    return new Column(columnDefinition.getColumnName(), convertDataType(columnDefinition));
  }

  protected LogicalNode visitInsert(PlanContext context, Stack<OpType> stack, Insert expr) throws PlanningException {
    stack.push(expr.getType());
    QueryBlock newQueryBlock = context.plan.newNoNameBlock();
    PlanContext newContext = new PlanContext(context.plan, newQueryBlock);
    Stack<OpType> subStack = new Stack<OpType>();
    LogicalNode subQuery = visitChild(newContext, subStack, expr.getSubQuery());
    context.plan.connectBlocks(newQueryBlock, context.block, BlockType.TableSubQuery);
    stack.pop();
View Full Code Here

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

   * @throws PlanningException
   */
  public static Column[] getColumns(PreprocessContext ctx, QualifiedAsteriskExpr asteriskExpr)
      throws PlanningException {
    RelationNode relationOp = null;
    QueryBlock block = ctx.currentBlock;
    Collection<QueryBlock> queryBlocks = ctx.plan.getQueryBlocks();
    if (asteriskExpr.hasQualifier()) {
      String qualifier;

      if (CatalogUtil.isFQTableName(asteriskExpr.getQualifier())) {
        qualifier = asteriskExpr.getQualifier();
      } else {
        qualifier = CatalogUtil.buildFQName(ctx.session.getCurrentDatabase(), asteriskExpr.getQualifier());
      }

      relationOp = block.getRelation(qualifier);

      // if a column name is outside of this query block
      if (relationOp == null) {
        // TODO - nested query can only refer outer query block? or not?
        for (QueryBlock eachBlock : queryBlocks) {
          if (eachBlock.existsRelation(qualifier)) {
            relationOp = eachBlock.getRelation(qualifier);
          }
        }
      }

      // If we cannot find any relation against a qualified column name
      if (relationOp == null) {
        throw new NoSuchColumnException(CatalogUtil.buildFQName(qualifier, "*"));
      }

      Schema schema = relationOp.getTableSchema();
      Column[] resolvedColumns = new Column[schema.size()];
      return schema.getColumns().toArray(resolvedColumns);
    } else { // if a column reference is not qualified
      // columns of every relation should be resolved.
      Iterator<RelationNode> iterator = block.getRelations().iterator();
      Schema schema;
      List<Column> resolvedColumns = TUtil.newList();

      while (iterator.hasNext()) {
        relationOp = iterator.next();
View Full Code Here

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

  @VisibleForTesting
  public LogicalPlan createPlan(Session session, Expr expr, boolean debug) throws PlanningException {

    LogicalPlan plan = new LogicalPlan(session.getCurrentDatabase(), this);

    QueryBlock rootBlock = plan.newAndGetBlock(LogicalPlan.ROOT_BLOCK);
    PreprocessContext preProcessorCtx = new PreprocessContext(session, plan, rootBlock);
    preprocessor.visit(preProcessorCtx, new Stack<Expr>(), expr);

    PlanContext context = new PlanContext(session, plan, plan.getRootBlock(), debug);
    LogicalNode topMostNode = this.visit(context, new Stack<Expr>(), expr);
View Full Code Here

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

      if (expr.getType() == OpType.RelationList && current.getType() == NodeType.SCAN) {
        return current;
      }
    }

    QueryBlock queryBlock = context.queryBlock;
    queryBlock.updateLatestNode(current);

    // if this node is the topmost
    if (stack.size() == 0) {
      queryBlock.setRoot(current);
    }

    if (!stack.empty()) {
      queryBlock.updateCurrentNode(stack.peek());
    }
    return current;
  }
View Full Code Here

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

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


    LogicalPlan plan = context.plan;
    QueryBlock block = context.queryBlock;

    // If a non-from statement is given
    if (!projection.hasChild()) {
      return buildPlanForNoneFromStatement(context, stack, projection);
    }

    String [] referenceNames;
    // in prephase, insert all target list into NamedExprManagers.
    // Then it gets reference names, each of which points an expression in target list.
    referenceNames = doProjectionPrephase(context, projection);

    ////////////////////////////////////////////////////////
    // Visit and Build Child Plan
    ////////////////////////////////////////////////////////
    stack.push(projection);
    LogicalNode child = visit(context, stack, projection.getChild());

    // check if it is implicit aggregation. If so, it inserts group-by node to its child.
    if (block.isAggregationRequired()) {
      child = insertGroupbyNode(context, child, stack);
    }
    stack.pop();
    ////////////////////////////////////////////////////////

    ProjectionNode projectionNode;
    Target [] targets;
    targets = buildTargets(plan, block, referenceNames);

    // Set ProjectionNode
    projectionNode = context.queryBlock.getNodeFromExpr(projection);
    projectionNode.setInSchema(child.getOutSchema());
    projectionNode.setTargets(targets);
    projectionNode.setChild(child);

    if (projection.isDistinct() && block.hasNode(NodeType.GROUP_BY)) {
      throw new VerifyException("Cannot support grouping and distinct at the same time yet");
    } else {
      if (projection.isDistinct()) {
        insertDistinctOperator(context, projectionNode, child, stack);
      }
View Full Code Here

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

  }

  private void setRawTargets(PlanContext context, Target[] targets, String[] referenceNames,
                             Projection projection) throws PlanningException {
    LogicalPlan plan = context.plan;
    QueryBlock block = context.queryBlock;

    // It's for debugging or unit tests.
    Target [] rawTargets = new Target[projection.getNamedExprs().length];
    for (int i = 0; i < projection.getNamedExprs().length; i++) {
      NamedExpr namedExpr = projection.getNamedExprs()[i];
      EvalNode evalNode = exprAnnotator.createEvalNode(plan, block, namedExpr.getExpr());
      rawTargets[i] = new Target(evalNode, referenceNames[i]);
    }
    // it's for debugging or unit testing
    block.setRawTargets(rawTargets);
  }
View Full Code Here

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

  }

  private void insertDistinctOperator(PlanContext context, ProjectionNode projectionNode, LogicalNode child,
                                      Stack<Expr> stack) throws PlanningException {
    LogicalPlan plan = context.plan;
    QueryBlock block = context.queryBlock;

    Schema outSchema = projectionNode.getOutSchema();
    GroupbyNode dupRemoval = context.plan.createNode(GroupbyNode.class);
    dupRemoval.setChild(child);
    dupRemoval.setInSchema(projectionNode.getInSchema());
    dupRemoval.setTargets(PlannerUtil.schemaToTargets(outSchema));
    dupRemoval.setGroupingColumns(outSchema.toArray());

    block.registerNode(dupRemoval);
    postHook(context, stack, null, dupRemoval);

    projectionNode.setChild(dupRemoval);
    projectionNode.setInSchema(dupRemoval.getOutSchema());
  }
View Full Code Here

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

    projectionNode.setChild(dupRemoval);
    projectionNode.setInSchema(dupRemoval.getOutSchema());
  }

  private String [] doProjectionPrephase(PlanContext context, Projection projection) throws PlanningException {
    QueryBlock block = context.queryBlock;

    int finalTargetNum = projection.size();
    String [] referenceNames = new String[finalTargetNum];
    ExprNormalizedResult [] normalizedExprList = new ExprNormalizedResult[finalTargetNum];
    NamedExpr namedExpr;
    for (int i = 0; i < finalTargetNum; i++) {
      namedExpr = projection.getNamedExprs()[i];

      if (PlannerUtil.existsAggregationFunction(namedExpr)) {
        block.setAggregationRequire();
      }
      // dissect an expression into multiple parts (at most dissected into three parts)
      normalizedExprList[i] = normalizer.normalize(context, namedExpr.getExpr());
    }
View Full Code Here

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

   * It builds non-from statement (only expressions) like '<code>SELECT 1+3 as plus</code>'.
   */
  private EvalExprNode buildPlanForNoneFromStatement(PlanContext context, Stack<Expr> stack, Projection projection)
      throws PlanningException {
    LogicalPlan plan = context.plan;
    QueryBlock block = context.queryBlock;

    int finalTargetNum = projection.getNamedExprs().length;
    Target [] targets = new Target[finalTargetNum];

    for (int i = 0; i < targets.length; i++) {
      NamedExpr namedExpr = projection.getNamedExprs()[i];
      EvalNode evalNode = exprAnnotator.createEvalNode(plan, block, namedExpr.getExpr());
      if (namedExpr.hasAlias()) {
        targets[i] = new Target(evalNode, namedExpr.getAlias());
      } else {
        targets[i] = new Target(evalNode, context.plan.generateUniqueColumnName(namedExpr.getExpr()));
      }
    }
    EvalExprNode evalExprNode = context.queryBlock.getNodeFromExpr(projection);
    evalExprNode.setTargets(targets);
    evalExprNode.setOutSchema(PlannerUtil.targetToSchema(targets));
    // it's for debugging or unit testing
    block.setRawTargets(targets);
    return evalExprNode;
  }
View Full Code Here

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

   */
  private LogicalNode insertGroupbyNode(PlanContext context, LogicalNode child, Stack<Expr> stack)
      throws PlanningException {

    LogicalPlan plan = context.plan;
    QueryBlock block = context.queryBlock;
    GroupbyNode groupbyNode = context.plan.createNode(GroupbyNode.class);
    groupbyNode.setChild(child);
    groupbyNode.setInSchema(child.getOutSchema());

    groupbyNode.setGroupingColumns(new Column[] {});

    Set<String> aggEvalNames = new LinkedHashSet<String>();
    Set<AggregationFunctionCallEval> aggEvals = new LinkedHashSet<AggregationFunctionCallEval>();
    boolean includeDistinctFunction = false;
    for (Iterator<NamedExpr> it = block.namedExprsMgr.getIteratorForUnevaluatedExprs(); it.hasNext();) {
      NamedExpr rawTarget = it.next();
      try {
        includeDistinctFunction = PlannerUtil.existsDistinctAggregationFunction(rawTarget.getExpr());
        EvalNode evalNode = exprAnnotator.createEvalNode(context.plan, context.queryBlock, rawTarget.getExpr());
        if (evalNode.getType() == EvalType.AGG_FUNCTION) {
          aggEvalNames.add(rawTarget.getAlias());
          aggEvals.add((AggregationFunctionCallEval) evalNode);
          block.namedExprsMgr.markAsEvaluated(rawTarget.getAlias(), evalNode);
        }
      } catch (VerifyException ve) {
      }
    }

    groupbyNode.setDistinct(includeDistinctFunction);
    groupbyNode.setAggFunctions(aggEvals.toArray(new AggregationFunctionCallEval[aggEvals.size()]));
    Target [] targets = ProjectionPushDownRule.buildGroupByTarget(groupbyNode, null,
        aggEvalNames.toArray(new String[aggEvalNames.size()]));
    groupbyNode.setTargets(targets);

    // this inserted group-by node doesn't pass through preprocessor. So manually added.
    block.registerNode(groupbyNode);
    postHook(context, stack, null, groupbyNode);
    return groupbyNode;
  }
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.