public PhysicalPlan compile(LogicalPlan plan,
Properties properties) throws FrontendException {
if (plan == null) {
int errCode = 2041;
String msg = "No Plan to compile";
throw new FrontendException(msg, errCode, PigException.BUG);
}
try {
if (getConfiguration().getProperty("pig.usenewlogicalplan", "true").equals("true")) {
log.info("pig.usenewlogicalplan is set to true. New logical plan will be used.");
// translate old logical plan to new plan
LogicalPlanMigrationVistor visitor = new LogicalPlanMigrationVistor(plan);
visitor.visit();
org.apache.pig.newplan.logical.relational.LogicalPlan newPlan = visitor.getNewLogicalPlan();
SchemaResetter schemaResetter = new SchemaResetter(newPlan);
schemaResetter.visit();
HashSet<String> optimizerRules = null;
try {
optimizerRules = (HashSet<String>) ObjectSerializer
.deserialize(pigContext.getProperties().getProperty(
"pig.optimizer.rules"));
} catch (IOException ioe) {
int errCode = 2110;
String msg = "Unable to deserialize optimizer rules.";
throw new FrontendException(msg, errCode, PigException.BUG, ioe);
}
// run optimizer
org.apache.pig.newplan.logical.optimizer.LogicalPlanOptimizer optimizer =
new org.apache.pig.newplan.logical.optimizer.LogicalPlanOptimizer(newPlan, 100, optimizerRules);
optimizer.optimize();
// compute whether output data is sorted or not
SortInfoSetter sortInfoSetter = new SortInfoSetter(newPlan);
sortInfoSetter.visit();
if (pigContext.inExplain==false) {
// Validate input/output file. Currently no validation framework in
// new logical plan, put this validator here first.
// We might decide to move it out to a validator framework in future
InputOutputFileValidator validator = new InputOutputFileValidator(newPlan, pigContext);
validator.validate();
}
// translate new logical plan to physical plan
org.apache.pig.newplan.logical.relational.LogToPhyTranslationVisitor translator =
new org.apache.pig.newplan.logical.relational.LogToPhyTranslationVisitor(newPlan);
translator.setPigContext(pigContext);
translator.visit();
return translator.getPhysicalPlan();
}else{
LogToPhyTranslationVisitor translator =
new LogToPhyTranslationVisitor(plan);
translator.setPigContext(pigContext);
translator.visit();
return translator.getPhysicalPlan();
}
} catch (Exception ve) {
int errCode = 2042;
String msg = "Error in new logical plan. Try -Dpig.usenewlogicalplan=false.";
throw new FrontendException(msg, errCode, PigException.BUG, ve);
}
}