Package org.apache.pig.LoadPushDown

Examples of org.apache.pig.LoadPushDown.RequiredFieldList


        }
       
        Pair<Map<Integer,Set<String>>,Set<Integer>> required =
            requiredItems.get(load);
       
        RequiredFieldList requiredFields = new RequiredFieldList();

        LogicalSchema s = load.getSchema();
        for (int i=0;i<s.size();i++) {
            RequiredField requiredField = null;
            // As we have done processing ahead, we assume that
            // a column is not present in both ColumnPruner and
            // MapPruner
            if( required.first != null && required.first.containsKey(i) ) {
                requiredField = new RequiredField();
                requiredField.setIndex(i);
                requiredField.setType(s.getField(i).type);
                List<RequiredField> subFields = new ArrayList<RequiredField>();
                for( String key : required.first.get(i) ) {
                    RequiredField subField = new RequiredField(key,-1,null,DataType.BYTEARRAY);
                    subFields.add(subField);
                }
                requiredField.setSubFields(subFields);
                requiredFields.add(requiredField);
            }
            if( required.second != null && required.second.contains(i) ) {
                requiredField = new RequiredField();
                requiredField.setIndex(i);
                requiredField.setType(s.getField(i).type);     
                requiredFields.add(requiredField);
            }
        }
       
        boolean[] columnRequired = new boolean[s.size()];
        for (RequiredField rf : requiredFields.getFields())
            columnRequired[rf.getIndex()] = true;
       
        List<Pair<Integer, Integer>> pruneList = new ArrayList<Pair<Integer, Integer>>();
        for (int i=0;i<columnRequired.length;i++)
        {
            if (!columnRequired[i])
                pruneList.add(new Pair<Integer, Integer>(0, i));
        }
        StringBuffer message = new StringBuffer();
        if (pruneList.size()!=0)
        {
            message.append("Columns pruned for " + load.getAlias() + ": ");
            for (int i=0;i<pruneList.size();i++)
            {
                message.append("$"+pruneList.get(i).second);
                if (i!=pruneList.size()-1)
                    message.append(", ");
            }
            log.info(message);
        }
       
        message = new StringBuffer();
        for(RequiredField rf: requiredFields.getFields()) {
            List<RequiredField> sub = rf.getSubFields();
            if (sub != null) {
                message.append("Map key required for " + load.getAlias() + ": $" + rf.getIndex() + "->" + sub + "\n");
            }
        }
        if (message.length()!=0)
            log.info(message);
       
        LoadPushDown.RequiredFieldResponse response = null;
        try {
            LoadFunc loadFunc = load.getLoadFunc();
            if (loadFunc instanceof LoadPushDown) {
                response = ((LoadPushDown)loadFunc).pushProjection(requiredFields);
            }
                               
        } catch (FrontendException e) {
            log.warn("pushProjection on "+load+" throw an exception, skip it");
        }                     
       
        // Loader does not support column pruning, insert foreach     
        if (columnPrune) {
            if (response==null || !response.getRequiredFieldResponse()) {
                LogicalPlan p = (LogicalPlan)load.getPlan();                       
                Operator next = p.getSuccessors(load).get(0);
                // if there is already a LOForEach after load, we don't need to
                // add another LOForEach
                if (next instanceof LOForEach) {
                    return;
                }
               
                LOForEach foreach = new LOForEach(load.getPlan());
               
                // add foreach to the base plan                      
                p.add(foreach);
                              
                p.insertBetween(load, foreach, next);
               
                LogicalPlan innerPlan = new LogicalPlan();
                foreach.setInnerPlan(innerPlan);
               
                // build foreach inner plan
                List<LogicalExpressionPlan> exps = new ArrayList<LogicalExpressionPlan>();             
                LOGenerate gen = new LOGenerate(innerPlan, exps, new boolean[requiredFields.getFields().size()]);
                innerPlan.add(gen);
               
                for (int i=0; i<requiredFields.getFields().size(); i++) {
                    LoadPushDown.RequiredField rf = requiredFields.getFields().get(i);
                    LOInnerLoad innerLoad = new LOInnerLoad(innerPlan, foreach, rf.getIndex());                   
                    innerPlan.add(innerLoad);         
                    innerPlan.connect(innerLoad, gen);
                   
                    LogicalExpressionPlan exp = new LogicalExpressionPlan();
                    ProjectExpression prj = new ProjectExpression(exp, i, -1, gen);
                    exp.add(prj);
                    exps.add(exp);
                }               
              
            } else {
                // columns are pruned, reset schema for LOLoader
                List<Integer> requiredIndexes = new ArrayList<Integer>();
                List<LoadPushDown.RequiredField> fieldList = requiredFields.getFields();
                for (int i=0; i<fieldList.size(); i++) {                   
                    requiredIndexes.add(fieldList.get(i).getIndex());
                }

                load.setRequiredFields(requiredIndexes);
View Full Code Here


    }
   
    // Prune fields of LOLoad, and use ColumePruner to prune all the downstream logical operators
    private void pruneLoader(LOLoad load, RequiredFields loaderRequiredFields) throws FrontendException
    {
        RequiredFieldList requiredFieldList = new RequiredFieldList();

        if (loaderRequiredFields==null || loaderRequiredFields.needAllFields())
            return;
        Schema loadSchema = load.getSchema();
        for (int i=0;i<loaderRequiredFields.size();i++)
        {
            Pair<Integer, Integer> pair = loaderRequiredFields.getField(i);
            MapKeysInfo mapKeysInfo = loaderRequiredFields.getMapKeysInfo(i);
            RequiredField requiredField = new RequiredField();
            requiredField.setIndex(pair.second);
            requiredField.setAlias(loadSchema.getField(pair.second).alias);
            requiredField.setType(loadSchema.getField(pair.second).type);
            if (mapKeysInfo!=null && !mapKeysInfo.needAllKeys())
            {
                List<RequiredField> subFieldList = new ArrayList<RequiredField>();
                for (String key : mapKeysInfo.getKeys())
                {
                    RequiredField mapKeyField = new RequiredField();
                    mapKeyField.setIndex(-1);
                    mapKeyField.setType(DataType.UNKNOWN);
                    mapKeyField.setAlias(key);
                    subFieldList.add(mapKeyField);
                }
                requiredField.setSubFields(subFieldList);
            }
            // Sort requiredFieldList, loader expect required field list sorted by index
            int j=0;
            while (requiredFieldList.getFields().size()>j && requiredFieldList.getFields().get(j).getIndex()<pair.second)
                j++;
            requiredFieldList.getFields().add(j, requiredField);
        }
       
        boolean[] columnRequired = new boolean[load.getSchema().size()];
        RequiredFieldResponse response = null;
        try {
            response = load.pushProjection(requiredFieldList);   
           
        } catch (FrontendException e) {
            log.warn("fieldsToRead on "+load+" throw an exception, skip it");
        }
       
        // If the request is not granted, probably the loader support position prune only,
        // and do not prune map key pruning (such as PigStorage). Drop all map keys (means
        // we do not prune map keys) and try again
        if (response==null || !response.getRequiredFieldResponse())
        {
            for (RequiredField rf : requiredFieldList.getFields())
            {
                if (rf.getType() == DataType.MAP)
                    rf.setSubFields(null);
            }
            try {
                response = load.pushProjection(requiredFieldList);   
            } catch (FrontendException e) {
                log.warn("fieldsToRead on "+load+" throw an exception, skip it");
            }
        }
       
        // Loader does not support column pruning, insert foreach
        LogicalOperator forEach = null;
        if (response==null || !response.getRequiredFieldResponse())
        {
            List<Integer> columnsToProject = new ArrayList<Integer>();
            for (RequiredField rf : requiredFieldList.getFields())
                columnsToProject.add(rf.getIndex());
           
            forEach = load.insertPlainForEachAfter(columnsToProject);
        }
       
        // Begin to prune
        for (Pair<Integer, Integer> pair: loaderRequiredFields.getFields())
            columnRequired[pair.second] = true;
       
        List<Pair<Integer, Integer>> pruneList = new ArrayList<Pair<Integer, Integer>>();
        for (int i=0;i<columnRequired.length;i++)
        {
            if (!columnRequired[i])
                pruneList.add(new Pair<Integer, Integer>(0, i));
        }

        StringBuffer message = new StringBuffer();
        if (pruneList.size()!=0)
        {
            if (forEach == null)
                pruner.addPruneMap(load, pruneList);
            else
                pruner.addPruneMap(forEach, pruneList);

            message.append("Columns pruned for " + load.getAlias() + ": ");
            for (int i=0;i<pruneList.size();i++)
            {
                message.append("$"+pruneList.get(i).second);
                if (i!=pruneList.size()-1)
                    message.append(", ");
            }
            log.info(message);
        }
        else
            log.info("No column pruned for " + load.getAlias());
        message = new StringBuffer();;
        for (RequiredField rf : requiredFieldList.getFields())
        {
            if (rf.getSubFields()!=null)
            {
                message.append("Map key required for " + load.getAlias()+": ");
                if (rf.getIndex()!=-1)
View Full Code Here

                }
               
                Pair<Map<Integer,Set<String>>,Set<Integer>> required =
                    requiredItems.get(load);
               
                RequiredFieldList requiredFields = new RequiredFieldList();

                LogicalSchema s = load.getSchema();
                for (int i=0;i<s.size();i++) {
                    RequiredField requiredField = null;
                    // As we have done processing ahead, we assume that
                    // a column is not present in both ColumnPruner and
                    // MapPruner
                    if( required.first != null && required.first.containsKey(i) ) {
                        requiredField = new RequiredField();
                        requiredField.setIndex(i);
                        requiredField.setType(s.getField(i).type);
                        List<RequiredField> subFields = new ArrayList<RequiredField>();
                        for( String key : required.first.get(i) ) {
                            RequiredField subField = new RequiredField(key,-1,null,DataType.BYTEARRAY);
                            subFields.add(subField);
                        }
                        requiredField.setSubFields(subFields);
                        requiredFields.add(requiredField);
                    }
                    if( required.second != null && required.second.contains(i) ) {
                        requiredField = new RequiredField();
                        requiredField.setIndex(i);
                        requiredField.setType(s.getField(i).type);     
                        requiredFields.add(requiredField);
                    }
                }        
                   
                log.info("Loader for " + load.getAlias() + " is pruned. Load fields " + requiredFields);
                for(RequiredField rf: requiredFields.getFields()) {
                    List<RequiredField> sub = rf.getSubFields();
                    if (sub != null) {
                        // log.info("For column " + rf.getIndex() + ", set map keys: " + sub.toString());
                        log.info("Map key required for " + load.getAlias() + ": $" + rf.getIndex() + "->" + sub);
                    }
                }
               
                LoadPushDown.RequiredFieldResponse response = null;
                try {
                    LoadFunc loadFunc = load.getLoadFunc();
                    if (loadFunc instanceof LoadPushDown) {
                        response = ((LoadPushDown)loadFunc).pushProjection(requiredFields);
                    }
                                       
                } catch (FrontendException e) {
                    log.warn("pushProjection on "+load+" throw an exception, skip it");
                }                     
               
                // Loader does not support column pruning, insert foreach     
                if (columnPrune) {
                    if (response==null || !response.getRequiredFieldResponse()) {
                        LogicalPlan p = (LogicalPlan)load.getPlan();                       
                        Operator next = p.getSuccessors(load).get(0);
                        // if there is already a LOForEach after load, we don't need to
                        // add another LOForEach
                        if (next instanceof LOForEach) {
                            return;
                        }
                       
                        LOForEach foreach = new LOForEach(load.getPlan());
                       
                        // add foreach to the base plan                      
                        p.add(foreach);
                                      
                        Pair<Integer,Integer> disconnectedPos = p.disconnect(load, next);
                        p.connect(load, disconnectedPos.first.intValue(), foreach, 0 );
                        p.connect(foreach, 0, next, disconnectedPos.second.intValue());
                       
                        // add foreach to the subplan
                        subPlan.add(foreach);
                       
                        LogicalPlan innerPlan = new LogicalPlan();
                        foreach.setInnerPlan(innerPlan);
                       
                        // build foreach inner plan
                        List<LogicalExpressionPlan> exps = new ArrayList<LogicalExpressionPlan>();             
                        LOGenerate gen = new LOGenerate(innerPlan, exps, new boolean[requiredFields.getFields().size()]);
                        innerPlan.add(gen);
                       
                        for (int i=0; i<requiredFields.getFields().size(); i++) {
                            LoadPushDown.RequiredField rf = requiredFields.getFields().get(i);
                            LOInnerLoad innerLoad = new LOInnerLoad(innerPlan, foreach, rf.getIndex());
                            innerLoad.getProjection().setUid(foreach);                   
                            innerPlan.add(innerLoad);         
                            innerPlan.connect(innerLoad, gen);
                           
                            LogicalExpressionPlan exp = new LogicalExpressionPlan();
                            ProjectExpression prj = new ProjectExpression(exp, rf.getType(), i, 0);
                            prj.setUid(gen);
                            exp.add(prj);
                            exps.add(exp);
                        }               
                      
                    } else {
                        // columns are pruned, reset schema for LOLoader
                        LogicalSchema newSchema = new LogicalSchema();
                        List<LoadPushDown.RequiredField> fieldList = requiredFields.getFields();
                        for (int i=0; i<fieldList.size(); i++) {               
                            newSchema.addField(s.getField(fieldList.get(i).getIndex()));
                        }

                        load.setScriptSchema(newSchema);
View Full Code Here

        }

        Pair<Map<Integer,Set<String>>,Set<Integer>> required =
            requiredItems.get(load);

        RequiredFieldList requiredFields = new RequiredFieldList();

        LogicalSchema s = load.getSchema();
        for (int i=0;i<s.size();i++) {
            RequiredField requiredField = null;
            // As we have done processing ahead, we assume that
            // a column is not present in both ColumnPruner and
            // MapPruner
            if( required.first != null && required.first.containsKey(i) ) {
                requiredField = new RequiredField();
                requiredField.setIndex(i);
                requiredField.setAlias(s.getField(i).alias);
                requiredField.setType(s.getField(i).type);
                List<RequiredField> subFields = new ArrayList<RequiredField>();
                for( String key : required.first.get(i) ) {
                    RequiredField subField = new RequiredField(key,-1,null,DataType.BYTEARRAY);
                    subFields.add(subField);
                }
                requiredField.setSubFields(subFields);
                requiredFields.add(requiredField);
            }
            if( required.second != null && required.second.contains(i) ) {
                requiredField = new RequiredField();
                requiredField.setIndex(i);
                requiredField.setAlias(s.getField(i).alias);
                requiredField.setType(s.getField(i).type);
                requiredFields.add(requiredField);
            }
        }

        boolean[] columnRequired = new boolean[s.size()];
        for (RequiredField rf : requiredFields.getFields())
            columnRequired[rf.getIndex()] = true;

        List<Pair<Integer, Integer>> pruneList = new ArrayList<Pair<Integer, Integer>>();
        for (int i=0;i<columnRequired.length;i++)
        {
            if (!columnRequired[i])
                pruneList.add(new Pair<Integer, Integer>(0, i));
        }
        StringBuffer message = new StringBuffer();
        if (pruneList.size()!=0)
        {
            message.append("Columns pruned for " + load.getAlias() + ": ");
            for (int i=0;i<pruneList.size();i++)
            {
                message.append("$"+pruneList.get(i).second);
                if (i!=pruneList.size()-1)
                    message.append(", ");
            }
            log.info(message);
        }

        message = new StringBuffer();
        for(RequiredField rf: requiredFields.getFields()) {
            List<RequiredField> sub = rf.getSubFields();
            if (sub != null) {
                message.append("Map key required for " + load.getAlias() + ": $" + rf.getIndex() + "->" + sub + "\n");
            }
        }
        if (message.length()!=0)
            log.info(message);

        LoadPushDown.RequiredFieldResponse response = null;
        try {
            LoadFunc loadFunc = load.getLoadFunc();
            if (loadFunc instanceof LoadPushDown) {
                response = ((LoadPushDown)loadFunc).pushProjection(requiredFields);
            }

        } catch (FrontendException e) {
            log.warn("pushProjection on "+load+" throw an exception, skip it");
        }

        // Loader does not support column pruning, insert foreach
        if (columnPrune) {
            if (response==null || !response.getRequiredFieldResponse()) {
                LogicalPlan p = (LogicalPlan)load.getPlan();
                Operator next = p.getSuccessors(load).get(0);
                // if there is already a LOForEach after load, we don't need to
                // add another LOForEach
                if (next instanceof LOForEach) {
                    return;
                }

                LOForEach foreach = new LOForEach(load.getPlan());

                // add foreach to the base plan
                p.add(foreach);

                p.insertBetween(load, foreach, next);

                LogicalPlan innerPlan = new LogicalPlan();
                foreach.setInnerPlan(innerPlan);

                // build foreach inner plan
                List<LogicalExpressionPlan> exps = new ArrayList<LogicalExpressionPlan>();
                LOGenerate gen = new LOGenerate(innerPlan, exps, new boolean[requiredFields.getFields().size()]);
                innerPlan.add(gen);

                for (int i=0; i<requiredFields.getFields().size(); i++) {
                    LoadPushDown.RequiredField rf = requiredFields.getFields().get(i);
                    LOInnerLoad innerLoad = new LOInnerLoad(innerPlan, foreach, rf.getIndex());
                    innerPlan.add(innerLoad);
                    innerPlan.connect(innerLoad, gen);

                    LogicalExpressionPlan exp = new LogicalExpressionPlan();
                    ProjectExpression prj = new ProjectExpression(exp, i, -1, gen);
                    exp.add(prj);
                    exps.add(exp);
                }

            } else {
                // columns are pruned, reset schema for LOLoader
                List<Integer> requiredIndexes = new ArrayList<Integer>();
                List<LoadPushDown.RequiredField> fieldList = requiredFields.getFields();
                for (int i=0; i<fieldList.size(); i++) {
                    requiredIndexes.add(fieldList.get(i).getIndex());
                }

                load.setRequiredFields(requiredIndexes);
View Full Code Here

        }
       
        Pair<Map<Integer,Set<String>>,Set<Integer>> required =
            requiredItems.get(load);
       
        RequiredFieldList requiredFields = new RequiredFieldList();

        LogicalSchema s = load.getSchema();
        for (int i=0;i<s.size();i++) {
            RequiredField requiredField = null;
            // As we have done processing ahead, we assume that
            // a column is not present in both ColumnPruner and
            // MapPruner
            if( required.first != null && required.first.containsKey(i) ) {
                requiredField = new RequiredField();
                requiredField.setIndex(i);
                requiredField.setAlias(s.getField(i).alias);
                requiredField.setType(s.getField(i).type);
                List<RequiredField> subFields = new ArrayList<RequiredField>();
                for( String key : required.first.get(i) ) {
                    RequiredField subField = new RequiredField(key,-1,null,DataType.BYTEARRAY);
                    subFields.add(subField);
                }
                requiredField.setSubFields(subFields);
                requiredFields.add(requiredField);
            }
            if( required.second != null && required.second.contains(i) ) {
                requiredField = new RequiredField();
                requiredField.setIndex(i);
                requiredField.setAlias(s.getField(i).alias);
                requiredField.setType(s.getField(i).type);     
                requiredFields.add(requiredField);
            }
        }
       
        boolean[] columnRequired = new boolean[s.size()];
        for (RequiredField rf : requiredFields.getFields())
            columnRequired[rf.getIndex()] = true;
       
        List<Pair<Integer, Integer>> pruneList = new ArrayList<Pair<Integer, Integer>>();
        for (int i=0;i<columnRequired.length;i++)
        {
            if (!columnRequired[i])
                pruneList.add(new Pair<Integer, Integer>(0, i));
        }
        StringBuffer message = new StringBuffer();
        if (pruneList.size()!=0)
        {
            message.append("Columns pruned for " + load.getAlias() + ": ");
            for (int i=0;i<pruneList.size();i++)
            {
                message.append("$"+pruneList.get(i).second);
                if (i!=pruneList.size()-1)
                    message.append(", ");
            }
            log.info(message);
        }
       
        message = new StringBuffer();
        for(RequiredField rf: requiredFields.getFields()) {
            List<RequiredField> sub = rf.getSubFields();
            if (sub != null) {
                message.append("Map key required for " + load.getAlias() + ": $" + rf.getIndex() + "->" + sub + "\n");
            }
        }
        if (message.length()!=0)
            log.info(message);
       
        LoadPushDown.RequiredFieldResponse response = null;
        try {
            LoadFunc loadFunc = load.getLoadFunc();
            if (loadFunc instanceof LoadPushDown) {
                response = ((LoadPushDown)loadFunc).pushProjection(requiredFields);
            }
                               
        } catch (FrontendException e) {
            log.warn("pushProjection on "+load+" throw an exception, skip it");
        }                     
       
        // Loader does not support column pruning, insert foreach     
        if (columnPrune) {
            if (response==null || !response.getRequiredFieldResponse()) {
                LogicalPlan p = (LogicalPlan)load.getPlan();                       
                Operator next = p.getSuccessors(load).get(0);
                // if there is already a LOForEach after load, we don't need to
                // add another LOForEach
                if (next instanceof LOForEach) {
                    return;
                }
               
                LOForEach foreach = new LOForEach(load.getPlan());
               
                // add foreach to the base plan                      
                p.add(foreach);
                              
                p.insertBetween(load, foreach, next);
               
                LogicalPlan innerPlan = new LogicalPlan();
                foreach.setInnerPlan(innerPlan);
               
                // build foreach inner plan
                List<LogicalExpressionPlan> exps = new ArrayList<LogicalExpressionPlan>();             
                LOGenerate gen = new LOGenerate(innerPlan, exps, new boolean[requiredFields.getFields().size()]);
                innerPlan.add(gen);
               
                for (int i=0; i<requiredFields.getFields().size(); i++) {
                    LoadPushDown.RequiredField rf = requiredFields.getFields().get(i);
                    LOInnerLoad innerLoad = new LOInnerLoad(innerPlan, foreach, rf.getIndex());                   
                    innerPlan.add(innerLoad);         
                    innerPlan.connect(innerLoad, gen);
                   
                    LogicalExpressionPlan exp = new LogicalExpressionPlan();
                    ProjectExpression prj = new ProjectExpression(exp, i, -1, gen);
                    exp.add(prj);
                    exps.add(exp);
                }               
              
            } else {
                // columns are pruned, reset schema for LOLoader
                List<Integer> requiredIndexes = new ArrayList<Integer>();
                List<LoadPushDown.RequiredField> fieldList = requiredFields.getFields();
                for (int i=0; i<fieldList.size(); i++) {                   
                    requiredIndexes.add(fieldList.get(i).getIndex());
                }

                load.setRequiredFields(requiredIndexes);
View Full Code Here

        }
       
        Pair<Map<Integer,Set<String>>,Set<Integer>> required =
            requiredItems.get(load);
       
        RequiredFieldList requiredFields = new RequiredFieldList();

        LogicalSchema s = load.getSchema();
        for (int i=0;i<s.size();i++) {
            RequiredField requiredField = null;
            // As we have done processing ahead, we assume that
            // a column is not present in both ColumnPruner and
            // MapPruner
            if( required.first != null && required.first.containsKey(i) ) {
                requiredField = new RequiredField();
                requiredField.setIndex(i);
                requiredField.setAlias(s.getField(i).alias);
                requiredField.setType(s.getField(i).type);
                List<RequiredField> subFields = new ArrayList<RequiredField>();
                for( String key : required.first.get(i) ) {
                    RequiredField subField = new RequiredField(key,-1,null,DataType.BYTEARRAY);
                    subFields.add(subField);
                }
                requiredField.setSubFields(subFields);
                requiredFields.add(requiredField);
            }
            if( required.second != null && required.second.contains(i) ) {
                requiredField = new RequiredField();
                requiredField.setIndex(i);
                requiredField.setAlias(s.getField(i).alias);
                requiredField.setType(s.getField(i).type);     
                requiredFields.add(requiredField);
            }
        }
       
        boolean[] columnRequired = new boolean[s.size()];
        for (RequiredField rf : requiredFields.getFields())
            columnRequired[rf.getIndex()] = true;
       
        List<Pair<Integer, Integer>> pruneList = new ArrayList<Pair<Integer, Integer>>();
        for (int i=0;i<columnRequired.length;i++)
        {
            if (!columnRequired[i])
                pruneList.add(new Pair<Integer, Integer>(0, i));
        }
        StringBuffer message = new StringBuffer();
        if (pruneList.size()!=0)
        {
            message.append("Columns pruned for " + load.getAlias() + ": ");
            for (int i=0;i<pruneList.size();i++)
            {
                message.append("$"+pruneList.get(i).second);
                if (i!=pruneList.size()-1)
                    message.append(", ");
            }
            log.info(message);
        }
       
        message = new StringBuffer();
        for(RequiredField rf: requiredFields.getFields()) {
            List<RequiredField> sub = rf.getSubFields();
            if (sub != null) {
                message.append("Map key required for " + load.getAlias() + ": $" + rf.getIndex() + "->" + sub + "\n");
            }
        }
        if (message.length()!=0)
            log.info(message);
       
        LoadPushDown.RequiredFieldResponse response = null;
        try {
            LoadFunc loadFunc = load.getLoadFunc();
            if (loadFunc instanceof LoadPushDown) {
                response = ((LoadPushDown)loadFunc).pushProjection(requiredFields);
            }
                               
        } catch (FrontendException e) {
            log.warn("pushProjection on "+load+" throw an exception, skip it");
        }                     
       
        // Loader does not support column pruning, insert foreach     
        if (columnPrune) {
            if (response==null || !response.getRequiredFieldResponse()) {
                LogicalPlan p = (LogicalPlan)load.getPlan();                       
                Operator next = p.getSuccessors(load).get(0);
                // if there is already a LOForEach after load, we don't need to
                // add another LOForEach
                if (next instanceof LOForEach) {
                    return;
                }
               
                LOForEach foreach = new LOForEach(load.getPlan());
               
                // add foreach to the base plan                      
                p.add(foreach);
                              
                p.insertBetween(load, foreach, next);
               
                LogicalPlan innerPlan = new LogicalPlan();
                foreach.setInnerPlan(innerPlan);
               
                // build foreach inner plan
                List<LogicalExpressionPlan> exps = new ArrayList<LogicalExpressionPlan>();             
                LOGenerate gen = new LOGenerate(innerPlan, exps, new boolean[requiredFields.getFields().size()]);
                innerPlan.add(gen);
               
                for (int i=0; i<requiredFields.getFields().size(); i++) {
                    LoadPushDown.RequiredField rf = requiredFields.getFields().get(i);
                    LOInnerLoad innerLoad = new LOInnerLoad(innerPlan, foreach, rf.getIndex());                   
                    innerPlan.add(innerLoad);         
                    innerPlan.connect(innerLoad, gen);
                   
                    LogicalExpressionPlan exp = new LogicalExpressionPlan();
                    ProjectExpression prj = new ProjectExpression(exp, i, -1, gen);
                    exp.add(prj);
                    exps.add(exp);
                }               
              
            } else {
                // columns are pruned, reset schema for LOLoader
                List<Integer> requiredIndexes = new ArrayList<Integer>();
                List<LoadPushDown.RequiredField> fieldList = requiredFields.getFields();
                for (int i=0; i<fieldList.size(); i++) {                   
                    requiredIndexes.add(fieldList.get(i).getIndex());
                }

                load.setRequiredFields(requiredIndexes);
View Full Code Here

    // test projected tuple. project a subset of fields based on field name.

    List<Field> tFields = thriftToPig.getTStructDescriptor().getFields();
    List<Integer> idxList = Lists.newArrayList();
    RequiredFieldList reqFieldList = new RequiredFieldList();
    for (int i=0; i < tFields.size(); i++) {
      String name = tFields.get(i).getName();
      if (name.hashCode()%2 == 0) {
        RequiredField rf = new RequiredField();
        rf.setAlias(name);
        rf.setIndex(i);
        reqFieldList.add(rf);

        idxList.add(i);
      }
    }
View Full Code Here

      idx++;
    }
  }

  private static RequiredFieldList evenFields(List<FieldDescriptor> protoFields) {
    RequiredFieldList reqList = new RequiredFieldList();

    int i = 0;
    for(FieldDescriptor fd : protoFields) {
      if (i%2 == 0) {
        RequiredField field = new RequiredField();
        field.setAlias(fd.getName());
        field.setIndex(i);
        // field.setType() type is not used
        reqList.add(field);
      }
      i++;
    }
    return reqList;
  }
View Full Code Here

TOP

Related Classes of org.apache.pig.LoadPushDown.RequiredFieldList

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.