Package org.apache.pig.test.utils

Examples of org.apache.pig.test.utils.LogicalPlanTester


        aschema.addField(new LogicalSchema.LogicalFieldSchema(null, null, DataType.INTEGER));
        assertTrue(schema.isEqual(aschema));
    }      
   
    public void testForeachPlan2() throws Exception {
        LogicalPlanTester lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load '/test/d.txt' as (id, d:bag{t:(id:int, s)});");
        lpt.buildPlan("b = foreach a generate id, FLATTEN(d);");       
        LogicalPlan plan = lpt.buildPlan("store b into '/test/empty';");
       
        // check basics
        org.apache.pig.newplan.logical.relational.LogicalPlan newPlan = migratePlan(plan);
       
        org.apache.pig.newplan.logical.relational.LogicalPlan expected =
View Full Code Here


        assertTrue(schema.getField("id")==schema.getField(0));
        assertTrue(schema.getField("d::id")==schema.getField(1));
    }
   
    public void testCoGroup() throws Exception {
        LogicalPlanTester lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load '/test/d.txt' as (name:chararray, age:int, gpa:float);");
        lpt.buildPlan("b = group a by name;");       
        LogicalPlan plan = lpt.buildPlan("store b into '/test/empty';");
       
        // check basics
        org.apache.pig.newplan.logical.relational.LogicalPlan newPlan = migratePlan(plan);
       
        LogicalSchema loadSchema =
View Full Code Here

        assertEquals( 0, prj.getColNum() );
        assertEquals( 0, prj.getInputNum() );
    }
   
    public void testCoGroup2() throws Exception {
        LogicalPlanTester lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load '/test/d.txt' as (name:chararray, age:int, gpa:float);");
        lpt.buildPlan("b = group a by ( name, age );");
        LogicalPlan plan = lpt.buildPlan("store b into '/test/empty';");
       
        // check basics
        org.apache.pig.newplan.logical.relational.LogicalPlan newPlan = migratePlan(plan);

        LogicalSchema loadSchema =
View Full Code Here

        assertEquals( 1, prj2.getColNum() );
        assertEquals( 0, prj2.getInputNum() );
    }
   
    public void testCoGroup3() throws Exception {
        LogicalPlanTester lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load '/test/d.txt' as (name:chararray, age:int, gpa:float);");
        lpt.buildPlan("b = load '/test/e.txt' as (name:chararray, blah:chararray );");
        lpt.buildPlan("c = group a by name, b by name;");
        LogicalPlan plan = lpt.buildPlan("store c into '/test/empty';");
       
        // check basics
        org.apache.pig.newplan.logical.relational.LogicalPlan newPlan = migratePlan(plan);
       
        assertEquals( LOCogroup.class, newPlan.getSuccessors( newPlan.getSources().get(0) ).get(0).getClass() );
View Full Code Here

        assertEquals( 0, prj2.getColNum() );
        assertEquals( 1, prj2.getInputNum() );
    }
   
    public void testCoGroup4() throws Exception {
        LogicalPlanTester lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load '/test/d.txt' as (name:chararray, age:int, gpa:float);");
        lpt.buildPlan("b = load '/test/e.txt' as (name:chararray, age:int, blah:chararray );");
        lpt.buildPlan("c = group a by ( name, age ), b by ( name, age );");
        LogicalPlan plan = lpt.buildPlan("store c into '/test/empty';");
       
        // check basics
        org.apache.pig.newplan.logical.relational.LogicalPlan newPlan = migratePlan(plan);
       
        assertEquals( LOCogroup.class, newPlan.getSuccessors( newPlan.getSources().get(0) ).get(0).getClass() );
View Full Code Here

    }

    @Test
    public void test1() throws Exception {
        // case 1: simple and implication
        LogicalPlanTester lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by (id > 3) AND (id > 5);");
        org.apache.pig.impl.logicalLayer.LogicalPlan plan = lpt.buildPlan("store b into 'empty';");
        LogicalPlan newLogicalPlan = migratePlan(plan);

        PlanOptimizer optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by (id > 5);");
        plan = lpt.buildPlan("store b into 'empty';");
        LogicalPlan expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 2: simple or implication
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by (id > 3) OR (id > 5);");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by (id > 3);");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 3: constant expression eval
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by (id > 3+4*2);");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by (id > 11);");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 4: simple NOT
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by NOT(NOT(NOT(id > 3)));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by (id <= 3);");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 5: redundant NOT
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by NOT(NOT(id > 3));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by (id > 3);");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 6: negative
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by (id > 3) AND (v1 is null);");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by (id > 3) AND (v1 is null);");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 7: is not null
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by NOT(v1 is null);");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by (v1 is not null);");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 8: combo I
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by NOT((id > 1) OR ((v1 is null) AND (id > 5)));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by (id <= 1);");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 9: combo II: lhs <-> rhs
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by NOT(((id > 5) AND (v1 is null)) OR (id > 1));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by (id <= 1);");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 10: complementary OR
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by ((id < 1) OR (id >= 1));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = load 'd.txt' as (id:int, v1, v2);");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 11: OR Equality elimination
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by ((id < 1) OR (id < 1));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by (id < 1);");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 12: AND Equality elimination
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by ((id < 1) AND (id < 1));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by (id < 1);");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 13: negative case
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by ((id < 1) AND (v1 is null));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by ((id < 1) AND (v1 is NULL));");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 14: combo III
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by NOT((id > 1) OR ((v1 is null) AND (id > 1+2*2)));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by (id <= 1);");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 15: combo III: negative
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by (((id > 5) OR (v1 < 3)) AND ((id > 4) OR (v1 > 5)));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by (((id > 5) OR (v1 < 3)) AND ((id > 4) OR (v1 > 5)));");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 15: combo III: negative
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by (((id > 5) OR (v1 > 3)) AND ((id > 4) OR (v1 > 5)));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by (((id > 5) OR (v1 > 3)) AND ((id > 4) OR (v1 > 5)));");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 16: conflicting OR
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by ((id < 1) OR (id > 1));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by ((id < 1) OR (id > 1));");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 17: conflicting AND: negtive case for now
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by ((id < 1) AND (id > 1));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by ((id < 1) AND (id > 1));");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 18: combo IV: negative
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by (((id > 5) OR (v1 > 3)) AND ((id < 8) OR (v1 > 5)));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by (((id > 5) OR (v1 > 3)) AND ((id < 8) OR (v1 > 5)));");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 19: negative AND
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by (id > 3) AND (id < 5);");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by (id > 3) AND (id < 5);");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 20: negative OR
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by (id > 3) OR (id < 5);");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1, v2)) by (id > 3) OR (id < 5);");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 20: combo V: negative
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by (((v1 > 3) OR (id > 5)) AND ((id < 8) OR (v1 > 5)));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by (((v1 > 3) OR (id > 5)) AND ((id < 8) OR (v1 > 5)));");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 22: combo V: negative
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by (((v1 > 3) OR (id > 5)) AND ((v1 > 5) OR (id < 8)));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by (((v1 > 3) OR (id > 5)) AND ((v1 > 5) OR (id < 8)));");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 23: combo VI: extremely degenerate
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by ((((id > 1) OR (id > 2)) AND ((id > 3) OR (id > 4))) AND (((id > 5) OR (id > 6)) AND ((id > 7) OR (id > 8))));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by (id > 7);");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 24: combo VII: extremely degenerate
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by ((((id > 1) OR (id > 2)) AND ((id > 3) OR (id > 4))) AND (id > 7));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by (id > 7);");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 25: combo VII: extremely degenerate
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by ((((id > 1) OR (id > 2)) AND ((id > 3) OR (id > 4))) AND (((id > 5) AND (id > 7))));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by (id > 7);");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 26: combo VIII: lhs<->rhs for case 25
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by ((((id > 7) AND (id > 5))) AND (((id > 4) OR (id > 3)) AND ((id > 2) OR (id > 1))));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by (id > 7);");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 27: combo VII: rhs<->lhs for case 24
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by ((id > 7) AND (((id > 4) OR (id > 3)) AND ((id > 2) OR (id > 1))));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by (id > 7);");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 28: complex equality
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by (((id > 4) OR (id > 3)) AND ((id > 3) OR (id > 4)));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by (id > 3);");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 29: complex equality
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by (((id > 4) OR (v1 > 3)) AND ((v1 > 3) OR (id > 4)));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by ((id > 4) OR (v1 > 3));");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

        // case 30: complex equality
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by (((id > 4) OR (v1 > 3)) OR ((v1 > 3) OR (id > 4)));");
        plan = lpt.buildPlan("store b into 'empty';");
        newLogicalPlan = migratePlan(plan);

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("b = filter (load 'd.txt' as (id:int, v1:int, v2)) by ((id > 4) OR (v1 > 3));");
        plan = lpt.buildPlan("store b into 'empty';");
        expected = migratePlan(plan);

        assertTrue(expected.isEqual(newLogicalPlan));

    }
View Full Code Here

                } else {
                    script +=  "c = join a by $0 left, b by $0;" ;
                }
                script += "d = order c by $1;";
                // ensure we parse correctly
                LogicalPlanTester lpt = new LogicalPlanTester(pigServer.getPigContext());
                lpt.buildPlan(script);
               
                // run query and test results only once
                if(i == 0) {
                    Util.registerMultiLineQuery(pigServer, script);
                    Iterator<Tuple> it = pigServer.openIterator("d");
View Full Code Here

                } else {
                    script +=  "c = join a by $0 right, b by $0;" ;
                }
                script += "d = order c by $3;";
                // ensure we parse correctly
                LogicalPlanTester lpt = new LogicalPlanTester(pigServer.getPigContext());
                lpt.buildPlan(script);
               
                // run query and test results only once
                if(i == 0) {
                    Util.registerMultiLineQuery(pigServer, script);
                    Iterator<Tuple> it = pigServer.openIterator("d");
View Full Code Here

                } else {
                    script +=  "c = join a by $0 full, b by $0;" ;
                }
                script += "d = order c by $1, $3;";
                // ensure we parse correctly
                LogicalPlanTester lpt = new LogicalPlanTester(pigServer.getPigContext());
                lpt.buildPlan(script);
               
                // run query and test results only once
                if(i == 0) {
                    Util.registerMultiLineQuery(pigServer, script);
                    Iterator<Tuple> it = pigServer.openIterator("d");
View Full Code Here

        }
    }
   
    @Test
    public void testMultiOuterJoinFailure() {
        LogicalPlanTester lpt = new LogicalPlanTester();
        lpt.buildPlan("a = load 'a.txt' as (n:chararray, a:int); ");
        lpt.buildPlan("b = load 'b.txt' as (n:chararray, m:chararray); ");
        lpt.buildPlan("c = load 'c.txt' as (n:chararray, m:chararray); ");
        String[] types = new String[] { "left", "right", "full" };
        for (int i = 0; i < types.length; i++) {
            boolean errCaught = false;
            try {
                lpt.buildPlanThrowExceptionOnError("d = join a by $0 " + types[i] + " outer, b by $0, c by $0;") ;
               
            } catch(Exception e) {
                errCaught = true;
                assertEquals("(left|right|full) outer joins are only supported for two inputs", e.getMessage());
            }
View Full Code Here

TOP

Related Classes of org.apache.pig.test.utils.LogicalPlanTester

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.