Package org.apache.pig.experimental.logical.expression

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


          cschema.getField(0).uid = 1;
          cschema.getField(1).uid = 2;
          cschema.getField(2).uid = 3;
          cschema.getField(3).uid = 4;
          LogicalExpressionPlan aprojplan = new LogicalExpressionPlan();
          ProjectExpression x = new ProjectExpression(aprojplan, DataType.INTEGER, 0, 0);
          x.neverUseForRealSetUid(1);
          LogicalExpressionPlan bprojplan = new LogicalExpressionPlan();
          ProjectExpression y = new ProjectExpression(bprojplan, DataType.INTEGER, 1, 0);
          y.neverUseForRealSetUid(3);
          MultiMap<Integer, LogicalExpressionPlan> mm =
              new MultiMap<Integer, LogicalExpressionPlan>();
          mm.put(0, aprojplan);
          mm.put(1, bprojplan);
          LOJoin C = new LOJoin(lp, mm, JOINTYPE.HASH, new boolean[] {true, true});
          C.neverUseForRealSetSchema(cschema);
          lp.add(C);
          lp.connect(A, C);
          lp.connect(B, C);
       
          // D = filter
          LogicalExpressionPlan filterPlan = new LogicalExpressionPlan();
          ProjectExpression fx = new ProjectExpression(filterPlan, DataType.INTEGER, 0, 0);
          fx.neverUseForRealSetUid(1);
          ConstantExpression fc0 = new ConstantExpression(filterPlan, DataType.INTEGER, new Integer(0));
          EqualExpression eq1 = new EqualExpression(filterPlan, fx, fc0);
          ProjectExpression fanotherx = new ProjectExpression(filterPlan, DataType.INTEGER, 0, 0);
          fanotherx.neverUseForRealSetUid(1);
          ProjectExpression fa = new ProjectExpression(filterPlan, DataType.INTEGER, 0, 2);
          fa.neverUseForRealSetUid(3);
          EqualExpression eq2 = new EqualExpression(filterPlan, fanotherx, fa);
          AndExpression and1 = new AndExpression(filterPlan, eq1, eq2);
          ProjectExpression fb = new ProjectExpression(filterPlan, DataType.INTEGER, 0, 3);
          fb.neverUseForRealSetUid(4);
          ConstantExpression fc1 = new ConstantExpression(filterPlan, DataType.INTEGER, new Integer(1));
          EqualExpression eq3 = new EqualExpression(filterPlan, fb, fc1);
          AndExpression and2 = new AndExpression(filterPlan, and1, eq3);
          ProjectExpression fanotherb = new ProjectExpression(filterPlan, DataType.INTEGER, 0, 3);
          fanotherb.neverUseForRealSetUid(4);
          ProjectExpression fy = new ProjectExpression(filterPlan, DataType.INTEGER, 0, 1);
          fy.neverUseForRealSetUid(2);
          EqualExpression eq4 = new EqualExpression(filterPlan, fy, fanotherb);
          new AndExpression(filterPlan, and2, eq4);
       
          LOFilter D = new LOFilter(lp, filterPlan);
          D.neverUseForRealSetSchema(cschema);
          // Connect D to B, since the transform has happened.
          lp.add(D);
          lp.connect(C, D);
        }
       
        LogicalPlanOptimizer optimizer = new LogicalPlanOptimizer(lp, 500);
        optimizer.optimize();
       
        LogicalPlan expected = new LogicalPlan();
        {
            // A = load
          LogicalSchema aschema = new LogicalSchema();
          aschema.addField(new LogicalSchema.LogicalFieldSchema(
              "x", null, DataType.INTEGER));
          aschema.addField(new LogicalSchema.LogicalFieldSchema(
              "y", null, DataType.INTEGER));
          aschema.getField(0).uid = 1;
          aschema.getField(1).uid = 2;
          LOLoad A = new LOLoad(new FileSpec("bla", new FuncSpec("PigStorage", "\t")), aschema, expected);
          expected.add(A);
         
          // DA = filter
          LogicalExpressionPlan DAfilterPlan = new LogicalExpressionPlan();
          ProjectExpression fx = new ProjectExpression(DAfilterPlan, DataType.INTEGER, 0, 0);
          fx.neverUseForRealSetUid(1);
          ConstantExpression fc0 = new ConstantExpression(DAfilterPlan, DataType.INTEGER, new Integer(0));
          new EqualExpression(DAfilterPlan, fx, fc0);
         
          LOFilter DA = new LOFilter(expected, DAfilterPlan);
          DA.neverUseForRealSetSchema(aschema);
          expected.add(DA);
          expected.connect(A, DA);
         
          // B = load
          LogicalSchema bschema = new LogicalSchema();
          bschema.addField(new LogicalSchema.LogicalFieldSchema(
              "a", null, DataType.INTEGER));
          bschema.addField(new LogicalSchema.LogicalFieldSchema(
              "b", null, DataType.INTEGER));
          bschema.getField(0).uid = 3;
          bschema.getField(1).uid = 4;
          LOLoad B = new LOLoad(null, bschema, expected);
          expected.add(B);
         
          // DB = filter
          LogicalExpressionPlan DBfilterPlan = new LogicalExpressionPlan();
          ProjectExpression fb = new ProjectExpression(DBfilterPlan, DataType.INTEGER, 0, 1);
          fb.neverUseForRealSetUid(4);
          ConstantExpression fc1 = new ConstantExpression(DBfilterPlan, DataType.INTEGER, new Integer(1));
          new EqualExpression(DBfilterPlan, fb, fc1);
         
          LOFilter DB = new LOFilter(expected, DBfilterPlan);
          DB.neverUseForRealSetSchema(bschema);
          expected.add(DB);
          expected.connect(B, DB);
         
          // C = join
          LogicalSchema cschema = new LogicalSchema();
          cschema.addField(new LogicalSchema.LogicalFieldSchema(
              "x", null, DataType.INTEGER));
          cschema.addField(new LogicalSchema.LogicalFieldSchema(
              "y", null, DataType.INTEGER));
          cschema.addField(new LogicalSchema.LogicalFieldSchema(
              "a", null, DataType.INTEGER));
          cschema.addField(new LogicalSchema.LogicalFieldSchema(
              "b", null, DataType.INTEGER));
          cschema.getField(0).uid = 1;
          cschema.getField(1).uid = 2;
          cschema.getField(2).uid = 3;
          cschema.getField(3).uid = 4;
          LogicalExpressionPlan aprojplan = new LogicalExpressionPlan();
          ProjectExpression x = new ProjectExpression(aprojplan, DataType.INTEGER, 0, 0);
          x.neverUseForRealSetUid(1);
          LogicalExpressionPlan bprojplan = new LogicalExpressionPlan();
          ProjectExpression y = new ProjectExpression(bprojplan, DataType.INTEGER, 1, 0);
          y.neverUseForRealSetUid(3);
          MultiMap<Integer, LogicalExpressionPlan> mm =
              new MultiMap<Integer, LogicalExpressionPlan>();
          mm.put(0, aprojplan);
          mm.put(1, bprojplan);
          LOJoin C = new LOJoin(expected, mm, JOINTYPE.HASH, new boolean[] {true, true});
          C.neverUseForRealSetSchema(cschema);
          expected.add(C);
          expected.connect(DA, C);
          expected.connect(DB, C);
         
          // D = filter
          LogicalExpressionPlan filterPlan = new LogicalExpressionPlan();
          ProjectExpression fanotherx = new ProjectExpression(filterPlan, DataType.INTEGER, 0, 0);
          fanotherx.neverUseForRealSetUid(1);
          ProjectExpression fa = new ProjectExpression(filterPlan, DataType.INTEGER, 0, 2);
          fa.neverUseForRealSetUid(3);
          EqualExpression eq2 = new EqualExpression(filterPlan, fanotherx, fa);
          ProjectExpression fanotherb = new ProjectExpression(filterPlan, DataType.INTEGER, 0, 3);
          fanotherb.neverUseForRealSetUid(4);
          ProjectExpression fy = new ProjectExpression(filterPlan, DataType.INTEGER, 0, 1);
          fy.neverUseForRealSetUid(2);
          EqualExpression eq4 = new EqualExpression(filterPlan, fy, fanotherb);
          new AndExpression(filterPlan, eq2, eq4);
         
          LOFilter D = new LOFilter(expected, filterPlan);
          D.neverUseForRealSetSchema(cschema);
View Full Code Here


        IsNullExpression isNull = (IsNullExpression)filPlan.getSources().get(0);
        assertTrue( ls.getField(0).uid != isNull.getUid() );
        assertTrue( ls.getField(1).uid != isNull.getUid() );
       
        assertEquals( ProjectExpression.class, isNull.getExpression().getClass() );
        ProjectExpression prj = (ProjectExpression) isNull.getExpression();
        assertEquals( ls.getField(0).uid, prj.getUid() );
    }
View Full Code Here

        IsNullExpression isNull = (IsNullExpression)notExp.getExpression();
        assertTrue( ls.getField(0).uid != isNull.getUid() );
        assertTrue( ls.getField(1).uid != isNull.getUid() );
       
        assertEquals( ProjectExpression.class, isNull.getExpression().getClass() );
        ProjectExpression prj = (ProjectExpression) isNull.getExpression();
        assertEquals( ls.getField(0).uid, prj.getUid() );
    }
View Full Code Here

        assertEquals( BinCondExpression.class, genExp.getSources().get(0).getClass() );
        BinCondExpression add = (BinCondExpression) genExp.getSources().get(0);
        assertEquals( LessThanExpression.class, add.getCondition().getClass() );
        LessThanExpression lessThan = (LessThanExpression) add.getCondition();
        assertEquals( ProjectExpression.class, lessThan.getLhs().getClass() );
        ProjectExpression prj1 = ((ProjectExpression)lessThan.getLhs());
        ProjectExpression prj2 = ((ProjectExpression)lessThan.getRhs());
        assertEquals( ls.getField(0).uid, prj1.getUid() );
        assertEquals( ProjectExpression.class, lessThan.getRhs().getClass() );
        assertEquals( ls.getField(1).uid, prj2.getUid() );
       
        assertEquals( ProjectExpression.class, add.getLhs().getClass() );
        ProjectExpression prj3 = ((ProjectExpression)add.getLhs());
        assertEquals( ls.getField(1).uid, prj3.getUid() );
        assertEquals( ProjectExpression.class, add.getRhs().getClass() );
        ProjectExpression prj4 = ((ProjectExpression)add.getRhs());
        assertEquals( ls.getField(0).uid, prj4.getUid() );
       
       
        assertEquals( 4, inputPln.getRoots().size() );
        for( PhysicalOperator p : inputPln.getRoots() ) {
            assertEquals( POProject.class, p.getClass() );
View Full Code Here

       
        LogicalExpressionPlan genExp1 = gen.getOutputPlans().get(0);
       
        assertEquals( 1, genExp1.getSources().size() );
        assertEquals( ProjectExpression.class, genExp1.getSources().get(0).getClass() );
        ProjectExpression prj1  = (ProjectExpression) genExp1.getSources().get(0);
        assertEquals( ls.getField(0).uid, prj1.getUid() );
       
        LogicalExpressionPlan genExp2 = gen.getOutputPlans().get(1);
        assertEquals( UserFuncExpression.class, genExp2.getSources().get(0).getClass() );
        assertEquals( ProjectExpression.class, genExp2.getSinks().get(0).getClass() );
        ProjectExpression prj2 = (ProjectExpression)genExp2.getSinks().get(0);
        assertEquals( ls.getField(1).uid, prj2.getUid() );
       
        assertEquals( 1, inputPln1.getLeaves().size() );
        assertEquals( 1, inputPln1.getRoots().size() );
        assertEquals( POProject.class, inputPln1.getLeaves().get(0).getClass() );
        assertEquals( 0, (( POProject) inputPln1.getLeaves().get(0)).getColumn() );
View Full Code Here

       
        LogicalExpressionPlan genExp1 = gen.getOutputPlans().get(0);
       
        assertEquals( 1, genExp1.getSources().size() );
        assertEquals( ProjectExpression.class, genExp1.getSources().get(0).getClass() );
        ProjectExpression prj1  = (ProjectExpression) genExp1.getSources().get(0);
        assertEquals( ls.getField(0).uid, prj1.getUid() );
       
        LogicalExpressionPlan genExp2 = gen.getOutputPlans().get(1);
        assertEquals( UserFuncExpression.class, genExp2.getSources().get(0).getClass() );
        assertEquals( ProjectExpression.class, genExp2.getSinks().get(0).getClass() );
        ProjectExpression prj2 = (ProjectExpression)genExp2.getSinks().get(0);
        assertEquals( ls.getField(1).uid, prj2.getUid() );
        assertEquals( BagDereferenceExpression.class, genExp2.getPredecessors(prj2).get(0).getClass() );
        assertEquals( 0, ((BagDereferenceExpression)genExp2.getPredecessors(prj2).get(0)).getBagColNum() );
       
        assertEquals( 1, inputPln.getRoots().size() );
        assertEquals( POProject.class, inputPln.getRoots().get(0).getClass() );
View Full Code Here

   
    @Test
    public void testBinaryOperatorOrder() throws IOException {
        LogicalExpressionPlan ep = new LogicalExpressionPlan();
        ConstantExpression c = new ConstantExpression(ep, DataType.INTEGER, new Integer(5));
        ProjectExpression p = new ProjectExpression(ep, DataType.INTEGER, 0, 0);
        EqualExpression e = new EqualExpression(ep, p, c);
        assertEquals(p, e.getLhs());
        assertEquals(c, e.getRhs());
       
    }
View Full Code Here

   
    @Test
    public void testExpressionPlanVisitor() throws IOException {
        LogicalExpressionPlan ep = new LogicalExpressionPlan();
        ConstantExpression c = new ConstantExpression(ep, DataType.INTEGER, new Integer(5));
        ProjectExpression p = new ProjectExpression(ep, DataType.INTEGER, 0, 0);
        EqualExpression e = new EqualExpression(ep, p, c);
        ConstantExpression c2 = new ConstantExpression(ep, DataType.BOOLEAN, new Boolean("true"));
        new AndExpression(ep, e, c2);
       
        TestExpressionVisitor v = new TestExpressionVisitor(ep);
View Full Code Here

   
    @Test
    public void testExpressionEquality() {
        LogicalExpressionPlan ep1 = new LogicalExpressionPlan();
        ConstantExpression c1 = new ConstantExpression(ep1, DataType.INTEGER, new Integer(5));
        ProjectExpression p1 = new ProjectExpression(ep1, DataType.INTEGER, 0, 0);
        EqualExpression e1 = new EqualExpression(ep1, p1, c1);
        ConstantExpression ca1 = new ConstantExpression(ep1, DataType.BOOLEAN, new Boolean("true"));
        AndExpression a1 = new AndExpression(ep1, e1, ca1);
       
        LogicalExpressionPlan ep2 = new LogicalExpressionPlan();
        ConstantExpression c2 = new ConstantExpression(ep2, DataType.INTEGER, new Integer(5));
        ProjectExpression p2 = new ProjectExpression(ep2, DataType.INTEGER, 0, 0);
        EqualExpression e2 = new EqualExpression(ep2, p2, c2);
        ConstantExpression ca2 = new ConstantExpression(ep2, DataType.BOOLEAN, new Boolean("true"));
        AndExpression a2 = new AndExpression(ep2, e2, ca2);
       
        assertTrue(ep1.isEqual(ep2));
        assertTrue(c1.isEqual(c2));
        assertTrue(p1.isEqual(p2));
        assertTrue(e1.isEqual(e2));
        assertTrue(ca1.isEqual(ca2));
        assertTrue(a1.isEqual(a2));
       
        LogicalExpressionPlan ep3 = new LogicalExpressionPlan();
        ConstantExpression c3 = new ConstantExpression(ep3, DataType.INTEGER, new Integer(3));
        ProjectExpression p3 = new ProjectExpression(ep3, DataType.INTEGER, 0, 1);
        EqualExpression e3 = new EqualExpression(ep3, p3, c3);
        ConstantExpression ca3 = new ConstantExpression(ep3, DataType.CHARARRAY, "true");
        AndExpression a3 = new AndExpression(ep3, e3, ca3);
       
        assertFalse(ep1.isEqual(ep3));
        assertFalse(c1.isEqual(c3));
        assertFalse(p1.isEqual(p3));
        assertFalse(e1.isEqual(e3));
        assertFalse(ca1.isEqual(ca3));
        assertFalse(a1.isEqual(a3));
       
        LogicalExpressionPlan ep4 = new LogicalExpressionPlan();
        ProjectExpression p4 = new ProjectExpression(ep4, DataType.INTEGER, 1, 0);
       
        assertFalse(ep1.isEqual(ep4));
        assertFalse(p1.isEqual(p4));
    }
View Full Code Here

            cschema.addField(new LogicalSchema.LogicalFieldSchema(
                "x", null, DataType.INTEGER));
            cschema.addField(new LogicalSchema.LogicalFieldSchema(
                "y", null, DataType.INTEGER));
            LogicalExpressionPlan aprojplan = new LogicalExpressionPlan();
            new ProjectExpression(aprojplan, DataType.INTEGER, 0, 0);
            LogicalExpressionPlan bprojplan = new LogicalExpressionPlan();
            new ProjectExpression(bprojplan, DataType.INTEGER, 1, 0);
            MultiMap<Integer, LogicalExpressionPlan> mm =
                new MultiMap<Integer, LogicalExpressionPlan>();
            mm.put(0, aprojplan);
            mm.put(1, bprojplan);
            LOJoin C = new LOJoin(lp, mm, JOINTYPE.HASH, new boolean[] {true, true});
            C.neverUseForRealSetSchema(cschema);
            lp.add(C);
            lp.connect(A, C);
            lp.connect(B, C);
           
            // D = filter
            LogicalExpressionPlan filterPlan = new LogicalExpressionPlan();
            ProjectExpression fy = new ProjectExpression(filterPlan, DataType.INTEGER, 0, 1);
            ConstantExpression fc = new ConstantExpression(filterPlan, DataType.INTEGER, new Integer(0));
            new EqualExpression(filterPlan, fy, fc);
            LOFilter D = new LOFilter(lp, filterPlan);
            D.neverUseForRealSetSchema(cschema);
            lp.add(D);
            lp.connect(C, D);
        }
       
        // Build a second similar plan to test equality
        // A = load
        LogicalPlan lp1 = new LogicalPlan();
        {
            LogicalSchema aschema = new LogicalSchema();
            aschema.addField(new LogicalSchema.LogicalFieldSchema(
                "x", null, DataType.INTEGER));
            LOLoad A = new LOLoad(new FileSpec("/abc",
                new FuncSpec("/fooload", new String[] {"x", "y"})), aschema, lp1);
            lp1.add(A);
           
            // B = load
            LogicalSchema bschema = new LogicalSchema();
            bschema.addField(new LogicalSchema.LogicalFieldSchema(
                "y", null, DataType.INTEGER));
            LOLoad B = new LOLoad(new FileSpec("/def",
                new FuncSpec("PigStorage", "\t")), bschema, lp1);
            lp1.add(B);
           
            // C = join
            LogicalSchema cschema = new LogicalSchema();
            cschema.addField(new LogicalSchema.LogicalFieldSchema(
                "x", null, DataType.INTEGER));
            cschema.addField(new LogicalSchema.LogicalFieldSchema(
                "y", null, DataType.INTEGER));
            LogicalExpressionPlan aprojplan = new LogicalExpressionPlan();
            new ProjectExpression(aprojplan, DataType.INTEGER, 0, 0);
            LogicalExpressionPlan bprojplan = new LogicalExpressionPlan();
            new ProjectExpression(bprojplan, DataType.INTEGER, 1, 0);
            MultiMap<Integer, LogicalExpressionPlan> mm =
                new MultiMap<Integer, LogicalExpressionPlan>();
            mm.put(0, aprojplan);
            mm.put(1, bprojplan);
            LOJoin C = new LOJoin(lp1, mm, JOINTYPE.HASH, new boolean[] {true, true});
            C.neverUseForRealSetSchema(cschema);
            lp1.add(C);
            lp1.connect(A, C);
            lp1.connect(B, C);
               
           
            // D = filter
            LogicalExpressionPlan filterPlan = new LogicalExpressionPlan();
            ProjectExpression fy = new ProjectExpression(filterPlan, DataType.INTEGER, 0, 1);
            ConstantExpression fc = new ConstantExpression(filterPlan, DataType.INTEGER, new Integer(0));
            new EqualExpression(filterPlan, fy, fc);
            LOFilter D = new LOFilter(lp1, filterPlan);
            D.neverUseForRealSetSchema(cschema);
            lp1.add(D);
View Full Code Here

TOP

Related Classes of org.apache.pig.experimental.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.