Package org.apache.pig.experimental.logical.relational

Examples of org.apache.pig.experimental.logical.relational.LogicalPlan


        assertFalse(C1.isEqual(C2));
    }
   
    @Test
    public void testJoinDifferentInner() throws IOException {
        LogicalPlan lp = new LogicalPlan();
               LogicalSchema jaschema1 = new LogicalSchema();
       jaschema1.addField(new LogicalSchema.LogicalFieldSchema(
           "x", null, DataType.INTEGER));
       LOLoad A1 = new LOLoad(new FileSpec("/abc",
           new FuncSpec("/fooload", new String[] {"x", "y"})), jaschema1, lp);
       lp.add(A1);
       
        // B = load
        LogicalSchema jbschema1 = new LogicalSchema();
        jbschema1.addField(new LogicalSchema.LogicalFieldSchema(
            "y", null, DataType.INTEGER));
        LOLoad B1 = new LOLoad(new FileSpec("/def",
            new FuncSpec("PigStorage", "\t")), jbschema1, lp);
        lp.add(B1);
       
        // C = join
        LogicalSchema jcschema1 = new LogicalSchema();
        jcschema1.addField(new LogicalSchema.LogicalFieldSchema(
            "x", null, DataType.INTEGER));
        jcschema1.addField(new LogicalSchema.LogicalFieldSchema(
            "y", null, DataType.INTEGER));
        LogicalExpressionPlan aprojplan1 = new LogicalExpressionPlan();
        new ProjectExpression(aprojplan1, DataType.INTEGER, 0, 0);
        LogicalExpressionPlan bprojplan1 = new LogicalExpressionPlan();
        new ProjectExpression(bprojplan1, DataType.INTEGER, 1, 0);
        MultiMap<Integer, LogicalExpressionPlan> mm1 =
            new MultiMap<Integer, LogicalExpressionPlan>();
        mm1.put(0, aprojplan1);
        mm1.put(1, bprojplan1);
        LOJoin C1 = new LOJoin(lp, mm1, JOINTYPE.HASH, new boolean[] {true, true});
        C1.neverUseForRealSetSchema(jcschema1);
        lp.add(C1);
        lp.connect(A1, C1);
        lp.connect(B1, C1);
       
        // Test different inner status
        // A = load
        LogicalSchema jaschema3 = new LogicalSchema();
        jaschema3.addField(new LogicalSchema.LogicalFieldSchema(
           "x", null, DataType.INTEGER));
        LOLoad A3 = new LOLoad(new FileSpec("/abc",
           new FuncSpec("/fooload", new String[] {"x", "y"})), jaschema3, lp);
        lp.add(A3);
       
        // B = load
        LogicalSchema jbschema3 = new LogicalSchema();
        jbschema3.addField(new LogicalSchema.LogicalFieldSchema(
            "y", null, DataType.INTEGER));
        LOLoad B3 = new LOLoad(new FileSpec("/def",
            new FuncSpec("PigStorage", "\t")), jbschema3, lp);
        lp.add(B3);
       
        // C = join
        LogicalSchema jcschema3 = new LogicalSchema();
        jcschema3.addField(new LogicalSchema.LogicalFieldSchema(
            "x", null, DataType.INTEGER));
        jcschema3.addField(new LogicalSchema.LogicalFieldSchema(
            "y", null, DataType.INTEGER));
        LogicalExpressionPlan aprojplan3 = new LogicalExpressionPlan();
        new ProjectExpression(aprojplan3, DataType.INTEGER, 0, 0);
        LogicalExpressionPlan bprojplan3 = new LogicalExpressionPlan();
        new ProjectExpression(bprojplan3, DataType.INTEGER, 1, 0);
        MultiMap<Integer, LogicalExpressionPlan> mm3 =
            new MultiMap<Integer, LogicalExpressionPlan>();
        mm3.put(0, aprojplan3);
        mm3.put(1, bprojplan3);
        LOJoin C3 = new LOJoin(lp, mm3, JOINTYPE.HASH, new boolean[] {true, false});
        C3.neverUseForRealSetSchema(jcschema3);
        lp.add(C3);
        lp.connect(A3, C3);
        lp.connect(B3, C3);
       
       
        assertFalse(C1.isEqual(C3));
    }
View Full Code Here


        assertFalse(C1.isEqual(C3));
    }
    @Test
    public void testJoinDifferentNumInputs() throws IOException {
        LogicalPlan lp = new LogicalPlan();
               LogicalSchema jaschema1 = new LogicalSchema();
       jaschema1.addField(new LogicalSchema.LogicalFieldSchema(
           "x", null, DataType.INTEGER));
       LOLoad A1 = new LOLoad(new FileSpec("/abc",
           new FuncSpec("/fooload", new String[] {"x", "y"})), jaschema1, lp);
       lp.add(A1);
       
        // B = load
        LogicalSchema jbschema1 = new LogicalSchema();
        jbschema1.addField(new LogicalSchema.LogicalFieldSchema(
            "y", null, DataType.INTEGER));
        LOLoad B1 = new LOLoad(new FileSpec("/def",
            new FuncSpec("PigStorage", "\t")), jbschema1, lp);
        lp.add(B1);
       
        // C = join
        LogicalSchema jcschema1 = new LogicalSchema();
        jcschema1.addField(new LogicalSchema.LogicalFieldSchema(
            "x", null, DataType.INTEGER));
        jcschema1.addField(new LogicalSchema.LogicalFieldSchema(
            "y", null, DataType.INTEGER));
        LogicalExpressionPlan aprojplan1 = new LogicalExpressionPlan();
        new ProjectExpression(aprojplan1, DataType.INTEGER, 0, 0);
        LogicalExpressionPlan bprojplan1 = new LogicalExpressionPlan();
        new ProjectExpression(bprojplan1, DataType.INTEGER, 1, 0);
        MultiMap<Integer, LogicalExpressionPlan> mm1 =
            new MultiMap<Integer, LogicalExpressionPlan>();
        mm1.put(0, aprojplan1);
        mm1.put(1, bprojplan1);
        LOJoin C1 = new LOJoin(lp, mm1, JOINTYPE.HASH, new boolean[] {true, true});
        C1.neverUseForRealSetSchema(jcschema1);
        lp.add(C1);
        lp.connect(A1, C1);
        lp.connect(B1, C1);
        // A = load
        LogicalSchema jaschema5 = new LogicalSchema();
        jaschema5.addField(new LogicalSchema.LogicalFieldSchema(
           "x", null, DataType.INTEGER));
        LOLoad A5 = new LOLoad(new FileSpec("/abc",
           new FuncSpec("/fooload", new String[] {"x", "y"})), jaschema5, lp);
        lp.add(A5);
       
        // B = load
        LogicalSchema jbschema5 = new LogicalSchema();
        jbschema5.addField(new LogicalSchema.LogicalFieldSchema(
            "y", null, DataType.INTEGER));
        LOLoad B5 = new LOLoad(new FileSpec("/def",
            new FuncSpec("PigStorage", "\t")), jbschema5, lp);
        lp.add(B5);
       
        // Beta = load
        LogicalSchema jbetaschema5 = new LogicalSchema();
        jbetaschema5.addField(new LogicalSchema.LogicalFieldSchema(
            "y", null, DataType.INTEGER));
        LOLoad Beta5 = new LOLoad(new FileSpec("/ghi",
            new FuncSpec("PigStorage", "\t")), jbetaschema5, lp);
        lp.add(Beta5);
       
        // C = join
        LogicalSchema jcschema5 = new LogicalSchema();
        jcschema5.addField(new LogicalSchema.LogicalFieldSchema(
            "x", null, DataType.INTEGER));
        jcschema5.addField(new LogicalSchema.LogicalFieldSchema(
            "y", null, DataType.INTEGER));
        LogicalExpressionPlan aprojplan5 = new LogicalExpressionPlan();
        new ProjectExpression(aprojplan5, DataType.INTEGER, 0, 0);
        LogicalExpressionPlan bprojplan5 = new LogicalExpressionPlan();
        new ProjectExpression(bprojplan5, DataType.INTEGER, 1, 0);
        LogicalExpressionPlan betaprojplan5 = new LogicalExpressionPlan();
        new ProjectExpression(betaprojplan5, DataType.INTEGER, 1, 0);
        MultiMap<Integer, LogicalExpressionPlan> mm5 =
            new MultiMap<Integer, LogicalExpressionPlan>();
        mm5.put(0, aprojplan5);
        mm5.put(1, bprojplan5);
        mm5.put(2, betaprojplan5);
        LOJoin C5 = new LOJoin(lp, mm5, JOINTYPE.HASH, new boolean[] {true, true});
        C5.neverUseForRealSetSchema(jcschema5);
        lp.add(C5);
        lp.connect(A5, C5);
        lp.connect(B5, C5);
        lp.connect(Beta5, C5);
       
        assertFalse(C1.isEqual(C5));
    }
View Full Code Here

        assertFalse(C1.isEqual(C5));
    }
       
    @Test
    public void testJoinDifferentJoinKeys() throws IOException {
        LogicalPlan lp = new LogicalPlan();
       
        // Test different join keys
        LogicalSchema jaschema6 = new LogicalSchema();
        jaschema6.addField(new LogicalSchema.LogicalFieldSchema(
           "x", null, DataType.INTEGER));
        LOLoad A6 = new LOLoad(new FileSpec("/abc",
           new FuncSpec("/fooload", new String[] {"x", "y"})), jaschema6, lp);
        lp.add(A6);
       
        // B = load
        LogicalSchema jbschema6 = new LogicalSchema();
        jbschema6.addField(new LogicalSchema.LogicalFieldSchema(
            "y", null, DataType.INTEGER));
        jbschema6.addField(new LogicalSchema.LogicalFieldSchema(
            "z", null, DataType.LONG));
        LOLoad B6 = new LOLoad(new FileSpec("/def",
            new FuncSpec("PigStorage", "\t")), jbschema6, lp);
        lp.add(B6);
       
        // C = join
        LogicalSchema jcschema6 = new LogicalSchema();
        jcschema6.addField(new LogicalSchema.LogicalFieldSchema(
            "x", null, DataType.INTEGER));
        jcschema6.addField(new LogicalSchema.LogicalFieldSchema(
            "y", null, DataType.INTEGER));
        LogicalExpressionPlan aprojplan6 = new LogicalExpressionPlan();
        new ProjectExpression(aprojplan6, DataType.INTEGER, 0, 0);
        LogicalExpressionPlan bprojplan6 = new LogicalExpressionPlan();
        new ProjectExpression(bprojplan6, DataType.INTEGER, 1, 0);
        LogicalExpressionPlan b2projplan6 = new LogicalExpressionPlan();
        new ProjectExpression(b2projplan6, DataType.INTEGER, 1, 1);
        MultiMap<Integer, LogicalExpressionPlan> mm6 =
            new MultiMap<Integer, LogicalExpressionPlan>();
        mm6.put(0, aprojplan6);
        mm6.put(1, bprojplan6);
        mm6.put(1, b2projplan6);
        LOJoin C6 = new LOJoin(lp, mm6, JOINTYPE.HASH, new boolean[] {true, true});
        C6.neverUseForRealSetSchema(jcschema6);
        lp.add(C6);
        lp.connect(A6, C6);
        lp.connect(B6, C6);
       
       
        LogicalSchema jaschema7 = new LogicalSchema();
        jaschema7.addField(new LogicalSchema.LogicalFieldSchema(
           "x", null, DataType.INTEGER));
        LOLoad A7 = new LOLoad(new FileSpec("/abc",
           new FuncSpec("/fooload", new String[] {"x", "y"})), jaschema7, lp);
        lp.add(A7);
       
        // B = load
        LogicalSchema jbschema7 = new LogicalSchema();
        jbschema7.addField(new LogicalSchema.LogicalFieldSchema(
            "y", null, DataType.INTEGER));
        jbschema7.addField(new LogicalSchema.LogicalFieldSchema(
            "z", null, DataType.LONG));
        LOLoad B7 = new LOLoad(new FileSpec("/def",
            new FuncSpec("PigStorage", "\t")), jbschema7, lp);
        lp.add(B7);
       
        // C = join
        LogicalSchema jcschema7 = new LogicalSchema();
        jcschema7.addField(new LogicalSchema.LogicalFieldSchema(
            "x", null, DataType.INTEGER));
        jcschema7.addField(new LogicalSchema.LogicalFieldSchema(
            "y", null, DataType.INTEGER));
        LogicalExpressionPlan aprojplan7 = new LogicalExpressionPlan();
        new ProjectExpression(aprojplan7, DataType.INTEGER, 0, 0);
        LogicalExpressionPlan bprojplan7 = new LogicalExpressionPlan();
        new ProjectExpression(bprojplan7, DataType.INTEGER, 1, 1);
        LogicalExpressionPlan b2projplan7 = new LogicalExpressionPlan();
        new ProjectExpression(b2projplan7, DataType.INTEGER, 1, 0);
        MultiMap<Integer, LogicalExpressionPlan> mm7 =
            new MultiMap<Integer, LogicalExpressionPlan>();
        mm7.put(0, aprojplan7);
        mm7.put(1, bprojplan7);
        mm7.put(1, b2projplan7);
        LOJoin C7 = new LOJoin(lp, mm7, JOINTYPE.HASH, new boolean[] {true, true});
        C7.neverUseForRealSetSchema(jcschema7);
        lp.add(C7);
        lp.connect(A7, C7);
        lp.connect(B7, C7);
       
        assertFalse(C6.isEqual(C7));
    }
View Full Code Here

        assertFalse(C6.isEqual(C7));
    }
   
    @Test
    public void testJoinDifferentNumJoinKeys() throws IOException {
        LogicalPlan lp = new LogicalPlan();
       
        // Test different join keys
        LogicalSchema jaschema6 = new LogicalSchema();
        jaschema6.addField(new LogicalSchema.LogicalFieldSchema(
           "x", null, DataType.INTEGER));
        LOLoad A6 = new LOLoad(new FileSpec("/abc",
           new FuncSpec("/fooload", new String[] {"x", "y"})), jaschema6, lp);
        lp.add(A6);
       
        // B = load
        LogicalSchema jbschema6 = new LogicalSchema();
        jbschema6.addField(new LogicalSchema.LogicalFieldSchema(
            "y", null, DataType.INTEGER));
        jbschema6.addField(new LogicalSchema.LogicalFieldSchema(
            "z", null, DataType.LONG));
        LOLoad B6 = new LOLoad(new FileSpec("/def",
            new FuncSpec("PigStorage", "\t")), jbschema6, lp);
        lp.add(B6);
       
        // C = join
        LogicalSchema jcschema6 = new LogicalSchema();
        jcschema6.addField(new LogicalSchema.LogicalFieldSchema(
            "x", null, DataType.INTEGER));
        jcschema6.addField(new LogicalSchema.LogicalFieldSchema(
            "y", null, DataType.INTEGER));
        LogicalExpressionPlan aprojplan6 = new LogicalExpressionPlan();
        new ProjectExpression(aprojplan6, DataType.INTEGER, 0, 0);
        LogicalExpressionPlan bprojplan6 = new LogicalExpressionPlan();
        new ProjectExpression(bprojplan6, DataType.INTEGER, 1, 0);
        LogicalExpressionPlan b2projplan6 = new LogicalExpressionPlan();
        new ProjectExpression(b2projplan6, DataType.INTEGER, 1, 1);
        MultiMap<Integer, LogicalExpressionPlan> mm6 =
            new MultiMap<Integer, LogicalExpressionPlan>();
        mm6.put(0, aprojplan6);
        mm6.put(1, bprojplan6);
        mm6.put(1, b2projplan6);
        LOJoin C6 = new LOJoin(lp, mm6, JOINTYPE.HASH, new boolean[] {true, true});
        C6.neverUseForRealSetSchema(jcschema6);
        lp.add(C6);
        lp.connect(A6, C6);
        lp.connect(B6, C6);
       
        // Test different different number of join keys
        LogicalSchema jaschema8 = new LogicalSchema();
        jaschema8.addField(new LogicalSchema.LogicalFieldSchema(
           "x", null, DataType.INTEGER));
        LOLoad A8 = new LOLoad(new FileSpec("/abc",
           new FuncSpec("/fooload", new String[] {"x", "y"})), jaschema8, lp);
        lp.add(A8);
       
        // B = load
        LogicalSchema jbschema8 = new LogicalSchema();
        jbschema8.addField(new LogicalSchema.LogicalFieldSchema(
            "y", null, DataType.INTEGER));
        jbschema8.addField(new LogicalSchema.LogicalFieldSchema(
            "z", null, DataType.LONG));
        LOLoad B8 = new LOLoad(new FileSpec("/def",
            new FuncSpec("PigStorage", "\t")), jbschema8, lp);
        lp.add(B8);
       
        // C = join
        LogicalSchema jcschema8 = new LogicalSchema();
        jcschema8.addField(new LogicalSchema.LogicalFieldSchema(
            "x", null, DataType.INTEGER));
        jcschema8.addField(new LogicalSchema.LogicalFieldSchema(
            "y", null, DataType.INTEGER));
        LogicalExpressionPlan aprojplan8 = new LogicalExpressionPlan();
        new ProjectExpression(aprojplan8, DataType.INTEGER, 0, 0);
        LogicalExpressionPlan bprojplan8 = new LogicalExpressionPlan();
        new ProjectExpression(bprojplan8, DataType.INTEGER, 1, 0);
        MultiMap<Integer, LogicalExpressionPlan> mm8 =
            new MultiMap<Integer, LogicalExpressionPlan>();
        mm8.put(0, aprojplan8);
        mm8.put(1, bprojplan8);
        LOJoin C8 = new LOJoin(lp, mm8, JOINTYPE.HASH, new boolean[] {true, true});
        C8.neverUseForRealSetSchema(jcschema8);
        lp.add(C8);
        lp.connect(A8, C8);
        lp.connect(B8, C8);
       
        assertFalse(C6.isEqual(C8));
    }
View Full Code Here

        assertFalse(C6.isEqual(C8));
    }
   
    @Test
    public void testRelationalSameOpDifferentPreds() throws IOException {
        LogicalPlan lp1 = new LogicalPlan();
        LogicalSchema aschema1 = new LogicalSchema();
        aschema1.addField(new LogicalSchema.LogicalFieldSchema(
            "x", null, DataType.INTEGER));
        LOLoad A1 = new LOLoad(new FileSpec("/abc",
            new FuncSpec("/fooload", new String[] {"x", "y"})), aschema1, lp1);
        lp1.add(A1);
       
        LogicalExpressionPlan fp1 = new LogicalExpressionPlan();
        ProjectExpression fy1 = new ProjectExpression(fp1, DataType.INTEGER, 0, 0);
        ConstantExpression fc1 = new ConstantExpression(fp1, DataType.INTEGER,
            new Integer(0));
        new EqualExpression(fp1, fy1, fc1);
        LOFilter D1 = new LOFilter(lp1, fp1);
        LogicalSchema cschema = new LogicalSchema();
        cschema.addField(new LogicalSchema.LogicalFieldSchema(
            "x", null, DataType.INTEGER));
        D1.neverUseForRealSetSchema(cschema);
        lp1.add(D1);
        lp1.connect(A1, D1);
       
        LogicalPlan lp2 = new LogicalPlan();
        LOLoad A2 = new LOLoad(new FileSpec("/abc",
            new FuncSpec("/foo", new String[] {"x", "z"})), null, lp2);
        lp2.add(A2);
       
        LogicalExpressionPlan fp2 = new LogicalExpressionPlan();
        ProjectExpression fy2 = new ProjectExpression(fp2, DataType.INTEGER, 0, 0);
        ConstantExpression fc2 = new ConstantExpression(fp2, DataType.INTEGER,
            new Integer(0));
        new EqualExpression(fp2, fy2, fc2);
        LOFilter D2 = new LOFilter(lp2, fp2);
        D2.neverUseForRealSetSchema(cschema);
        lp2.add(D2);
        lp2.connect(A2, D2);
       
        assertFalse(D1.isEqual(D2));
    }
View Full Code Here

       
    }
   
    @Test
    public void testLogicalPlanVisitor() throws IOException {
        LogicalPlan lp = new LogicalPlan();
        LOLoad load = new LOLoad(null, null, lp);
        /*lp.add((LogicalRelationalOperator)null, load,
            (LogicalRelationalOperator)null);*/
        lp.add(load);
       
        TestLogicalVisitor v = new TestLogicalVisitor(lp);
        v.visit();
       
        assertEquals("load ", v.getVisitPlan());
View Full Code Here

        // B = load 'morebla' as (y);
        // C = join A on x, B on y;
        // D = filter C by y > 0;
       
        // A = load
        LogicalPlan lp = 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, lp);
            lp.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, lp);
            lp.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(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);
            lp1.connect(C, D);
               
        }
       
        assertTrue( lp.isEqual(lp1));
    }
View Full Code Here

        // C = join A on x, B on y;
        // D = filter C by y > 0;
        // The plan is built with the filter having been pushed above the join
        // but the listners not yet having been called.
        // A = load
        lp = new LogicalPlan();
        LogicalSchema aschema = new LogicalSchema();
        aschema.addField(new LogicalSchema.LogicalFieldSchema(
            "x", null, DataType.INTEGER));
        aschema.getField(0).uid = 1;
        LOLoad A = new LOLoad(null, aschema, lp);
        lp.add(A);
       
        // B = load
        LogicalSchema bschema = new LogicalSchema();
        bschema.addField(new LogicalSchema.LogicalFieldSchema(
            "y", null, DataType.INTEGER));
        bschema.getField(0).uid = 2;
        LOLoad B = new LOLoad(null, bschema, lp);
        lp.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));
        cschema.getField(0).uid = 1;
        cschema.getField(1).uid = 2;
        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(2);
        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);
        // Don't add it to the plan quite yet
       
        // D = filter
        LogicalExpressionPlan filterPlan = new LogicalExpressionPlan();
        ProjectExpression fy = new ProjectExpression(filterPlan, DataType.INTEGER, 0, 1);
        fy.neverUseForRealSetUid(2);
        ConstantExpression fc = new ConstantExpression(filterPlan, DataType.INTEGER, new Integer(0));
        new EqualExpression(filterPlan, fy, fc);
        LOFilter D = new LOFilter(lp, filterPlan);
        D.neverUseForRealSetSchema(cschema);
        // Connect D to B, since the transform has happened.
        lp.add(D);
        lp.connect(B, D);
       
        // Now add in C, connected to A and D.
        lp.add(C);
        lp.connect(A, C);
        lp.connect(D, C);
       
        changedPlan = new LogicalPlan();
        changedPlan.add(D);
        changedPlan.add(C);
        changedPlan.connect(D, C);
    }
View Full Code Here

       
        // Plan here is
        // Load (name, cuisines{t:(name)}) -> foreach gen name,flatten(cuisines)
        // -> filter name == 'joe' --> stor
       
        LogicalPlan plan = null;
        LOLoad load = null;
        LOForEach foreach = null;
        LOFilter filter = null;
        LOStore stor = null;
       
        plan = new LogicalPlan();
       
        LogicalSchema schema = new LogicalSchema();
        schema.addField(new LogicalSchema.LogicalFieldSchema("name", null, DataType.CHARARRAY));
        LogicalSchema bagSchema = new LogicalSchema();
        LogicalSchema bagTupleSchema = new LogicalSchema();
        bagTupleSchema.addField( new LogicalSchema.LogicalFieldSchema("name", null, DataType.CHARARRAY) );
        bagSchema.addField( new LogicalSchema.LogicalFieldSchema( "t", bagTupleSchema, DataType.TUPLE ) );
        schema.addField(new LogicalSchema.LogicalFieldSchema("cuisines", bagSchema, DataType.BAG));
       
        load = new LOLoad(null, schema, plan);
        load.setAlias("A");
        plan.add(load);
       
        foreach = new LOForEach(plan);
       
        LogicalPlan innerPlan = new LogicalPlan();
        LOInnerLoad innerLoad = new LOInnerLoad(innerPlan, foreach, 0);
        innerPlan.add(innerLoad);
       
        LOInnerLoad innerLoad2 = new LOInnerLoad(innerPlan, foreach, 1);
        innerPlan.add(innerLoad2);
       
        LogicalExpressionPlan namePrj = new LogicalExpressionPlan();       
        ProjectExpression prjName = new ProjectExpression(namePrj, DataType.CHARARRAY, 0, 0);
        namePrj.add(prjName);
       
        LogicalExpressionPlan cuisinesPrj = new LogicalExpressionPlan();
        ProjectExpression prjCuisines = new ProjectExpression(cuisinesPrj, DataType.BAG, 1, 0);
        cuisinesPrj.add(prjCuisines);
       
        List<LogicalExpressionPlan> expPlans = new ArrayList<LogicalExpressionPlan>();
        expPlans.add(namePrj);
        expPlans.add(cuisinesPrj);
       
        boolean flatten[] = new boolean[2];
        flatten[0] = false;
        flatten[1] = true;
       
        LOGenerate generate = new LOGenerate(innerPlan, expPlans, flatten);       
        innerPlan.add(generate);
        innerPlan.connect(innerLoad, generate);
        innerPlan.connect(innerLoad2, generate);
       
        foreach.setInnerPlan(innerPlan);
        foreach.setAlias("B");
        plan.add(foreach);
       
View Full Code Here

       
        // Plan here is
        // Load (name, cuisines{t:(name)}) -> foreach gen name,flatten(cuisines)
        // -> filter $1 == 'joe' --> filter name == 'joe' --> stor
       
        LogicalPlan plan = null;
        LOLoad load = null;
        LOForEach foreach = null;
        LOFilter filter = null;
        LOStore stor = null;
       
        plan = new LogicalPlan();
       
        LogicalSchema schema = new LogicalSchema();
        schema.addField(new LogicalSchema.LogicalFieldSchema("name", null, DataType.CHARARRAY));
        LogicalSchema bagSchema = new LogicalSchema();
        LogicalSchema bagTupleSchema = new LogicalSchema();
        bagTupleSchema.addField( new LogicalSchema.LogicalFieldSchema("name", null, DataType.CHARARRAY) );
        bagSchema.addField( new LogicalSchema.LogicalFieldSchema( "t", bagTupleSchema, DataType.TUPLE ) );
        schema.addField(new LogicalSchema.LogicalFieldSchema("cuisines", bagSchema, DataType.BAG));
       
        load = new LOLoad(null, schema, plan);
        load.setAlias("A");
        plan.add(load);
       
        foreach = new LOForEach(plan);
       
        LogicalPlan innerPlan = new LogicalPlan();
        LOInnerLoad innerLoad = new LOInnerLoad(innerPlan, foreach, 0);
        innerPlan.add(innerLoad);
       
        LOInnerLoad innerLoad2 = new LOInnerLoad(innerPlan, foreach, 1);
        innerPlan.add(innerLoad2);
       
        LogicalExpressionPlan namePrj = new LogicalExpressionPlan();       
        ProjectExpression prjName = new ProjectExpression(namePrj, DataType.CHARARRAY, 0, 0);
        namePrj.add(prjName);
       
        LogicalExpressionPlan cuisinesPrj = new LogicalExpressionPlan();
        ProjectExpression prjCuisines = new ProjectExpression(cuisinesPrj, DataType.BAG, 1, 0);
        cuisinesPrj.add(prjCuisines);
       
        List<LogicalExpressionPlan> expPlans = new ArrayList<LogicalExpressionPlan>();
        expPlans.add(namePrj);
        expPlans.add(cuisinesPrj);
       
        boolean flatten[] = new boolean[2];
        flatten[0] = false;
        flatten[1] = true;
       
        LOGenerate generate = new LOGenerate(innerPlan, expPlans, flatten);       
        innerPlan.add(generate);
        innerPlan.connect(innerLoad, generate);
        innerPlan.connect(innerLoad2, generate);
       
        foreach.setInnerPlan(innerPlan);
        foreach.setAlias("B");
        plan.add(foreach);
       
View Full Code Here

TOP

Related Classes of org.apache.pig.experimental.logical.relational.LogicalPlan

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.