* @throws RecognitionException
*/
LogicalExpression buildProjectExpr(SourceLocation loc, LogicalExpressionPlan plan, LogicalRelationalOperator op,
Map<String, Operator> operators, Map<String, LogicalExpressionPlan> exprPlans, String colAlias, int col)
throws RecognitionException {
ProjectExpression result = null;
if( colAlias != null ) {
LogicalExpressionPlan exprPlan = exprPlans.get( colAlias );
if( exprPlan != null ) {
LogicalExpressionPlan planCopy = null;
try {
planCopy = exprPlan.deepCopy();
plan.merge( planCopy );
} catch (FrontendException ex) {
throw new PlanGenerationFailureException( intStream, loc, ex );
}
// The projected alias is actually expression alias, so the projections in the represented
// expression doesn't have any operator associated with it. We need to set it when we
// substitute the expression alias with the its expression.
if( op != null ) {
Iterator<Operator> it = plan.getOperators();
while( it.hasNext() ) {
Operator o = it.next();
if( o instanceof ProjectExpression ) {
ProjectExpression projExpr = (ProjectExpression)o;
projExpr.setAttachedRelationalOp( op );
}
}
}
LogicalExpression root = (LogicalExpression)planCopy.getSources().get( 0 );// get the root of the plan
LogicalFieldSchema schema;
try {
schema = root.getFieldSchema();
if (schema.alias == null) {
schema.alias = colAlias;
}
} catch (FrontendException e) {
// Sometimes it can throw an exception. If it does, then there is no schema to get
}
return root;
} else {
result = new ProjectExpression( plan, 0, colAlias, operators.get( colAlias ), op );
result.setLocation( loc );
return result;
}
}
result = new ProjectExpression( plan, 0, col, op );
result.setLocation( loc );
return result;
}