Package org.apache.pig.newplan.logical.expression

Examples of org.apache.pig.newplan.logical.expression.ProjectExpression


     */
    LogicalExpression buildProjectExpr(SourceLocation loc,
            LogicalExpressionPlan plan, LogicalRelationalOperator relOp,
            int input, String colAlias, int col)
    throws ParserValidationException {
        ProjectExpression result = null;
        result = colAlias != null ?
            new ProjectExpression( plan, input, colAlias, relOp ) :
            new ProjectExpression( plan, input, col, relOp );
        result.setLocation( loc );
        return result;
    }
View Full Code Here


            String msg = "in range project (..) at least one of start or end " +
            "has to be specified. Use project-star (*) instead.";
            throw new ParserValidationException(intStream, loc, msg);
        }
       
        ProjectExpression proj = new ProjectExpression(plan, input, relOp);

        //set first column to be projected
        if(startExpr != null){
            checkRangeProjectExpr(loc, startExpr);
            ProjectExpression startProj = (ProjectExpression)startExpr;
            if(startProj.getColAlias() != null){
                try {
                    proj.setStartAlias(startProj.getColAlias());
                } catch (FrontendException e) {
                    throw new ParserValidationException(intStream, loc, e);
                }
            }else{
                proj.setStartCol(startProj.getColNum());
            }
        }else{
            proj.setStartCol(0);//project from first column
        }
       
        //set last column to be projected
        if(endExpr != null){
            checkRangeProjectExpr(loc, endExpr);
            ProjectExpression endProj = (ProjectExpression)endExpr;
            if(endProj.getColAlias() != null){
                try {
                    proj.setEndAlias(endProj.getColAlias());
                } catch (FrontendException e) {
                    throw new ParserValidationException(intStream, loc, e);
                }
            }else{
                proj.setEndCol(endProj.getColNum());
            }
        }else{
            proj.setEndCol(-1); //project to last column
        }
       
View Full Code Here

        LOGenerate gen = new LOGenerate( lp );
        boolean[] flatten = new boolean[exprPlans.size()];
       
        List<Operator> innerLoads = new ArrayList<Operator>( exprPlans.size() );
        for( LogicalExpressionPlan plan : exprPlans ) {
            ProjectExpression pe = (ProjectExpression)plan.getSinks().get( 0 );
            String al = pe.getColAlias();
            LOInnerLoad iload = ( al == null )
                    new LOInnerLoad( lp, f, pe.getColNum() ) : createInnerLoad(loc, lp, f, al );
            iload.setLocation( pe.getLocation() );
            pe.setColNum( -1 );
            pe.setInputNum( innerLoads.size() );
            pe.setAttachedRelationalOp( gen );
            innerLoads.add( iload );
        }
       
        gen.setOutputPlans( exprPlans );
        gen.setFlattenFlags( flatten );
View Full Code Here

      if (schema != null) {
    ArrayList<LogicalFieldSchema> fields = (ArrayList<LogicalFieldSchema>) schema
            .getFields();
    for (int i = 0; i < fields.size(); i++) {
        LogicalExpressionPlan lEplan = new LogicalExpressionPlan();
        new ProjectExpression(lEplan, i, fields.get(i).alias, null, gen);
        allExprPlan.add(lEplan);
    }
      }
  }

  // iterate over all operations and generate corresponding UDFs
  for (int operIdx = 0; operIdx < operations.size(); operIdx++) {
      List<LogicalExpressionPlan> lexpPlanList = new ArrayList<LogicalExpressionPlan>();
      List<LogicalExpression> lexpList = new ArrayList<LogicalExpression>();

      lexpPlanList.addAll(expressionPlans.get(operIdx));

      // If duplicates exists in the dimension list then exception is
      // thrown
      checkDuplicateProject(lexpPlanList);

      // Construct ProjectExpression from the LogicalExpressionPlans
      lexpList = getProjectExpList(lexpPlanList, gen);

      for (int i = 0; i < lexpList.size(); i++) {
    // Retain the columns that needs to be pushed down.
    // Remove the dimension columns from the input column list
    // as it will be attached to CubeDimension UDF
    for (int j = 0; j < allExprPlan.size(); j++) {
        LogicalExpression lexp = (LogicalExpression) allExprPlan.get(j).getSources()
          .get(0);
        String colAlias = ((ProjectExpression) lexpList.get(i)).getColAlias();
        if (colAlias == null) {
      colAlias = ((ProjectExpression) lexpList.get(i)).getFieldSchema().alias;
        }

        String projExpAlias = null;
        try {
      projExpAlias = ((ProjectExpression) lexp).getColAlias();
        } catch (ClassCastException e) {
      // if it is not projection then it should be
      // UserFuncExpr.
      // ignore and continue till next ProjExpr is encountered
      continue;
        }
        if (colAlias.equals(projExpAlias) == true) {
      allExprPlan.remove(j);
        } else {
      // if projected exp alias is a namespaced alias
      if (projExpAlias.lastIndexOf(":") != -1) {
          projExpAlias = projExpAlias.substring(
            projExpAlias.lastIndexOf(":") + 1, projExpAlias.length());
          if (colAlias.equals(projExpAlias) == true) {
        allExprPlan.remove(j);
          }
      }
        }
    }
      }

      // Create UDF with user specified dimensions
      LogicalExpressionPlan uexpPlan = new LogicalExpressionPlan();
      if (operations.get(operIdx).equals("CUBE")) {
    new UserFuncExpression(uexpPlan, new FuncSpec(CubeDimensions.class.getName()),
            lexpList);
      } else {
    new UserFuncExpression(uexpPlan, new FuncSpec(RollupDimensions.class.getName()),
            lexpList);
      }

      for (LogicalExpressionPlan lexp : lexpPlanList) {
    Iterator<Operator> it = lexp.getOperators();
    while (it.hasNext()) {
        uexpPlan.add(it.next());
    }
      }
      // Add the UDF to logical expression plan that contains dependent
      // attributes (pushed down from input columns)
      allExprPlan.add(operIdx, uexpPlan);
  }

  // If the operator is a UserFuncExpression then set the flatten flags.
  List<Boolean> flattenFlags = new ArrayList<Boolean>();
  for (int idx = 0; idx < allExprPlan.size(); idx++) {
      List<Operator> opers = allExprPlan.get(idx).getSources();
      for (Operator oper : opers) {
    if (oper instanceof ProjectExpression) {
        flattenFlags.add(false);
    } else if (oper instanceof UserFuncExpression) {
        flattenFlags.add(true);
    }
      }
  }

  // Generate and Foreach operator creation
  String falias = null;
  try {
      buildGenerateOp(loc, (LOForEach) foreach, (LOGenerate) gen, allExprPlan,
        flattenFlags, getUserDefinedSchema(allExprPlan));
      falias = buildForeachOp(loc, (LOForEach) foreach, "cube", inputAlias, innerPlan);
  } catch (ParserValidationException pve) {
      throw new FrontendException(pve);
  }

  List<Boolean> innerFlags = new ArrayList<Boolean>();
  List<String> inpAliases = new ArrayList<String>();
  inpAliases.add(falias);
  innerFlags.add(false);

  // Get the output schema of foreach operator and reconstruct the
  // LogicalExpressionPlan for each dimensional attributes
  MultiMap<Integer, LogicalExpressionPlan> exprPlansCopy = new MultiMap<Integer, LogicalExpressionPlan>();

  for (LogicalExpressionPlan exp : expressionPlans.values()) {
      LogicalExpression lexp = (LogicalExpression) exp.getSources().get(0);
      LogicalExpressionPlan epGrp = new LogicalExpressionPlan();
      new ProjectExpression(epGrp, 0, lexp.getFieldSchema().alias, null, groupby);
      exprPlansCopy.put(0, epGrp);
  }

  // build group by operator
  try {
View Full Code Here

        Iterator<Operator> it = plan.getOperators();
        while( it.hasNext() ) {
            Operator sink = it.next();
            //check all ProjectExpression
            if( sink instanceof ProjectExpression ) {
                ProjectExpression projExpr = (ProjectExpression)sink;
                String colAlias = projExpr.getColAlias();
                if( projExpr.isRangeProject()){

                    LOInnerLoad innerLoad = new LOInnerLoad( lp, foreach,
                            new ProjectExpression(projExpr, new LogicalExpressionPlan())
                    );
                    setupInnerLoadAndProj(innerLoad, projExpr, lp, inputs);
                } else if( colAlias != null ) {
                    // the project is using a column alias
                    Operator op = projExpr.getProjectedOperator();
                    if( op != null ) {
                        // this means the project expression refers to a relation
                        // in the nested foreach

                        //add the relation to inputs of LOGenerate and set
                        // projection input
                        int index = inputs.indexOf( op );
                        if( index == -1 ) {
                            index = inputs.size();
                            inputs.add( op );
                        }
                        projExpr.setInputNum( index );
                        projExpr.setColNum( -1 );
                    } else {
                        // this means the project expression refers to a column
                        // in the input of foreach. Add a LOInnerLoad and use that
                        // as input
                        LOInnerLoad innerLoad = new LOInnerLoad( lp, foreach, colAlias );
                        setupInnerLoadAndProj(innerLoad, projExpr, lp, inputs);
                    }
                } else {
                    // the project expression is referring to column in ForEach input
                    // using position (eg $1)
                    LOInnerLoad innerLoad = new LOInnerLoad( lp, foreach, projExpr.getColNum() );
                    setupInnerLoadAndProj(innerLoad, projExpr, lp, inputs);
                }
            }
        }
    }
View Full Code Here

        Iterator<Operator> it = plan.getOperators();
        if( !( it.next() instanceof ProjectExpression ) || it.hasNext() ) {
            throw new NonProjectExpressionException( intStream, loc, expr );
        }
        Operator op = null;
        ProjectExpression projExpr = (ProjectExpression)expr;
        String colAlias = projExpr.getColAlias();
        if( colAlias != null ) {
            op = operators.get( colAlias );
            if( op == null ) {
                op = createInnerLoad(loc, innerPlan, foreach, colAlias );
                op.setLocation( projExpr.getLocation() );
                innerPlan.add( op );
            }
        } else {
            op = new LOInnerLoad( innerPlan, foreach, projExpr.getColNum() );
            op.setLocation( projExpr.getLocation() );
            innerPlan.add( op );
        }
        return op;
    }
View Full Code Here

     * @throws RecognitionException
     */
    LogicalExpression buildProjectExpr(SourceLocation loc, LogicalExpressionPlan plan, LogicalRelationalOperator op,
        Map<String, Operator> operators, Map<String, LogicalExpressionPlan> exprPlans, String colAlias, int col)
    throws RecognitionException {
        ProjectExpression result = null;

        if( colAlias != null ) {
            LogicalExpressionPlan exprPlan = exprPlans.get( colAlias );
            if( exprPlan != null ) {
                LogicalExpressionPlan planCopy = null;
                try {
                    planCopy = exprPlan.deepCopy();
                    plan.merge( planCopy );
                } catch (FrontendException ex) {
                    throw new PlanGenerationFailureException( intStream, loc, ex );
                }
                // The projected alias is actually expression alias, so the projections in the represented
                // expression doesn't have any operator associated with it. We need to set it when we
                // substitute the expression alias with the its expression.
                if( op != null ) {
                    Iterator<Operator> it = plan.getOperators();
                    while( it.hasNext() ) {
                        Operator o = it.next();
                        if( o instanceof ProjectExpression ) {
                            ProjectExpression projExpr = (ProjectExpression)o;
                            projExpr.setAttachedRelationalOp( op );
                        }
                    }
                }
                LogicalExpression root = (LogicalExpression)planCopy.getSources().get( 0 );// get the root of the plan
                LogicalFieldSchema schema;
                try {
                    schema = root.getFieldSchema();
                    if (schema.alias == null) {
                        schema.alias = colAlias;
                    }
                } catch (FrontendException e) {
                    // Sometimes it can throw an exception. If it does, then there is no schema to get
                }
                return root;
            } else {
                result = new ProjectExpression( plan, 0, colAlias, operators.get( colAlias ), op );
                result.setLocation( loc );
                return result;
            }
        }
        result = new ProjectExpression( plan, 0, col, op );
        result.setLocation( loc );
        return result;
    }
View Full Code Here

     */
    LogicalExpression buildProjectExpr(SourceLocation loc,
            LogicalExpressionPlan plan, LogicalRelationalOperator relOp,
            int input, String colAlias, int col)
    throws ParserValidationException {
        ProjectExpression result = null;
        result = colAlias != null ?
            new ProjectExpression( plan, input, colAlias, null, relOp ) :
            new ProjectExpression( plan, input, col, relOp );
        result.setLocation( loc );
        return result;
    }
View Full Code Here

            String msg = "in range project (..) at least one of start or end " +
            "has to be specified. Use project-star (*) instead.";
            throw new ParserValidationException(intStream, loc, msg);
        }

        ProjectExpression proj = new ProjectExpression(plan, input, relOp);

        //set first column to be projected
        if(startExpr != null){
            checkRangeProjectExpr(loc, startExpr);
            ProjectExpression startProj = (ProjectExpression)startExpr;
            if(startProj.getColAlias() != null){
                try {
                    proj.setStartAlias(startProj.getColAlias());
                } catch (FrontendException e) {
                    throw new ParserValidationException(intStream, loc, e);
                }
            }else{
                proj.setStartCol(startProj.getColNum());
            }
        }else{
            proj.setStartCol(0);//project from first column
        }

        //set last column to be projected
        if(endExpr != null){
            checkRangeProjectExpr(loc, endExpr);
            ProjectExpression endProj = (ProjectExpression)endExpr;
            if(endProj.getColAlias() != null){
                try {
                    proj.setEndAlias(endProj.getColAlias());
                } catch (FrontendException e) {
                    throw new ParserValidationException(intStream, loc, e);
                }
            }else{
                proj.setEndCol(endProj.getColNum());
            }
        }else{
            proj.setEndCol(-1); //project to last column
        }

View Full Code Here

        LOGenerate gen = new LOGenerate( lp );
        boolean[] flatten = new boolean[exprPlans.size()];

        List<Operator> innerLoads = new ArrayList<Operator>( exprPlans.size() );
        for( LogicalExpressionPlan plan : exprPlans ) {
            ProjectExpression pe = (ProjectExpression)plan.getSinks().get( 0 );
            String al = pe.getColAlias();
            LOInnerLoad iload = ( al == null ) ?
                    new LOInnerLoad( lp, f, pe.getColNum() ) : createInnerLoad(loc, lp, f, al );
            iload.setLocation( pe.getLocation() );
            pe.setColNum( -1 );
            pe.setInputNum( innerLoads.size() );
            pe.setAttachedRelationalOp( gen );
            innerLoads.add( iload );
        }

        gen.setOutputPlans( exprPlans );
        gen.setFlattenFlags( flatten );
View Full Code Here

TOP

Related Classes of org.apache.pig.newplan.logical.expression.ProjectExpression

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.