Package org.apache.pig.impl.plan

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


        String query = "foreach (group (load 'a') by $1) generate group, '1' ;";
        LogicalPlan lp = planTester.buildPlan(query);
       
        //check that the loads' projection map is null
        LOLoad loada = (LOLoad) lp.getRoots().get(0);
        ProjectionMap loadaProjectionMap = loada.getProjectionMap();
        assertTrue(loadaProjectionMap.changes() == false);
       
        //check cogroup projection map
        LOCogroup cogroup = (LOCogroup)lp.getSuccessors(loada).get(0);
        ProjectionMap cogroupProjectionMap = cogroup.getProjectionMap();
        assertTrue(cogroupProjectionMap.changes() == true);
       
        MultiMap<Integer, ProjectionMap.Column> cogroupMapFields = cogroupProjectionMap.getMappedFields();
        assertTrue(cogroupMapFields != null);
       
        List<ProjectionMap.Column> mapValues = (ArrayList<ProjectionMap.Column>)cogroupMapFields.get(0);
        assertTrue(mapValues.get(0).getInputColumn().first == 0);
        assertTrue(mapValues.get(0).getInputColumn().second == 1);

        //check the cogroup removed fields is null
        assertTrue(cogroupProjectionMap.getRemovedFields() == null);
       
        //check that cogroup added fields contain [0, 1]
        List<Integer> cogroupAddedFields = cogroupProjectionMap.getAddedFields();
        assertTrue(cogroupAddedFields.size() == 1);
        assertTrue(cogroupAddedFields.get(0) == 1);
       
        //check that the foreach projection map has non-null mappedFields
        LOForEach foreach = (LOForEach)lp.getLeaves().get(0);
        ProjectionMap foreachProjectionMap = foreach.getProjectionMap();
        assertTrue(foreachProjectionMap.changes() == true);       
       
        MultiMap<Integer, ProjectionMap.Column> foreachMapFields = foreachProjectionMap.getMappedFields();
        assertTrue(foreachMapFields != null);
       
        mapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(0);
        assertTrue(mapValues.get(0).getInputColumn().first == 0);
        assertTrue(mapValues.get(0).getInputColumn().second == 0);


        //check that removed fields has all the columns from the input cogroup
        List<Pair<Integer, Integer>> foreachRemovedFields = foreachProjectionMap.getRemovedFields();
        assertTrue(foreachRemovedFields.size() == 1);

        Pair<Integer, Integer> removedField = foreachRemovedFields.get(0);
        assertTrue(removedField.first == 0);
        assertTrue(removedField.second == 1);
       
        //check that added fields contain [1]
        List<Integer> foreachAddedFields = foreachProjectionMap.getAddedFields();
        assertTrue(foreachAddedFields != null);
        assertTrue(foreachAddedFields.size() == 1);
        assertTrue(foreachAddedFields.get(0) == 1);
    }
View Full Code Here


        planTester.buildPlan("a = load 'a' as (url,hitCount);");
        LogicalPlan lp = planTester.buildPlan("b = distinct a;");
       
        //check that the load projection map is null
        LOLoad load = (LOLoad) lp.getRoots().get(0);
        ProjectionMap loadProjectionMap = load.getProjectionMap();
        assertTrue(loadProjectionMap.changes() == false);
       
        //check that the distinct projection map is not null
        LODistinct distinct = (LODistinct)lp.getLeaves().get(0);
        ProjectionMap distinctProjectionMap = distinct.getProjectionMap();
        assertTrue(distinctProjectionMap != null);
        assertTrue(distinctProjectionMap.changes() == false);
    }
View Full Code Here

        String query = "stream (load 'a') through `" + simpleEchoStreamingCommand + "` as (x, y);";
        LogicalPlan lp = planTester.buildPlan(query);
       
        //check that the load projection map is null
        LOLoad load = (LOLoad) lp.getRoots().get(0);
        ProjectionMap loadProjectionMap = load.getProjectionMap();
        assertTrue(loadProjectionMap.changes() == false);
       
        //check that the stream projection map is null
        LOStream stream = (LOStream)lp.getLeaves().get(0);
        ProjectionMap streamProjectionMap = stream.getProjectionMap();
        assertTrue(streamProjectionMap.changes() == true);
        assertTrue(streamProjectionMap.getMappedFields() == null);
        assertTrue(streamProjectionMap.getRemovedFields() == null);
       
        List<Integer> streamAddedFields = streamProjectionMap.getAddedFields();
        assertTrue(streamAddedFields.size() == 2);
        assertTrue(streamAddedFields.get(0) == 0);
        assertTrue(streamAddedFields.get(1) == 1);
    }
View Full Code Here

        String query = "stream (load 'a' as (url, hitCount)) through `" + simpleEchoStreamingCommand + "` as (x, y);";
        LogicalPlan lp = planTester.buildPlan(query);
       
        //check that the load projection map is null
        LOLoad load = (LOLoad) lp.getRoots().get(0);
        ProjectionMap loadProjectionMap = load.getProjectionMap();
        assertTrue(loadProjectionMap.changes() == false);
       
        //check that the stream projection map is null
        LOStream stream = (LOStream)lp.getLeaves().get(0);
        ProjectionMap streamProjectionMap = stream.getProjectionMap();
        assertTrue(streamProjectionMap.changes() == true);
        assertTrue(streamProjectionMap.getMappedFields() == null);
       
        //check that removed fields has all the columns from the input load
        List<Pair<Integer, Integer>> streamRemovedFields = streamProjectionMap.getRemovedFields();
        assertTrue(streamRemovedFields.size() == 2);
        Pair<Integer, Integer> removedField = streamRemovedFields.get(0);
        assertTrue(removedField.first == 0);
        assertTrue(removedField.second == 0);
       
        removedField = streamRemovedFields.get(1);
        assertTrue(removedField.first == 0);
        assertTrue(removedField.second == 1);
       
        List<Integer> streamAddedFields = streamProjectionMap.getAddedFields();
        assertTrue(streamAddedFields.size() == 2);
        assertTrue(streamAddedFields.get(0) == 0);
        assertTrue(streamAddedFields.get(1) == 1);
    }
View Full Code Here

        planTester.buildPlan("c = cogroup a by url, b by url;");
        LogicalPlan lp = planTester.buildPlan("d = foreach c generate group,flatten(a),flatten(b);");

        //check that the loads' projection map is null
        LOLoad loada = (LOLoad) lp.getRoots().get(0);
        ProjectionMap loadaProjectionMap = loada.getProjectionMap();
        assertTrue(loadaProjectionMap.changes() == false);
       
        LOLoad loadb = (LOLoad) lp.getRoots().get(1);
        ProjectionMap loadbProjectionMap = loadb.getProjectionMap();
        assertTrue(loadbProjectionMap.changes() == false);

        //check cogroup projection map
        LOCogroup cogroup = (LOCogroup)lp.getSuccessors(loada).get(0);
        ProjectionMap cogroupProjectionMap = cogroup.getProjectionMap();
        assertTrue(cogroupProjectionMap.changes() == true);
       
        MultiMap<Integer, ProjectionMap.Column> cogroupMapFields = cogroupProjectionMap.getMappedFields();
        assertTrue(cogroupMapFields != null);
       
        List<ProjectionMap.Column> cogroupMapValues = (ArrayList<ProjectionMap.Column>)cogroupMapFields.get(0);
        assertTrue(cogroupMapValues.get(0).getInputColumn().first == 0);
        assertTrue(cogroupMapValues.get(0).getInputColumn().second == 0);
        assertTrue(cogroupMapValues.get(1).getInputColumn().first == 1);
        assertTrue(cogroupMapValues.get(1).getInputColumn().second == 0);
       
        //check that removed fields has hitCount from a and rank from b
        List<Pair<Integer, Integer>> cogroupRemovedFields = cogroupProjectionMap.getRemovedFields();
        assertTrue(cogroupRemovedFields.size() == 2);
        Pair<Integer, Integer> removedField = cogroupRemovedFields.get(0);
        assertTrue(removedField.first == 0);
        assertTrue(removedField.second == 1);
       
        removedField = cogroupRemovedFields.get(1);
        assertTrue(removedField.first == 1);
        assertTrue(removedField.second == 1);

       
        //check that cogroup added fields contain [1, 2]
        List<Integer> cogroupAddedFields = cogroupProjectionMap.getAddedFields();
        assertTrue(cogroupAddedFields.size() == 2);
        assertTrue(cogroupAddedFields.get(0) == 1);
        assertTrue(cogroupAddedFields.get(1) == 2);
       
        //check that the foreach projection map has null mappedFields
        LOForEach foreach = (LOForEach)lp.getLeaves().get(0);
        ProjectionMap foreachProjectionMap = foreach.getProjectionMap();
        assertTrue(foreachProjectionMap.changes() == true);
       
        MultiMap<Integer, ProjectionMap.Column> foreachMapFields = foreachProjectionMap.getMappedFields();
        assertTrue(foreachMapFields != null);
       
        List<ProjectionMap.Column> foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(0);
        assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
        assertTrue(foreachMapValues.get(0).getInputColumn().second == 0);
       
        foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(1);
        assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
        assertTrue(foreachMapValues.get(0).getInputColumn().second == 1);
       
        foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(2);
        assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
        assertTrue(foreachMapValues.get(0).getInputColumn().second == 1);
       
        foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(3);
        assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
        assertTrue(foreachMapValues.get(0).getInputColumn().second == 2);
       
        foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(4);
        assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
        assertTrue(foreachMapValues.get(0).getInputColumn().second == 2);
       
        //check that removed fields is null
        List<Pair<Integer, Integer>> foreachRemovedFields = foreachProjectionMap.getRemovedFields();
        assertTrue(foreachRemovedFields == null);
       
        //check that added fields is null
        List<Integer> foreachAddedFields = foreachProjectionMap.getAddedFields();
        assertTrue(foreachAddedFields == null);
       
        lp = planTester.buildPlan("e = foreach d generate group, a::url, b::url, b::rank, rank;");
       
        foreach = (LOForEach)lp.getLeaves().get(0);
        foreachProjectionMap = foreach.getProjectionMap();
        assertTrue(foreachProjectionMap.changes() == true);
       
        foreachMapFields = foreachProjectionMap.getMappedFields();
        assertTrue(foreachMapFields != null);
       
        foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(0);
        assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
        assertTrue(foreachMapValues.get(0).getInputColumn().second == 0);
       
        foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(1);
        assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
        assertTrue(foreachMapValues.get(0).getInputColumn().second == 1);
       
        foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(2);
        assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
        assertTrue(foreachMapValues.get(0).getInputColumn().second == 3);
       
        foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(3);
        assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
        assertTrue(foreachMapValues.get(0).getInputColumn().second == 4);
       
        foreachMapValues = (ArrayList<ProjectionMap.Column>)foreachMapFields.get(4);
        assertTrue(foreachMapValues.get(0).getInputColumn().first == 0);
        assertTrue(foreachMapValues.get(0).getInputColumn().second == 4);
       
        //check that removed fields is null
        foreachRemovedFields = foreachProjectionMap.getRemovedFields();
        assertTrue(foreachRemovedFields != null);
        assertTrue(foreachRemovedFields.size() == 1);
       
        removedField = foreachRemovedFields.get(0);
        assertTrue(removedField.first == 0);
        assertTrue(removedField.second == 2);
       
        //check that added fields is null
        foreachAddedFields = foreachProjectionMap.getAddedFields();
        assertTrue(foreachAddedFields == null);
    }
View Full Code Here

        String query = "c = cross (load 'a' as (url, hitcount)), (load 'b' as (url, rank));";
        LogicalPlan lp = planTester.buildPlan(query);

        //check that the loads' projection map is null
        LOLoad loada = (LOLoad) lp.getRoots().get(0);
        ProjectionMap loadaProjectionMap = loada.getProjectionMap();
        assertTrue(loadaProjectionMap.changes() == false);
       
        LOLoad loadb = (LOLoad) lp.getRoots().get(1);
        ProjectionMap loadbProjectionMap = loadb.getProjectionMap();
        assertTrue(loadbProjectionMap.changes() == false);
       
        //check cross projection map
        LOCross cross = (LOCross)lp.getSuccessors(loada).get(0);
        ProjectionMap crossProjectionMap = cross.getProjectionMap();
        assertTrue(crossProjectionMap != null);
       
        MultiMap<Integer, ProjectionMap.Column> crossMapFields = crossProjectionMap.getMappedFields();
        assertTrue(crossMapFields != null);
       
        List<ProjectionMap.Column> crossMapValues = (ArrayList<ProjectionMap.Column>)crossMapFields.get(0);
        assertTrue(crossMapValues.get(0).getInputColumn().first == 0);
        assertTrue(crossMapValues.get(0).getInputColumn().second == 0);
       
        crossMapValues = (ArrayList<ProjectionMap.Column>)crossMapFields.get(1);
        assertTrue(crossMapValues.get(0).getInputColumn().first == 0);
        assertTrue(crossMapValues.get(0).getInputColumn().second == 1);
       
        crossMapValues = (ArrayList<ProjectionMap.Column>)crossMapFields.get(2);
        assertTrue(crossMapValues.get(0).getInputColumn().first == 1);
        assertTrue(crossMapValues.get(0).getInputColumn().second == 0);
       
        crossMapValues = (ArrayList<ProjectionMap.Column>)crossMapFields.get(3);
        assertTrue(crossMapValues.get(0).getInputColumn().first == 1);
        assertTrue(crossMapValues.get(0).getInputColumn().second == 1);
       
        //check that removed fields is null
        List<Pair<Integer, Integer>> crossRemovedFields = crossProjectionMap.getRemovedFields();
        assertTrue(crossRemovedFields == null);
       
        //check that added fields is null
        List<Integer> crossAddedFields = crossProjectionMap.getAddedFields();
        assertTrue(crossAddedFields == null);
    }
View Full Code Here

        String query = "c = union (load 'a' as (url, hitcount)), (load 'b' as (url, rank));";
        LogicalPlan lp = planTester.buildPlan(query);

        //check that the loads' projection map is null
        LOLoad loada = (LOLoad) lp.getRoots().get(0);
        ProjectionMap loadaProjectionMap = loada.getProjectionMap();
        assertTrue(loadaProjectionMap.changes() == false);
       
        LOLoad loadb = (LOLoad) lp.getRoots().get(1);
        ProjectionMap loadbProjectionMap = loadb.getProjectionMap();
        assertTrue(loadbProjectionMap.changes() == false);
       
        //check union projection map
        LOUnion union = (LOUnion)lp.getSuccessors(loada).get(0);
        ProjectionMap unionProjectionMap = union.getProjectionMap();
        assertTrue(unionProjectionMap != null);
       
        MultiMap<Integer, ProjectionMap.Column> unionMapFields = unionProjectionMap.getMappedFields();
        assertTrue(unionMapFields != null);

        List<ProjectionMap.Column> unionMapValues = (ArrayList<ProjectionMap.Column>)unionMapFields.get(0);
        assertTrue(unionMapValues.get(0).getInputColumn().first == 0);
        assertTrue(unionMapValues.get(0).getInputColumn().second == 0);
       
        assertTrue(unionMapValues.get(1).getInputColumn().first == 1);
        assertTrue(unionMapValues.get(1).getInputColumn().second == 0);
       
        unionMapValues = (ArrayList<ProjectionMap.Column>)unionMapFields.get(1);
        assertTrue(unionMapValues.get(0).getInputColumn().first == 0);
        assertTrue(unionMapValues.get(0).getInputColumn().second == 1);
       
        assertTrue(unionMapValues.get(1).getInputColumn().first == 1);
        assertTrue(unionMapValues.get(1).getInputColumn().second == 1);
       
        //check that removed fields is null
        List<Pair<Integer, Integer>> unionRemovedFields = unionProjectionMap.getRemovedFields();
        assertTrue(unionRemovedFields == null);
       
        //check that added fields is null
        List<Integer> unionAddedFields = unionProjectionMap.getAddedFields();
        assertTrue(unionAddedFields == null);

    }
View Full Code Here

        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);

        //check that the loads' projection map is null
        LOLoad loada = (LOLoad) lp.getRoots().get(0);
        ProjectionMap loadaProjectionMap = loada.getProjectionMap();
        assertTrue(loadaProjectionMap.changes() == false);
       
        LOLoad loadb = (LOLoad) lp.getRoots().get(1);
        ProjectionMap loadbProjectionMap = loadb.getProjectionMap();
        assertTrue(loadbProjectionMap.changes() == false);
       
        //check frjoin projection map
        LOJoin frjoin = (LOJoin)lp.getSuccessors(loada).get(0);
        ProjectionMap frjoinProjectionMap = frjoin.getProjectionMap();
        assertTrue(frjoinProjectionMap != null);
       
        MultiMap<Integer, ProjectionMap.Column> frjoinMapFields = frjoinProjectionMap.getMappedFields();
        assertTrue(frjoinMapFields != null);

        List<ProjectionMap.Column> frjoinMapValues = (ArrayList<ProjectionMap.Column>)frjoinMapFields.get(0);
        assertTrue(frjoinMapValues.get(0).getInputColumn().first == 0);
        assertTrue(frjoinMapValues.get(0).getInputColumn().second == 0);
       
        frjoinMapValues = (ArrayList<ProjectionMap.Column>)frjoinMapFields.get(1);
        assertTrue(frjoinMapValues.get(0).getInputColumn().first == 0);
        assertTrue(frjoinMapValues.get(0).getInputColumn().second == 1);
       
        frjoinMapValues = (ArrayList<ProjectionMap.Column>)frjoinMapFields.get(2);
        assertTrue(frjoinMapValues.get(0).getInputColumn().first == 1);
        assertTrue(frjoinMapValues.get(0).getInputColumn().second == 0);
       
        frjoinMapValues = (ArrayList<ProjectionMap.Column>)frjoinMapFields.get(3);
        assertTrue(frjoinMapValues.get(0).getInputColumn().first == 1);
        assertTrue(frjoinMapValues.get(0).getInputColumn().second == 1);
       
        //check that removed fields is null
        List<Pair<Integer, Integer>> frjoinRemovedFields = frjoinProjectionMap.getRemovedFields();
        assertTrue(frjoinRemovedFields == null);
       
        //check that added fields is null
        List<Integer> frjoinAddedFields = frjoinProjectionMap.getAddedFields();
        assertTrue(frjoinAddedFields == null);

    }
View Full Code Here

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

        //check that the loads' projection map is null
        LOLoad loada = (LOLoad) lp.getRoots().get(0);
        ProjectionMap loadaProjectionMap = loada.getProjectionMap();
        assertTrue(loadaProjectionMap.changes() == false);
       
        LOLoad loadb = (LOLoad) lp.getRoots().get(1);
        ProjectionMap loadbProjectionMap = loadb.getProjectionMap();
        assertTrue(loadbProjectionMap.changes() == false);
       
        //check join projection map
        LOJoin join = (LOJoin)lp.getSuccessors(loada).get(0);
        ProjectionMap joinProjectionMap = join.getProjectionMap();
        assertTrue(joinProjectionMap != null);
       
        MultiMap<Integer, ProjectionMap.Column> joinMapFields = joinProjectionMap.getMappedFields();
        assertTrue(joinMapFields != null);

        List<ProjectionMap.Column> frjoinMapValues = (ArrayList<ProjectionMap.Column>)joinMapFields.get(0);
        assertTrue(frjoinMapValues.get(0).getInputColumn().first == 0);
        assertTrue(frjoinMapValues.get(0).getInputColumn().second == 0);
       
        frjoinMapValues = (ArrayList<ProjectionMap.Column>)joinMapFields.get(1);
        assertTrue(frjoinMapValues.get(0).getInputColumn().first == 0);
        assertTrue(frjoinMapValues.get(0).getInputColumn().second == 1);
       
        frjoinMapValues = (ArrayList<ProjectionMap.Column>)joinMapFields.get(2);
        assertTrue(frjoinMapValues.get(0).getInputColumn().first == 1);
        assertTrue(frjoinMapValues.get(0).getInputColumn().second == 0);
       
        frjoinMapValues = (ArrayList<ProjectionMap.Column>)joinMapFields.get(3);
        assertTrue(frjoinMapValues.get(0).getInputColumn().first == 1);
        assertTrue(frjoinMapValues.get(0).getInputColumn().second == 1);
       
        //check that removed fields is null
        List<Pair<Integer, Integer>> joinRemovedFields = joinProjectionMap.getRemovedFields();
        assertTrue(joinRemovedFields == null);
       
        //check that added fields is null
        List<Integer> joinAddedFields = joinProjectionMap.getAddedFields();
        assertTrue(joinAddedFields == null);
    }
View Full Code Here

        String query = "c = cross (load 'a' as (url, hitcount)), (load 'b');";
        LogicalPlan lp = planTester.buildPlan(query);

        //check that the loads' projection map is null
        LOLoad loada = (LOLoad) lp.getRoots().get(0);
        ProjectionMap loadaProjectionMap = loada.getProjectionMap();
        assertTrue(loadaProjectionMap.changes() == false);
       
        LOLoad loadb = (LOLoad) lp.getRoots().get(1);
        ProjectionMap loadbProjectionMap = loadb.getProjectionMap();
        assertTrue(loadbProjectionMap.changes() == false);
       
        //check cross projection map
        LOCross cross = (LOCross)lp.getSuccessors(loada).get(0);
        ProjectionMap crossProjectionMap = cross.getProjectionMap();
        assertTrue(crossProjectionMap == null);
    }
View Full Code Here

TOP

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

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.