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

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


        // build an expression with 2 AND, it should split into 3 filters
        LogicalExpressionPlan p5 = new LogicalExpressionPlan();
       
      
        LogicalExpression lp3 = new ProjectExpression(p5, 0, 2, filter);
        LogicalExpression cont = new ConstantExpression(p5, new Integer(3));
        p5.add(lp3);
        p5.add(cont);      
        LogicalExpression eq = new EqualExpression(p5, lp3, cont);
       
        LogicalExpression lp4 = new ProjectExpression(p5, 0, 3, filter);
        LogicalExpression cont2 = new ConstantExpression(p5, new Integer(3));       
        p5.add(lp4);
        p5.add(cont2);
        LogicalExpression eq2 = new EqualExpression(p5, lp4, cont2);       
       
        LogicalExpression and1 = new AndExpression(p5, eq, eq2);
View Full Code Here


        prep();
        // build an expression with 2 AND, it should split into 3 filters
        LogicalExpressionPlan p5 = new LogicalExpressionPlan();
       
        LogicalExpression lp3 = new ProjectExpression(p5, 0, 2, filter);
        LogicalExpression cont = new ConstantExpression(p5, new Integer(3));
        p5.add(lp3);
        p5.add(cont);
        LogicalExpression eq = new EqualExpression(p5, lp3, cont);     
       
        lp3 = new ProjectExpression(p5, 0, 0, filter);
View Full Code Here

        LOGenerate gen = (LOGenerate)foreach.getInnerPlan().getSinks().get(0);
        LogicalExpressionPlan exprPlan = gen.getOutputPlans().get(0);
        Operator logOp = exprPlan.getSources().get(0);
        Assert.assertTrue( logOp instanceof ConstantExpression);

        ConstantExpression loConst = (ConstantExpression)logOp;
        Assert.assertTrue(loConst.getType() == DataType.TUPLE);
        Assert.assertTrue(loConst.getValue() instanceof Tuple);
        Assert.assertTrue(loConst.getValue().equals(TupleFactory.getInstance().newTuple()));

        String s = foreach.getSchema().toString(false);
        Assert.assertTrue( s.equals(":tuple()"));
    }
View Full Code Here

        LOGenerate gen = (LOGenerate)foreach.getInnerPlan().getSinks().get(0);
        LogicalExpressionPlan exprPlan = gen.getOutputPlans().get(0);
        Operator logOp = exprPlan.getSources().get(0);
        Assert.assertTrue( logOp instanceof ConstantExpression);

        ConstantExpression loConst = (ConstantExpression)logOp;
        Assert.assertTrue(loConst.getType() == DataType.MAP);
        Assert.assertTrue(loConst.getValue() instanceof Map);
        Assert.assertTrue(loConst.getValue().equals(new HashMap<String,Object>()));

        String s = foreach.getSchema().toString(false);
        Assert.assertTrue( s.equals(":map"));
    }
View Full Code Here

        LOGenerate gen = (LOGenerate)foreach.getInnerPlan().getSinks().get(0);
        LogicalExpressionPlan exprPlan = gen.getOutputPlans().get(0);
        Operator logOp = exprPlan.getSources().get(0);
        Assert.assertTrue( logOp instanceof ConstantExpression);

        ConstantExpression loConst = (ConstantExpression)logOp;
        Assert.assertTrue(loConst.getType() == DataType.BAG);
        Assert.assertTrue(loConst.getValue() instanceof DataBag);
        Assert.assertTrue(loConst.getValue().equals(BagFactory.getInstance().newDefaultBag()));

        String s = foreach.getSchema().toString(false);
        Assert.assertTrue( s.equals(":bag{}") );
    }
View Full Code Here

        LogicalExpressionPlan filterPlan = new LogicalExpressionPlan();
        LOFilter D = new LOFilter(lp, filterPlan);
        ProjectExpression fy = new ProjectExpression(filterPlan, 0, 1, D);
        fy.neverUseForRealSetFieldSchema(new LogicalFieldSchema(null, null,
                DataType.INTEGER, 2));
        ConstantExpression fc = new ConstantExpression(filterPlan, new Integer(0));
        new EqualExpression(filterPlan, fy, fc);

        D.neverUseForRealSetSchema(cschema);
        // Connect D to B, since the transform has happened.
        lp.add(D);
View Full Code Here

        return new LogicalExpressionVisitor( exprPlan, new DependencyOrderWalker( exprPlan ) ) {

            @Override
            public void visit(ScalarExpression expr) throws FrontendException {
                // This is a scalar udf.
                ConstantExpression filenameConst = (ConstantExpression)exprPlan.getSuccessors( expr ).get( 1 );

                Operator refOp = expr.getImplicitReferencedOperator();
                Operator attachedOp = expr.getAttachedLogicalOperator();
                LogicalPlan lp = (LogicalPlan) attachedOp.getPlan();
                List<Operator> succs = lp.getSuccessors( refOp );
                LOStore store = null;
                FuncSpec interStorageFuncSpec = new FuncSpec(InterStorage.class.getName());
                if( succs != null ) {
                    for( Operator succ : succs ) {
                        if( succ instanceof LOStore
                                && ((LOStore)succ).isTmpStore()
                                && interStorageFuncSpec.equals(
                                    ((LOStore)succ).getOutputSpec().getFuncSpec() ) ) {
                            store = (LOStore)succ;
                            break;
                        }
                    }
                }

                if( store == null ) {
                    FileSpec fileSpec;
                    try {
                        fileSpec = new FileSpec( FileLocalizer.getTemporaryPath( pigContext ).toString(), interStorageFuncSpec );                    // TODO: need to hookup the pigcontext.
                    } catch (IOException e) {
                        throw new PlanValidationException( expr, "Failed to process scalar" + e);
                    }
                    StoreFuncInterface stoFunc = (StoreFuncInterface)PigContext.instantiateFuncFromSpec(interStorageFuncSpec);
                    String sig = LogicalPlanBuilder.newOperatorKey(scope);
                    stoFunc.setStoreFuncUDFContextSignature(sig);
                    store = new LOStore(lp, fileSpec, stoFunc, sig);
                    store.setTmpStore(true);
                    lp.add( store );
                    lp.connect( refOp, store );
                }
               
                expr.setImplicitReferencedOperator(store);
                filenameConst.setValue( store.getOutputSpec().getFileName() );
               
                if( lp.getSoftLinkSuccessors( store ) == null ||
                    !lp.getSoftLinkSuccessors( store ).contains( attachedOp ) ) {
                    lp.createSoftLink( store, attachedOp );
                }
View Full Code Here

            // D = filter
            LogicalExpressionPlan filterPlan = new LogicalExpressionPlan();
            LOFilter D = new LOFilter(lp, filterPlan);
            ProjectExpression fx = new ProjectExpression(filterPlan, 0, 0, D);
            ConstantExpression fc0 = new ConstantExpression(filterPlan, new Integer(0));
            EqualExpression eq1 = new EqualExpression(filterPlan, fx, fc0);
            ProjectExpression fanotherx = new ProjectExpression(filterPlan, 0, 0, D);
            ProjectExpression fa = new ProjectExpression(filterPlan, 0, 2, D);
            EqualExpression eq2 = new EqualExpression(filterPlan, fanotherx, fa);
            AndExpression and1 = new AndExpression(filterPlan, eq1, eq2);
            ProjectExpression fb = new ProjectExpression(filterPlan, 0, 3, D);
            ConstantExpression fc1 = new ConstantExpression(filterPlan, new Integer(1));
            EqualExpression eq3 = new EqualExpression(filterPlan, fb, fc1);
            AndExpression and2 = new AndExpression(filterPlan, and1, eq3);
            ProjectExpression fanotherb = new ProjectExpression(filterPlan, 0, 3, D);
            ProjectExpression fy = new ProjectExpression(filterPlan, 0, 1, D);
            EqualExpression eq4 = new EqualExpression(filterPlan, fy, fanotherb);
            new AndExpression(filterPlan, and2, eq4);

            D.setAlias("D");
            // Connect D to B, since the transform has happened.
            lp.add(D);
            lp.connect(C, D);
        }

        System.out.println(lp);
        LogicalPlanOptimizer optimizer = new LogicalPlanOptimizer(lp, 500, null);
        optimizer.optimize();

        LogicalPlan expected = new LogicalPlan();
        {
            // A = load
            LogicalSchema aschema = new LogicalSchema();
            aschema.addField(new LogicalSchema.LogicalFieldSchema(
                "x", null, DataType.BYTEARRAY));
            aschema.addField(new LogicalSchema.LogicalFieldSchema(
                "y", null, DataType.BYTEARRAY));
            LOLoad A = newLOLoad(new FileSpec("bla", new FuncSpec("PigStorage", "\t")), aschema, expected, conf);
            expected.add(A);

            // DA = filter
            LogicalExpressionPlan DAfilterPlan = new LogicalExpressionPlan();
            LOFilter DA = new LOFilter(expected, DAfilterPlan);
            ProjectExpression fx = new ProjectExpression(DAfilterPlan, 0, 0, DA);
            fx.neverUseForRealSetFieldSchema(new LogicalFieldSchema(null, null, DataType.BYTEARRAY));
            ConstantExpression fc0 = new ConstantExpression(DAfilterPlan, new Integer(0));
            new EqualExpression(DAfilterPlan, fx, fc0);

            DA.neverUseForRealSetSchema(aschema);
            expected.add(DA);
            expected.connect(A, DA);

            // B = load
            LogicalSchema bschema = new LogicalSchema();
            bschema.addField(new LogicalSchema.LogicalFieldSchema(
                "a", null, DataType.BYTEARRAY));
            bschema.addField(new LogicalSchema.LogicalFieldSchema(
                "b", null, DataType.BYTEARRAY));
            LOLoad B = newLOLoad(new FileSpec("morebla", new FuncSpec("PigStorage", "\t")), bschema, expected, conf);
            expected.add(B);

            // DB = filter
            LogicalExpressionPlan DBfilterPlan = new LogicalExpressionPlan();
            LOFilter DB = new LOFilter(expected, DBfilterPlan);
            ProjectExpression fb = new ProjectExpression(DBfilterPlan, 0, 1, DB);
            fb.neverUseForRealSetFieldSchema(new LogicalFieldSchema(null, null, DataType.BYTEARRAY));
            ConstantExpression fc1 = new ConstantExpression(DBfilterPlan, new Integer(1));
            new EqualExpression(DBfilterPlan, fb, fc1);

            DB.neverUseForRealSetSchema(bschema);
            expected.add(DB);
            expected.connect(B, DB);
View Full Code Here

    private static String getTestExpression(LogicalExpression op) throws FrontendException {
        if(op == null) {
            return null;
        }
        if(op instanceof ConstantExpression) {
            ConstantExpression constExpr =(ConstantExpression)op ;
            return String.valueOf(constExpr.getValue());
        } else if (op instanceof ProjectExpression) {
            ProjectExpression projExpr = (ProjectExpression)op;
            String fieldName = projExpr.getFieldSchema().alias;
            return fieldName;
        } else {
View Full Code Here

                LogicalFieldSchema matchFS = opSchema.getFieldSubNameMatch(fs.alias);
                if(matchFS != null){
                    pos = opSchema.getFieldPosition(matchFS.alias);
                }
                if( pos == -1 ) {
                    ConstantExpression constExp = new ConstantExpression( exprPlan, null);
                    if(fs.type != DataType.BYTEARRAY){
                        LogicalSchema.LogicalFieldSchema constFs = fs.deepCopy();
                        constFs.resetUid();
                        new CastExpression(exprPlan, constExp, constFs);
                    }
View Full Code Here

TOP

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

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.