Package org.apache.pig.impl.plan

Examples of org.apache.pig.impl.plan.RequiredFields


    public void testQueryUnionWithSchema() throws FrontendException {
        String query = "c = union (load 'a' as (url, hitcount)), (load 'b' as (url, rank));";
        LogicalPlan lp = planTester.buildPlan(query);

        LOUnion union = (LOUnion)lp.getLeaves().get(0);
        RequiredFields unionRelevantFields0 = union.getRelevantInputs(0, 0).get(0);
        assertTrue(unionRelevantFields0.getNeedAllFields() == false);
        assertTrue(unionRelevantFields0.getNeedNoFields() == false);
        assertTrue(unionRelevantFields0.getFields().size() == 1);
        assertTrue(unionRelevantFields0.getFields().contains(new Pair<Integer, Integer>(0, 0)));
       
        RequiredFields unionRelevantFields1 = union.getRelevantInputs(0, 0).get(1);
        assertTrue(unionRelevantFields1.getNeedAllFields() == false);
        assertTrue(unionRelevantFields1.getNeedNoFields() == false);
        assertTrue(unionRelevantFields1.getFields().size() == 1);
        assertTrue(unionRelevantFields1.getFields().contains(new Pair<Integer, Integer>(1, 0)));
    }
View Full Code Here


    public void testQueryFRJoinSchema() throws FrontendException {
        String query = "c = join (load 'a' as (url, hitcount)) by $0, (load 'b' as (url, rank)) by $0 using \"replicated\";";
        LogicalPlan lp = planTester.buildPlan(query);

        LOJoin frjoin = (LOJoin)lp.getLeaves().get(0);
        RequiredFields frjoinRelevantFields0 = frjoin.getRelevantInputs(0, 0).get(0);
        assertTrue(frjoinRelevantFields0.getNeedAllFields() == false);
        assertTrue(frjoinRelevantFields0.getNeedNoFields() == false);
        assertTrue(frjoinRelevantFields0.getFields().size() == 1);
        assertTrue(frjoinRelevantFields0.getFields().get(0).first == 0);
        assertTrue(frjoinRelevantFields0.getFields().get(0).second == 0);
       
        assertTrue(frjoin.getRelevantInputs(0, 0).get(1)==null);
       
        RequiredFields frjoinRelevantFields1 = frjoin.getRelevantInputs(0, 1).get(0);
        assertTrue(frjoinRelevantFields1.getNeedAllFields() == false);
        assertTrue(frjoinRelevantFields1.getNeedNoFields() == false);
        assertTrue(frjoinRelevantFields1.getFields().size() == 1);
        assertTrue(frjoinRelevantFields1.getFields().get(0).first == 0);
        assertTrue(frjoinRelevantFields1.getFields().get(0).second == 1);
       
        assertTrue(frjoin.getRelevantInputs(0, 1).get(1)==null);
       
        RequiredFields frjoinRelevantFields2 = frjoin.getRelevantInputs(0, 2).get(1);
        assertTrue(frjoinRelevantFields2.getNeedAllFields() == false);
        assertTrue(frjoinRelevantFields2.getNeedNoFields() == false);
        assertTrue(frjoinRelevantFields2.getFields().size() == 1);
        assertTrue(frjoinRelevantFields2.getFields().get(0).first == 1);
        assertTrue(frjoinRelevantFields2.getFields().get(0).second == 0);
       
        assertTrue(frjoin.getRelevantInputs(0, 2).get(0)==null);
       
        RequiredFields frjoinRelevantFields3 = frjoin.getRelevantInputs(0, 3).get(1);
        assertTrue(frjoinRelevantFields3.getNeedAllFields() == false);
        assertTrue(frjoinRelevantFields3.getNeedNoFields() == false);
        assertTrue(frjoinRelevantFields3.getFields().size() == 1);
        assertTrue(frjoinRelevantFields3.getFields().get(0).first == 1);
        assertTrue(frjoinRelevantFields3.getFields().get(0).second == 1);
       
        assertTrue(frjoin.getRelevantInputs(0, 3).get(0)==null);
       
        assertTrue(frjoin.getRelevantInputs(0, 4)==null);
    }
View Full Code Here

    public void testQueryJoinWithSchema() throws FrontendException {
        String query = "c = join (load 'a' as (url, hitcount)) by $0, (load 'b' as (url, rank)) by $0;";
        LogicalPlan lp = planTester.buildPlan(query);

        LOJoin join = (LOJoin)lp.getLeaves().get(0);
        RequiredFields joinRelevantFields0 = join.getRelevantInputs(0, 0).get(0);
        assertTrue(joinRelevantFields0.getNeedAllFields() == false);
        assertTrue(joinRelevantFields0.getNeedNoFields() == false);
        assertTrue(joinRelevantFields0.getFields().size() == 1);
        assertTrue(joinRelevantFields0.getFields().get(0).first == 0);
        assertTrue(joinRelevantFields0.getFields().get(0).second == 0);
       
        assertTrue(join.getRelevantInputs(0, 0).get(1)==null);
       
        RequiredFields joinRelevantFields1 = join.getRelevantInputs(0, 1).get(0);
        assertTrue(joinRelevantFields1.getNeedAllFields() == false);
        assertTrue(joinRelevantFields1.getNeedNoFields() == false);
        assertTrue(joinRelevantFields1.getFields().size() == 1);
        assertTrue(joinRelevantFields1.getFields().get(0).first == 0);
        assertTrue(joinRelevantFields1.getFields().get(0).second == 1);
       
        assertTrue(join.getRelevantInputs(0, 1).get(1)==null);
       
        RequiredFields joinRelevantFields2 = join.getRelevantInputs(0, 2).get(1);
        assertTrue(joinRelevantFields2.getNeedAllFields() == false);
        assertTrue(joinRelevantFields2.getNeedNoFields() == false);
        assertTrue(joinRelevantFields2.getFields().size() == 1);
        assertTrue(joinRelevantFields2.getFields().get(0).first == 1);
        assertTrue(joinRelevantFields2.getFields().get(0).second == 0);
       
        assertTrue(join.getRelevantInputs(0, 2).get(0)==null);
       
        RequiredFields joinRelevantFields3 = join.getRelevantInputs(0, 3).get(1);
        assertTrue(joinRelevantFields3.getNeedAllFields() == false);
        assertTrue(joinRelevantFields3.getNeedNoFields() == false);
        assertTrue(joinRelevantFields3.getFields().size() == 1);
        assertTrue(joinRelevantFields3.getFields().get(0).first == 1);
        assertTrue(joinRelevantFields3.getFields().get(0).second == 1);
       
        assertTrue(join.getRelevantInputs(0, 3).get(0)==null);
       
        assertTrue(join.getRelevantInputs(0, 4)==null);
    }
View Full Code Here

    public void testQueryUnionWithMixedSchema() throws FrontendException {
        String query = "c = union (load 'a' as (url, hitcount)), (load 'b');";
        LogicalPlan lp = planTester.buildPlan(query);
        LOUnion union = (LOUnion)lp.getLeaves().get(0);
       
        RequiredFields unionRelevantFields0 = union.getRelevantInputs(0, 0).get(0);
        assertTrue(unionRelevantFields0.getNeedAllFields() == false);
        assertTrue(unionRelevantFields0.getNeedNoFields() == false);
        assertTrue(unionRelevantFields0.getFields().size() == 1);
        assertTrue(unionRelevantFields0.getFields().contains(new Pair<Integer, Integer>(0, 0)));
       
        RequiredFields unionRelevantFields1 = union.getRelevantInputs(0, 0).get(1);
        assertTrue(unionRelevantFields1.getNeedAllFields() == false);
        assertTrue(unionRelevantFields1.getNeedNoFields() == false);
        assertTrue(unionRelevantFields1.getFields().size() == 1);
        assertTrue(unionRelevantFields1.getFields().contains(new Pair<Integer, Integer>(1, 0)));
    }
View Full Code Here

    public void testQueryFilterWithStarNoSchema() throws FrontendException {
        planTester.buildPlan("a = load 'a';");
        LogicalPlan lp = planTester.buildPlan("b = filter a by COUNT(*) == 3;");
       
        LOFilter filter = (LOFilter)lp.getLeaves().get(0);
        RequiredFields filterRelevantFields0 = filter.getRelevantInputs(0, 0).get(0);
        assertTrue(filterRelevantFields0.getNeedAllFields() == false);
        assertTrue(filterRelevantFields0.getNeedNoFields() == false);
        assertTrue(filterRelevantFields0.getFields().size() == 1);
        assertTrue(filterRelevantFields0.getFields().get(0).first == 0);
        assertTrue(filterRelevantFields0.getFields().get(0).second == 0);
       
        RequiredFields filterRelevantFields1 = filter.getRelevantInputs(0, 1).get(0);
        assertTrue(filterRelevantFields1.getNeedAllFields() == false);
        assertTrue(filterRelevantFields1.getNeedNoFields() == false);
        assertTrue(filterRelevantFields1.getFields().size() == 1);
        assertTrue(filterRelevantFields1.getFields().get(0).first == 0);
        assertTrue(filterRelevantFields1.getFields().get(0).second == 1);
    }
View Full Code Here

    public void testQueryOrderByStarNoSchema() throws FrontendException {
        planTester.buildPlan("a = load 'a';");
        LogicalPlan lp = planTester.buildPlan("b = order a by *;");
       
        LOSort sort = (LOSort)lp.getLeaves().get(0);
        RequiredFields sortRelevantFields0 = sort.getRelevantInputs(0, 0).get(0);
        assertTrue(sortRelevantFields0.getNeedAllFields() == false);
        assertTrue(sortRelevantFields0.getNeedNoFields() == false);
        assertTrue(sortRelevantFields0.getFields().size() == 1);
        assertTrue(sortRelevantFields0.getFields().get(0).first == 0);
        assertTrue(sortRelevantFields0.getFields().get(0).second == 0);
       
        RequiredFields sortRelevantFields1 = sort.getRelevantInputs(0, 1).get(0);
        assertTrue(sortRelevantFields1.getNeedAllFields() == false);
        assertTrue(sortRelevantFields1.getNeedNoFields() == false);
        assertTrue(sortRelevantFields1.getFields().size() == 1);
        assertTrue(sortRelevantFields1.getFields().get(0).first == 0);
        assertTrue(sortRelevantFields1.getFields().get(0).second == 1);
    }
View Full Code Here

    public void testQueryGroupByStarNoSchema() throws FrontendException  {
        String query = "foreach (group (load 'a') by *) generate $1 ;";
        LogicalPlan lp = planTester.buildPlan(query);
       
        LOCogroup cogroup = (LOCogroup)lp.getSuccessors(lp.getRoots().get(0)).get(0);
        RequiredFields cogroupRelevantFields0 = cogroup.getRelevantInputs(0, 0).get(0);
        assertTrue(cogroupRelevantFields0.getNeedAllFields() == true);
        assertTrue(cogroupRelevantFields0.getNeedNoFields() == false);
       
        RequiredFields cogroupRelevantFields1 = cogroup.getRelevantInputs(0, 1).get(0);
        assertTrue(cogroupRelevantFields1.getNeedAllFields() == true);
        assertTrue(cogroupRelevantFields1.getNeedNoFields() == false);
       
        LOForEach foreach = (LOForEach)lp.getSuccessors(cogroup).get(0);
        RequiredFields foreachRelevantFields0 = foreach.getRelevantInputs(0, 0).get(0);
        assertTrue(foreachRelevantFields0.needNoFields() == false);
        assertTrue(foreachRelevantFields0.needAllFields() == false);
        assertTrue(foreachRelevantFields0.getFields().size() == 1);
        assertTrue(foreachRelevantFields0.getFields().get(0).first == 0);
        assertTrue(foreachRelevantFields0.getFields().get(0).second == 1);
       
        assertTrue(foreach.getRelevantInputs(0, 1) == null);
    }
View Full Code Here

    public void testQueryFilterStarWithSchema() throws FrontendException {
        planTester.buildPlan("a = load 'a' as (url,hitCount);");
        LogicalPlan lp = planTester.buildPlan("b = filter a by COUNT(*) == 3;");
       
        LOFilter filter = (LOFilter)lp.getLeaves().get(0);
        RequiredFields filterRelevantFields0 = filter.getRelevantInputs(0, 0).get(0);
        assertTrue(filterRelevantFields0.getNeedAllFields() == false);
        assertTrue(filterRelevantFields0.getNeedNoFields() == false);
        assertTrue(filterRelevantFields0.getFields().size() == 1);
        assertTrue(filterRelevantFields0.getFields().get(0).first == 0);
        assertTrue(filterRelevantFields0.getFields().get(0).second == 0);
       
        RequiredFields filterRelevantFields1 = filter.getRelevantInputs(0, 1).get(0);
        assertTrue(filterRelevantFields1.getNeedAllFields() == false);
        assertTrue(filterRelevantFields1.getNeedNoFields() == false);
        assertTrue(filterRelevantFields1.getFields().size() == 1);
        assertTrue(filterRelevantFields1.getFields().get(0).first == 0);
        assertTrue(filterRelevantFields1.getFields().get(0).second == 1);
    }
View Full Code Here

    public void testQuerySplitWithStarSchema() throws FrontendException {
        planTester.buildPlan("a = load 'a' as (url, hitCount);");
        LogicalPlan lp = planTester.buildPlan("split a into b if url == '3', c if COUNT(*) == '3';");
       
        LOSplit split = (LOSplit)lp.getSuccessors(lp.getRoots().get(0)).get(0);
        RequiredFields splitRelevantFields0 = split.getRelevantInputs(0, 0).get(0);
        assertTrue(splitRelevantFields0.needAllFields() == false);
        assertTrue(splitRelevantFields0.needNoFields() == false);
        assertTrue(splitRelevantFields0.getFields().size() == 1);
        assertTrue(splitRelevantFields0.getFields().contains(new Pair<Integer, Integer>(0, 0)));
       
        RequiredFields splitRelevantFields1 = split.getRelevantInputs(0, 1).get(0);
        assertTrue(splitRelevantFields1.needAllFields() == false);
        assertTrue(splitRelevantFields1.needNoFields() == false);
        assertTrue(splitRelevantFields1.getFields().size() == 1);
        assertTrue(splitRelevantFields1.getFields().contains(new Pair<Integer, Integer>(0, 1)));
       
        assertTrue(split.getRelevantInputs(0, 2) == null);

        LOSplitOutput splitb = (LOSplitOutput)lp.getSuccessors(split).get(0);
        RequiredFields splitbRelevantFields0 = splitb.getRelevantInputs(0, 0).get(0);
        assertTrue(splitbRelevantFields0.getNeedAllFields() == false);
        assertTrue(splitbRelevantFields0.getNeedNoFields() == false);
        assertTrue(splitbRelevantFields0.getFields().size() == 1);
        assertTrue(splitbRelevantFields0.getFields().get(0).first == 0);
        assertTrue(splitbRelevantFields0.getFields().get(0).second == 0);
       
        RequiredFields splitbRelevantFields1 = splitb.getRelevantInputs(0, 1).get(0);
        assertTrue(splitbRelevantFields1.getNeedAllFields() == false);
        assertTrue(splitbRelevantFields1.getNeedNoFields() == false);
        assertTrue(splitbRelevantFields1.getFields().size() == 1);
        assertTrue(splitbRelevantFields1.getFields().contains(new Pair<Integer, Integer>(0, 1)));
       
        LOSplitOutput splitc = (LOSplitOutput)lp.getSuccessors(split).get(1);
        RequiredFields splitcRelevantFields0 = splitc.getRelevantInputs(0, 0).get(0);
        assertTrue(splitcRelevantFields0.getNeedAllFields() == false);
        assertTrue(splitcRelevantFields0.getNeedNoFields() == false);
        assertTrue(splitcRelevantFields0.getFields().size() == 1);
        assertTrue(splitcRelevantFields0.getFields().contains(new Pair<Integer, Integer>(0, 0)));
       
        RequiredFields splitcRelevantFields1 = splitc.getRelevantInputs(0, 1).get(0);
        assertTrue(splitcRelevantFields1.getNeedAllFields() == false);
        assertTrue(splitcRelevantFields1.getNeedNoFields() == false);
        assertTrue(splitcRelevantFields1.getFields().size() == 1);
        assertTrue(splitcRelevantFields1.getFields().contains(new Pair<Integer, Integer>(0, 1)));
    }
View Full Code Here

                    groupByStar = true;
                }
            }

            if(groupByStar) {
                requiredFields.add(new RequiredFields(true));
            } else {               
                for (LOProject project : projectSet) {
                    for (int inputColumn : project.getProjection()) {
                        fields.add(new Pair<Integer, Integer>(inputNum, inputColumn));
                    }
                }
       
                if(fields.size() == 0) {
                    requiredFields.add(new RequiredFields(false, true));
                } else {               
                    requiredFields.add(new RequiredFields(new ArrayList<Pair<Integer, Integer>>(fields)));
                }
            }
        }
       
        return (requiredFields.size() == 0? null: requiredFields);
View Full Code Here

TOP

Related Classes of org.apache.pig.impl.plan.RequiredFields

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.