Package org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators

Examples of org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POUserFunc


                int errCode = 2020;
                String msg = "Expected to find plan with UDF or project leaf. Found " + leaf.getClass().getSimpleName();
                throw new PlanException(msg, errCode, PigException.BUG);
            }

            POUserFunc func = (POUserFunc)leaf;
            try {
                func.setAlgebraicFunction(type);
            } catch (ExecException e) {
                int errCode = 2075;
                String msg = "Could not set algebraic function type.";
                throw new PlanException(msg, errCode, PigException.BUG, e);
            }
View Full Code Here


                }
                // we have stick in the POUserfunc(org.apache.pig.builtin.Distinct)[DataBag]
                // in place of the Project-PODistinct pair
                PhysicalOperator distinctPredecessor = mPlan.getPredecessors(pred).get(0);

                POUserFunc func = null;

                try {
                    String scope = proj.getOperatorKey().scope;
                    List<PhysicalOperator> funcInput = new ArrayList<PhysicalOperator>();
                    FuncSpec fSpec = new FuncSpec(DISTINCT_UDF_CLASSNAME);
                    funcInput.add(distinctPredecessor);
                    // explicitly set distinctPredecessor's result type to
                    // be tuple - this is relevant when distinctPredecessor is
                    // originally a POForeach with return type BAG - we need to
                    // set it to tuple so we get a stream of tuples.
                    distinctPredecessor.setResultType(DataType.TUPLE);
                    func = new POUserFunc(new OperatorKey(scope,
                            NodeIdGenerator.getGenerator().getNextNodeId(scope)),-1, funcInput, fSpec);
                    func.setResultType(DataType.BAG);
                    mPlan.replace(proj, func);
                    mPlan.remove(pred);
                    // connect the the newly added "func" to
                    // the predecessor to the earlier PODistinct
                    mPlan.connect(distinctPredecessor, func);
View Full Code Here

       
        List<PhysicalOperator> ufInps = new ArrayList<PhysicalOperator>();
        ufInps.add(prjStar);
       
      PhysicalPlan ep = new PhysicalPlan();
      POUserFunc uf = new POUserFunc(new OperatorKey(scope,nig.getNextNodeId(scope)), -1, ufInps,
                  new FuncSpec(GetMemNumRows.class.getName(), (String[])null));
      uf.setResultType(DataType.TUPLE);
      ep.add(uf);    
      ep.add(prjStar);
      ep.connect(prjStar, uf);

        transformPlans.add(ep);     
View Full Code Here

        ep4.add(prjStar4);
       
        List<PhysicalOperator> ufInps = new ArrayList<PhysicalOperator>();
        ufInps.add(prjStar4);
     
        POUserFunc uf = new POUserFunc(new OperatorKey(scope,nig.getNextNodeId(scope)), -1, ufInps,
            new FuncSpec(udfClassName, udfArgs));
        ep4.add(uf);
        ep4.connect(prjStar4, uf);
       
        List<PhysicalPlan> ep4s = new ArrayList<PhysicalPlan>();
View Full Code Here

    @Override
    public void visit( UserFuncExpression op ) throws FrontendException {      
        Object f = PigContext.instantiateFuncFromSpec(op.getFuncSpec());
        PhysicalOperator p;
        if (f instanceof EvalFunc) {
            p = new POUserFunc(new OperatorKey(DEFAULT_SCOPE, nodeGen
                    .getNextNodeId(DEFAULT_SCOPE)), -1,
                    null, op.getFuncSpec(), (EvalFunc) f);
            List<String> cacheFiles = ((EvalFunc)f).getCacheFiles();
            if (cacheFiles != null) {
                ((POUserFunc)p).setCacheFiles(cacheFiles.toArray(new String[cacheFiles.size()]));
View Full Code Here

        // setup udf
        List<PhysicalOperator> udfInps = new ArrayList<PhysicalOperator>();
        udfInps.add(projVal1);
        FuncSpec sumSpec = new FuncSpec(IntSum.Intermediate.class.getName());
        POUserFunc sumUdf = new POUserFunc(GenPhyOp.getOK(), -1, udfInps,
                sumSpec);
        valPlan1.add(sumUdf);
        valPlan1.connect(projVal1, sumUdf);

        List<PhysicalPlan> valuePlans = new ArrayList<PhysicalPlan>();
View Full Code Here

  public void userFuncArity(DataBag input ) throws ExecException {
    String funcSpec = ARITY.class.getName() + "()";
    PORead read = new PORead(new OperatorKey("", r.nextLong()), input);
    List<PhysicalOperator> inputs = new LinkedList<PhysicalOperator>();
    inputs.add(read);
    POUserFunc userFunc = new POUserFunc(new OperatorKey("", r.nextLong()),
        -1, inputs, new FuncSpec(funcSpec));
    Result res = new Result();
    Integer i = null;
    res = userFunc.getNext(i);
    while (res.returnStatus != POStatus.STATUS_EOP) {
      // System.out.println(res.result);
      int result = (Integer) res.result;
      assertEquals(2, result);
      res = userFunc.getNext(i);
    }
  }
View Full Code Here

    Tuple tup2 = Util.loadNestTuple(TupleFactory.getInstance().newTuple(1),
        input);
    // System.out.println("Input = " + tup1);
    String funcSpec = AVG.class.getName() + "()";

    POUserFunc po = new POUserFunc(new OperatorKey("", r.nextLong()), -1,
        null, new FuncSpec(funcSpec));

                //************ Initial Calculations ******************
    TupleFactory tf = TupleFactory.getInstance();
    po.setAlgebraicFunction(INIT);
    po.attachInput(tup1);
    Tuple t = null;
    Result res = po.getNext(t);
    Tuple outputInitial1 = (res.returnStatus == POStatus.STATUS_OK) ? (Tuple) res.result
        : null;
    Tuple outputInitial2 = (res.returnStatus == POStatus.STATUS_OK) ? (Tuple) res.result
        : null;
    System.out.println(outputInitial1 + " " + outputInitial2);
    assertEquals(outputInitial1, outputInitial2);
    double sum = (Double) outputInitial1.get(0);
    long count = (Long) outputInitial1.get(1);
    assertEquals(initialExpectedSum, sum);
    assertEquals(initialExpectedCount, count);

                //************ Intermediate Data and Calculations ******************
    DataBag bag = BagFactory.getInstance().newDefaultBag();
    bag.add(outputInitial1);
    bag.add(outputInitial2);
    Tuple outputInitial = tf.newTuple();
    outputInitial.append(bag);
    // Tuple outputIntermed = intermed.exec(outputInitial);
    po = new POUserFunc(new OperatorKey("", r.nextLong()), -1, null,
        new FuncSpec(funcSpec));
    po.setAlgebraicFunction(INTERMED);
    po.attachInput(outputInitial);
    res = po.getNext(t);
    Tuple outputIntermed = (res.returnStatus == POStatus.STATUS_OK) ? (Tuple) res.result
        : null;

    sum = (Double) outputIntermed.get(0);
    count = (Long) outputIntermed.get(1);
    assertEquals(intermedExpectedSum, sum);
    assertEquals(intermedExpectedCount, count);
    System.out.println(outputIntermed);

                //************ Final Calculations ******************
    po = new POUserFunc(new OperatorKey("", r.nextLong()), -1, null,
        new FuncSpec(funcSpec));
    po.setAlgebraicFunction(FINAL);
    po.attachInput(outputInitial);
    res = po.getNext(t);
    Double output = (res.returnStatus == POStatus.STATUS_OK) ? (Double) res.result
        : null;
    // Double output = fin.exec(outputInitial);
    assertEquals( expectedAvg, output);
    // System.out.println("output = " + output);
View Full Code Here

                    // constant or project.  not combining it
                    //TODO: Warn
                    return null;
                }
                POProject proj = (POProject)root;
                POUserFunc combineUdf = getAlgebraicSuccessor(proj, pplan);
                if(combineUdf == null){
                   
                    if(proj.isProjectToEnd()){
                        //project-star or project to end
                        // not combinable
View Full Code Here

                int errCode = 2020;
                String msg = "Expected to find plan with UDF or project leaf. Found " + leaf.getClass().getSimpleName();
                throw new PlanException(msg, errCode, PigException.BUG);
            }

            POUserFunc func = (POUserFunc)leaf;
            try {
                func.setAlgebraicFunction(type);
            } catch (ExecException e) {
                int errCode = 2075;
                String msg = "Could not set algebraic function type.";
                throw new PlanException(msg, errCode, PigException.BUG, e);
            }
View Full Code Here

TOP

Related Classes of org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POUserFunc

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.