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

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


        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");
View Full Code Here


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

    private LogicalSchema translateSchema(Schema schema) {     
        if (schema == null) {
            return null;
        }
       
        LogicalSchema s2 = new LogicalSchema();
        List<Schema.FieldSchema> ll = schema.getFields();
        for (Schema.FieldSchema f: ll) {
            LogicalSchema.LogicalFieldSchema f2 =
                new LogicalSchema.LogicalFieldSchema(f.alias, translateSchema(f.schema), f.type);
                      
            s2.addField(f2);
        }
       
        return s2;
    }
View Full Code Here

    }
   
    public void visit(LOLoad load) throws VisitorException{     
        FileSpec fs = load.getInputFile();
       
        LogicalSchema s = null;
        try {
            s = translateSchema(load.getSchema());
        }catch(Exception e) {
            throw new VisitorException("Failed to translate schema.", e);
        }
View Full Code Here

            // Find the operator this projection references
            LogicalRelationalOperator pred = p.findReferent(currentOp);
           
            // Get the schema for this operator and search it for the matching uid
            int match = -1;
            LogicalSchema schema = pred.getSchema();
            List<LogicalSchema.LogicalFieldSchema> fields = schema.getFields();
            for (int i = 0; i < fields.size(); i++) {
                if (fields.get(i).uid == myUid) {
                    match = i;
                    break;
                }
View Full Code Here

        List<Operator> ll = subPlan.getSources();
        boolean found = false;
        for(Operator op: ll) {
            if (op instanceof LOLoad) {
                Set<Long> uids = (Set<Long>)op.getAnnotation(INPUTUIDS);
                LogicalSchema s = ((LOLoad) op).getSchema();
                Set<Integer> required = getColumns(s, uids);
               
                if (required.size() < s.size()) {
                    op.annotate(REQUIREDCOLS, required);             
                    found = true;
                }
            }
        }
View Full Code Here

    @Override
    public void visitLOLoad(LOLoad load) throws IOException {
        super.visitLOLoad(load);
       
        LogicalSchema s = load.getSchema();
        stampSchema(s);
    }
View Full Code Here

        // First check if we have a load with a map in it or not
        List<Operator> sources = currentPlan.getSources();
       
        boolean hasMap = false;
        for( Operator source : sources ) {
            LogicalSchema schema = ((LogicalRelationalOperator)source).getSchema();
            // If any of the loads has a null schema we dont know the ramifications here
            // so we skip this optimization
            if( schema == null ) {
                return false;
            }
            if( hasMap( schema ) ) {
                hasMap = true;
            }
        }
                   
        // We dont have any map in the first level of schema
        if( !hasMap ) {
            return false;
        }
       
       
        // Now we check what keys are needed
        MapMarker marker = new MapMarker(currentPlan);
        marker.visit();
       
        // Get all Uids from Sinks
        List<Operator> sinks = currentPlan.getSinks();
        Set<Long> sinkMapUids = new HashSet<Long>();
        for( Operator sink : sinks ) {
            LogicalSchema schema = ((LogicalRelationalOperator)sink).getSchema();
            sinkMapUids.addAll( getMapUids( schema ) );
        }
       
       
        // If we have found specific keys which are needed then we return true;
        // Else if we dont have any specific keys we return false
        boolean hasAnnotation = false;
        for( Operator source : sources ) {
            Map<Integer,Set<String>> annotationValue =
                (Map<Integer, Set<String>>) ((LogicalRelationalOperator)source).getAnnotation(REQUIRED_MAPKEYS);
           
            // Now for all full maps found in sinks we cannot prune them at source
            if( ! sinkMapUids.isEmpty() && annotationValue != null &&
                    !annotationValue.isEmpty() ) {
                Integer[] annotationKeyArray = annotationValue.keySet().toArray( new Integer[0] );
                LogicalSchema sourceSchema = ((LogicalRelationalOperator)source).getSchema();
                for( Integer col : annotationKeyArray ) {                 
                    if( sinkMapUids.contains(sourceSchema.getField(col).uid)) {
                        annotationValue.remove( col );
                    }
                }
            }
           
View Full Code Here

           
            if (output == null) {
                return false;
            }
                           
            LogicalSchema s = op.getSchema();
            if (s == null) {
                return false;
            }
                              
            // check if there is already a foreach
            List<Operator> ll = op.getPlan().getSuccessors(op);
            if (ll != null && ll.get(0) instanceof LOForEach) {
                return false;
            }
           
            Set<Integer> cols = new HashSet<Integer>();
            for(long uid: output) {
                int col = s.findField(uid);
                if (col < 0) {
                    throw new RuntimeException("Uid " + uid + " is not in the schema of " + op.getName());
                }
                cols.add(col);
            }
           
            if (cols.size()<s.size()) {
                op.annotate(REQUIREDCOLS, cols);
                return true;
            }
           
            return false;
View Full Code Here

TOP

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

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.