Package org.apache.pig.test.utils

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


     *
     * @throws IOException
     */
    @Test
    public void testDuplicateInputs() throws IOException {
        LogicalPlanTester lpt = new LogicalPlanTester( pc );
        lpt.buildPlan( "A = load 'file.txt' as (a0:int, a1:double);" );
        lpt.buildPlan( "A1 = foreach A generate (int)a0 as a0, (double)a1 as a1;" );
        lpt.buildPlan( "B = group A1 all;" );
        lpt.buildPlan( "C = foreach B generate A1;" );
        lpt.buildPlan( "D = foreach C generate SUM(A1.a0), AVG(A1.a1);" );
        org.apache.pig.impl.logicalLayer.LogicalPlan plan = lpt.buildPlan( "store D into 'empty';" )
        LogicalPlan newLogicalPlan = migratePlan( plan );
       
        Operator store = newLogicalPlan.getSinks().get(0);
        int forEachCount1 = getForEachOperatorCount( newLogicalPlan );
        LOForEach foreach1 = (LOForEach)newLogicalPlan.getPredecessors(store).get(0);
View Full Code Here


     *
     * @throws IOException
     */
    @Test
    public void testNegative1() throws IOException {
        LogicalPlanTester lpt = new LogicalPlanTester( pc );
        lpt.buildPlan( "A = LOAD 'file.txt' as (a, b, c, d:bag{t:tuple(c0:int,c1:int)});" );
        lpt.buildPlan( "B = FOREACH A GENERATE a+5 AS u, b-c/2 AS v, d AS w;" );
        lpt.buildPlan( "C = FOREACH B { S = ORDER w BY $0; GENERATE $0 as x, COUNT(S) as y; };" );
        org.apache.pig.impl.logicalLayer.LogicalPlan plan = lpt.buildPlan( "store C into 'empty';" )
        LogicalPlan newLogicalPlan = migratePlan( plan );
       
        int forEachCount1 = getForEachOperatorCount( newLogicalPlan );
              
        PlanOptimizer optimizer = new MyPlanOptimizer( newLogicalPlan, 3 );
View Full Code Here

     *
     * @throws IOException
     */
    @Test
    public void testNegative2() throws IOException {
        LogicalPlanTester lpt = new LogicalPlanTester( pc );
        lpt.buildPlan( "A = LOAD 'file.txt' as (a, b, c);" );
        lpt.buildPlan( "B = FOREACH A GENERATE FLATTEN(a), b, c;" );
        lpt.buildPlan( "C = FOREACH B GENERATE $0, $1+$2;" );
        org.apache.pig.impl.logicalLayer.LogicalPlan plan = lpt.buildPlan( "store C into 'empty';" )
        LogicalPlan newLogicalPlan = migratePlan( plan );
       
        int forEachCount1 = getForEachOperatorCount( newLogicalPlan );
              
        PlanOptimizer optimizer = new MyPlanOptimizer( newLogicalPlan, 3 );
View Full Code Here

     *
     * @throws IOException
     */
    @Test  
    public void testJoinInputOrder() throws IOException  {
        LogicalPlanTester lpt = new LogicalPlanTester( pc );
        lpt.buildPlan( "l1 = load 'y' as (a);" );
        lpt.buildPlan( "l2 = load 'z' as (a1,b1,c1,d1);" );
        lpt.buildPlan( "f1 = foreach l2 generate a1, b1, c1, d1;" );
        lpt.buildPlan( "f2 = foreach f1 generate a1, b1, c1;" );
        lpt.buildPlan( "j1 = join f2 by a1, l1 by a using 'replicated';" );
       
        org.apache.pig.impl.logicalLayer.LogicalPlan plan = lpt.buildPlan( "store j1 into 'empty';" )
        LogicalPlan newLogicalPlan = migratePlan( plan );

        int forEachCount1 = getForEachOperatorCount( newLogicalPlan );
        int outputExprCount1 = getOutputExprCount( newLogicalPlan );
              
View Full Code Here

    }      

    @Test
    public void testParallelism() throws Exception{

        LogicalPlanTester tester = new LogicalPlanTester();
        tester.buildPlan("A = LOAD '" + INPUT_FILE + "';");
        tester.buildPlan("B = LOAD '" + INPUT_FILE + "';");
        tester.buildPlan("C = join A by $0, B by $0 using \"merge\" parallel 50;");
        LogicalPlan lp = tester.buildPlan("store C into 'out';");
  PigContext pc = new PigContext(ExecType.MAPREDUCE,cluster.getProperties());
        pc.connect();
  MROperPlan mro = Util.buildMRPlan(Util.buildPhysicalPlan(lp, pc),pc);
        Assert.assertEquals(1,mro.getRoots().get(0).getRequestedParallelism());
    }
View Full Code Here

        Util.deleteFile(cluster, INPUT_FILE);
    }
   
    @Test
    public void testNonCollectableLoader() throws Exception{
        LogicalPlanTester lpt = new LogicalPlanTester();
        lpt.buildPlan("A = LOAD '" + INPUT_FILE + "' as (id, name, grade);");
        LogicalPlan lp = lpt.buildPlan("B = group A by id using 'collected';");
        PigContext pc = new PigContext(ExecType.MAPREDUCE,cluster.getProperties());
        pc.connect();
        try {
            Util.buildMRPlan(Util.buildPhysicalPlan(lp, pc),pc)
            fail("Must throw MRCompiler Exception");
View Full Code Here

    }

    @Test
    public void testCollectedGrpSpecifiedInSingleQuotes1(){
       
        LogicalPlanTester lpt = new LogicalPlanTester();
        lpt.buildPlan("A = LOAD '" + INPUT_FILE + "' as (id, name, grade);");
        LogicalPlan lp = lpt.buildPlan("B = group A by id using 'collected';");
        assertEquals(LOCogroup.GROUPTYPE.COLLECTED, ((LOCogroup)lp.getLeaves().get(0)).getGroupType());
    }
View Full Code Here

    }
   
    @Test
    public void testCollectedGrpSpecifiedInSingleQuotes2(){
       
        LogicalPlanTester lpt = new LogicalPlanTester();
        lpt.buildPlan("A = LOAD '" + INPUT_FILE + "' as (id, name, grade);");
        LogicalPlan lp = lpt.buildPlan("B = group A all using 'regular';");
        assertEquals(LOCogroup.GROUPTYPE.REGULAR, ((LOCogroup)lp.getLeaves().get(0)).getGroupType());
    }
View Full Code Here

    @Test
    public void testValidation() throws Exception{
       
        String outputFileName = "test-output.txt";
        try {
            LogicalPlanTester lpt = new LogicalPlanTester();
            lpt.buildPlan("a = load '" + inputFileName + "' as (c:chararray, " +
                    "i:int,d:double);");
            LogicalPlan lp = lpt.buildPlan("store a into '" + outputFileName + "' using " +
                    "PigStorage();");
            InputOutputFileVisitor visitor = new InputOutputFileVisitor(lp, null, pig.getPigContext());
            visitor.visit();
        } catch (PlanValidationException e){
                // Since output file is not present, validation should pass
View Full Code Here

        String input[] = new String[] { "some data" };
        String outputFileName = "test-output.txt";
        boolean sawException = false;
        try {
            Util.createInputFile(pig.getPigContext(),outputFileName, input);
            LogicalPlanTester lpt = new LogicalPlanTester(pig.getPigContext());
            lpt.buildPlan("a = load '" + inputFileName + "' as (c:chararray, " +
                    "i:int,d:double);");
            LogicalPlan lp = lpt.buildPlan("store a into '" + outputFileName +
                    "' using PigStorage();");
            InputOutputFileVisitor visitor = new InputOutputFileVisitor(lp,
                    new CompilationMessageCollector(), pig.getPigContext());
            visitor.visit();
        } catch (PlanValidationException pve){
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.