Package org.apache.tajo.engine.eval

Examples of org.apache.tajo.engine.eval.EvalNode


  public void fill(int id, Target target) {
    this.targets[id] = target;
    this.unresolvedTargets[id] = target;

    EvalNode evalNode = target.getEvalTree();
    if (evalNode.getType() == EvalType.FIELD) {
      if (target.hasAlias()) {
        FieldEval fieldEval = (FieldEval) evalNode;
        targetColumnToId.put(fieldEval.getColumnRef(), id);
      }
    }
View Full Code Here


  public LogicalNode visitJoin(PushDownContext context, LogicalPlan plan, JoinNode node, Stack<LogicalNode> stack)
      throws PlanningException {
    Set<Column> currentRequired = Sets.newHashSet(context.upperRequired);

    if (node.hasTargets()) {
      EvalNode expr;
      for (Target target : node.getTargets()) {
        expr = target.getEvalTree();
        if (expr.getType() != EvalType.FIELD) {
          currentRequired.addAll(EvalTreeUtil.findDistinctRefColumns(target.getEvalTree()));
        }
      }
    }
View Full Code Here

  }

  private static LogicalNode pushDownProjectablePost(PushDownContext context, LogicalNode node, boolean last)
      throws PlanningException {
    TargetListManager targetListManager = context.targetListManager;
    EvalNode expr;

    List<Integer> newEvaluatedTargetIds = new ArrayList<Integer>();

    for (int i = 0; i < targetListManager.size(); i++) {
      expr = targetListManager.getTarget(i).getEvalTree();

      if (!targetListManager.isResolved(i) && PlannerUtil.canBeEvaluated(expr, node)) {

        if (node instanceof RelationNode) { // For ScanNode

          if (expr.getType() == EvalType.FIELD && !targetListManager.getTarget(i).hasAlias()) {
            targetListManager.resolve(i);
          } else if (EvalTreeUtil.findDistinctAggFunction(expr).size() == 0) {
            targetListManager.resolve(i);
            newEvaluatedTargetIds.add(i);
          }

        } else if (node instanceof GroupbyNode) { // For GroupBy
          if (EvalTreeUtil.findDistinctAggFunction(expr).size() > 0 && expr.getType() != EvalType.FIELD) {
            targetListManager.resolve(i);
            newEvaluatedTargetIds.add(i);
          }

        } else if (node instanceof JoinNode) {
          if (expr.getType() != EvalType.FIELD && EvalTreeUtil.findDistinctAggFunction(expr).size() == 0) {
            targetListManager.resolve(i);
            newEvaluatedTargetIds.add(i);
          }
        }
      }
View Full Code Here

    LogicalNode right = joinNode.getLeftChild();

    // here we should stop selection pushdown on the null supplying side(s) of an outer join
    // get the two operands of the join operation as well as the join type
    JoinType joinType = joinNode.getJoinType();
    EvalNode joinQual = joinNode.getJoinQual();
    if (joinQual != null && isOuterJoin(joinType)) {

      // if both are fields
       if (joinQual.getLeftExpr().getType() == EvalType.FIELD && joinQual.getRightExpr().getType() == EvalType.FIELD) {

          String leftTableName = ((FieldEval) joinQual.getLeftExpr()).getTableId();
          String rightTableName = ((FieldEval) joinQual.getRightExpr()).getTableId();
          List<String> nullSuppliers = Lists.newArrayList();
          String [] leftLineage = PlannerUtil.getLineage(joinNode.getLeftChild());
          String [] rightLineage = PlannerUtil.getLineage(joinNode.getRightChild());
          Set<String> leftTableSet = Sets.newHashSet(leftLineage);
          Set<String> rightTableSet = Sets.newHashSet(rightLineage);

          // some verification
          if (joinType == JoinType.FULL_OUTER) {
             nullSuppliers.add(leftTableName);
             nullSuppliers.add(rightTableName);

             // verify that these null suppliers are indeed in the left and right sets
             if (!rightTableSet.contains(nullSuppliers.get(0)) && !leftTableSet.contains(nullSuppliers.get(0))) {
                throw new InvalidQueryException("Incorrect Logical Query Plan with regard to outer join");
             }
             if (!rightTableSet.contains(nullSuppliers.get(1)) && !leftTableSet.contains(nullSuppliers.get(1))) {
                throw new InvalidQueryException("Incorrect Logical Query Plan with regard to outer join");
             }

          } else if (joinType == JoinType.LEFT_OUTER) {
             nullSuppliers.add(((ScanNode)joinNode.getRightChild()).getTableName());
             //verify that this null supplier is indeed in the right sub-tree
             if (!rightTableSet.contains(nullSuppliers.get(0))) {
                 throw new InvalidQueryException("Incorrect Logical Query Plan with regard to outer join");
             }
          } else if (joinType == JoinType.RIGHT_OUTER) {
            if (((ScanNode)joinNode.getRightChild()).getTableName().equals(rightTableName)) {
              nullSuppliers.add(leftTableName);
            } else {
              nullSuppliers.add(rightTableName);
            }

            // verify that this null supplier is indeed in the left sub-tree
            if (!leftTableSet.contains(nullSuppliers.get(0))) {
              throw new InvalidQueryException("Incorrect Logical Query Plan with regard to outer join");
            }
          }
        
         // retain in this outer join node's JoinQual those selection predicates
         // related to the outer join's null supplier(s)
         List<EvalNode> matched2 = Lists.newArrayList();
         for (EvalNode eval : cnf) {
           
            Set<Column> columnRefs = EvalTreeUtil.findDistinctRefColumns(eval);
            Set<String> tableNames = Sets.newHashSet();
            // getting distinct table references
            for (Column col : columnRefs) {
              if (!tableNames.contains(col.getQualifier())) {
                tableNames.add(col.getQualifier());
              }
            }
           
            //if the predicate involves any of the null suppliers
            boolean shouldKeep=false;
            Iterator<String> it2 = nullSuppliers.iterator();
            while(it2.hasNext()){
              if(tableNames.contains(it2.next()) == true) {
                   shouldKeep = true;
              }
            }

            if(shouldKeep == true) {
                matched2.add(eval);
            }
           
          }

          //merge the retained predicates and establish them in the current outer join node. Then remove them from the cnf
          EvalNode qual2 = null;
          if (matched2.size() > 1) {
             // merged into one eval tree
             qual2 = EvalTreeUtil.transformCNF2Singleton(
                        matched2.toArray(new EvalNode [matched2.size()]));
          } else if (matched2.size() == 1) {
             // if the number of matched expr is one
             qual2 = matched2.get(0);
          }

          if (qual2 != null) {
             EvalNode conjQual2 = EvalTreeUtil.transformCNF2Singleton(joinNode.getJoinQual(), qual2);
             joinNode.setJoinQual(conjQual2);
             cnf.removeAll(matched2);
          } // for the remaining cnf, push it as usual
       }
    }

    if (joinNode.hasJoinQual()) {
      cnf.addAll(Sets.newHashSet(EvalTreeUtil.getConjNormalForm(joinNode.getJoinQual())));
    }

    visitChild(cnf, plan, left, stack);
    visitChild(cnf, plan, right, stack);

    List<EvalNode> matched = Lists.newArrayList();
    for (EvalNode eval : cnf) {
      if (PlannerUtil.canBeEvaluated(eval, joinNode)) {
        matched.add(eval);
      }
    }

    EvalNode qual = null;
    if (matched.size() > 1) {
      // merged into one eval tree
      qual = EvalTreeUtil.transformCNF2Singleton(
          matched.toArray(new EvalNode[matched.size()]));
    } else if (matched.size() == 1) {
View Full Code Here

      if (PlannerUtil.canBeEvaluated(eval, scanNode)) {
        matched.add(eval);
      }
    }

    EvalNode qual = null;
    if (matched.size() > 1) {
      // merged into one eval tree
      qual = EvalTreeUtil.transformCNF2Singleton(
          matched.toArray(new EvalNode [matched.size()]));
    } else if (matched.size() == 1) {
View Full Code Here

      if (targets == null) {
        throw new PlanningException("No targets");
      }
      Tuple outTuple = new VTuple(targets.length);
      for (int i = 0; i < targets.length; i++) {
        EvalNode eval = targets[i].getEvalTree();
        outTuple.put(i, eval.eval(null, null));
      }

      Schema schema = PlannerUtil.targetToSchema(targets);
      RowStoreUtil.RowStoreEncoder encoder = RowStoreUtil.createEncoder(schema);
      byte [] serializedBytes = encoder.toBytes(outTuple);
View Full Code Here

  public Target getTarget(String referenceName, boolean unevaluatedForm) {
    String normalized = referenceName;
    int refId = nameToIdMap.get(normalized);

    if (!unevaluatedForm && evaluationStateMap.containsKey(refId) && evaluationStateMap.get(refId)) {
      EvalNode evalNode = idToEvalMap.get(refId);

      // If the expression is already evaluated, it should use the FieldEval to access a field value.
      // But, if this reference name is not primary name, it cannot use the reference name.
      // It changes the given reference name to the primary name.
      if (isEvaluated(normalized) && !isPrimaryName(refId, referenceName)) {
        return new Target(new FieldEval(getPrimaryName(refId),evalNode.getValueType()), referenceName);
      }

      EvalNode referredEval;
      if (evalNode.getType() == EvalType.CONST) {
        referredEval = evalNode;
      } else {
        referredEval = new FieldEval(idToNamesMap.get(refId).get(0), evalNode.getValueType());
      }
View Full Code Here

    Target [] targets;
    targets = new Target[projectTargetExprs.length];

    for (int i = 0; i < expr.getNamedExprs().length; i++) {
      NamedExpr namedExpr = expr.getNamedExprs()[i];
      EvalNode evalNode = annotator.createEvalNode(ctx.plan, ctx.currentBlock, namedExpr.getExpr());

      if (namedExpr.hasAlias()) {
        targets[i] = new Target(evalNode, namedExpr.getAlias());
      } else if (evalNode.getType() == EvalType.FIELD) {
        targets[i] = new Target((FieldEval) evalNode);
      } else {
        String generatedName = ctx.plan.generateUniqueColumnName(namedExpr.getExpr());
        targets[i] = new Target(evalNode, generatedName);
        namedExpr.setAlias(generatedName);
View Full Code Here

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

    for (int i = 0; i < finalTargetNum; i++) {
      NamedExpr namedExpr = projection.getNamedExprs()[i];
      EvalNode evalNode = annotator.createEvalNode(ctx.plan, ctx.currentBlock, namedExpr.getExpr());

      if (namedExpr.hasAlias()) {
        targets[i] = new Target(evalNode, namedExpr.getAlias());
      } else {
        targets[i] = new Target(evalNode, "?name_" + i);
View Full Code Here

TOP

Related Classes of org.apache.tajo.engine.eval.EvalNode

Copyright © 2018 www.massapicom. 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.