Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 package org.apache.pig.newplan.logical.optimizer;
 
 import java.util.List;
 import java.util.Set;
 
 
 public class SchemaResetter extends LogicalRelationalNodesVisitor {
 
     // uid duplicates are removed only after optimizer rule 
     // DuplicateForEachColumnRewrite has run. So disable it in calls before that
     boolean skipDuplicateUidCheck = true;
     
     private void visitAll(Collection<LogicalExpressionPlanlexpPlansthrows FrontendException {
 	for (LogicalExpressionPlan expPlan : lexpPlans) {
 	    FieldSchemaResetter fsResetter = new FieldSchemaResetter(expPlan);
 	    fsResetter.visit();
 	}
     }
     
     public SchemaResetter(OperatorPlan planthrows FrontendException {
         this(planfalse);
     }
 
     public SchemaResetter(OperatorPlan planboolean skipDuplicateUidCheck
             throws FrontendException {
         super(plannew DependencyOrderWalker(plan));
         this. = skipDuplicateUidCheck;
     }
 
     @Override
     public void visit(LOLoad loadthrows FrontendException {
         load.resetSchema();
         validate(load.getSchema());
     }
 
     @Override
     public void visit(LOFilter filterthrows FrontendException {
         filter.resetSchema();
         FieldSchemaResetter fsResetter = new FieldSchemaResetter(filter.getFilterPlan());
         fsResetter.visit();
         validate(filter.getSchema());
     }
     
     @Override
     public void visit(LOStore storethrows FrontendException {
         store.resetSchema();
         validate(store.getSchema());
     }
    
    @Override
    public void visit(LOJoin jointhrows FrontendException {
        join.resetSchema();
        visitAll(join.getExpressionPlanValues());
        validate(join.getSchema());
    }
    
    @Override
    public void visit(LOForEach foreachthrows FrontendException {
        foreach.resetSchema();
        OperatorPlan innerPlan = foreach.getInnerPlan();
        PlanWalker newWalker = .spawnChildWalker(innerPlan);
        pushWalker(newWalker);
        .walk(this);
        popWalker();
        validate(foreach.getSchema());
    }
    
    @Override
    public void visit(LOGenerate genthrows FrontendException {
        gen.resetSchema();
        visitAll(gen.getOutputPlans());
        validate(gen.getSchema());
    }
    
    @Override
    public void visit(LOInnerLoad loadthrows FrontendException {
        load.resetSchema();
        load.getProjection().resetFieldSchema();
        load.getSchema();
    }
    @Override
    public void visit(LOCube loCubethrows FrontendException {
	loCube.resetSchema();
    }
    
    @Override
    public void visit(LOCogroup loCogroupthrows FrontendException {
        loCogroup.resetSchema();
        visitAll(loCogroup.getExpressionPlans().values());
        validate(loCogroup.getSchema());
    }
    
    @Override
    public void visit(LOSplit loSplitthrows FrontendException {
        loSplit.resetSchema();
        validate(loSplit.getSchema());
    }
    
    @Override
    public void visit(LOSplitOutput loSplitOutputthrows FrontendException {
        loSplitOutput.resetSchema();
        FieldSchemaResetter fsResetter = new FieldSchemaResetter(loSplitOutput.getFilterPlan());
        fsResetter.visit();
        validate(loSplitOutput.getSchema());
    }
    
    @Override
    public void visit(LOUnion loUnionthrows FrontendException {
        loUnion.resetSchema();
        validate(loUnion.getSchema());
    }
    
    @Override
    public void visit(LOSort loSortthrows FrontendException {
        loSort.resetSchema();
        visitAll(loSort.getSortColPlans());
        validate(loSort.getSchema());
    }
    @Override
    public void visit(LORank loRankthrows FrontendException{
        loRank.resetSchema();
        visitAll(loRank.getRankColPlans());
        validate(loRank.getSchema());
    }
    @Override
    public void visit(LODistinct loDistinctthrows FrontendException {
        loDistinct.resetSchema();
        validate(loDistinct.getSchema());
    }
    @Override
    public void visit(LOLimit loLimitthrows FrontendException {
        loLimit.resetSchema();
        if (loLimit.getLimitPlan() != null) {
            FieldSchemaResetter fsResetter = new FieldSchemaResetter(
                    loLimit.getLimitPlan());
            fsResetter.visit();
        }
        validate(loLimit.getSchema());
    }
    
    @Override
    public void visit(LOCross loCrossthrows FrontendException {
        loCross.resetSchema();
        validate(loCross.getSchema());
    }
    
    @Override
    public void visit(LOStream loStreamthrows FrontendException {
        loStream.resetSchema();
        validate(loStream.getSchema());
    }


    
Check if schema is valid (ready to be part of a final logical plan)

Parameters:
schema
Throws:
org.apache.pig.impl.plan.PlanValidationException if the if any field in schema has uid -1 or (skipDuplicateUidCheck is true and there are duplicate uids in schema)
    public void validate(LogicalSchema schema)
            throws PlanValidationException{
        
        if(schema == null)
            return;
        
        Set<LonguidsSeen = new HashSet<Long>();
        for(LogicalFieldSchema fs : schema.getFields()){
            
            if(!){
                //check duplicate uid
                if(!uidsSeen.add(fs.uid)){
                    // uid already seen
                    String msg = "Logical plan invalid state: duplicate uid in " +
                            "schema : " + schema;
                    throw new PlanValidationException(
                            msg,
                            2270,
                            .
                            );
                }
            }
            
            if(fs.uid < 0){
                String msg = "Logical plan invalid state: invalid uid " + fs.uid + 
                        " in schema : " + schema;
                throw new PlanValidationException(
                        msg,
                        2271,
                        .
                        );
                
            }
        }
    }
    protected FieldSchemaResetter(OperatorPlan pthrows FrontendException {
        super(pnew ReverseDependencyOrderWalker(p));
    }
    @Override
    protected void execute(LogicalExpression opthrows FrontendException {
        op.resetFieldSchema();
        op.getFieldSchema();
    }
New to GrepCode? Check out our FAQ X