pig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject svn commit: r982345 [2/13] - in /hadoop/pig/trunk: ./ src/org/apache/pig/ src/org/apache/pig/backend/hadoop/executionengine/ src/org/apache/pig/experimental/ src/org/apache/pig/newplan/ src/org/apache/pig/newplan/logical/ src/org/apache/pig/newplan/log...
Date Wed, 04 Aug 2010 17:46:48 GMT
Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/LogicalExpPlanMigrationVistor.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/LogicalExpPlanMigrationVistor.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/LogicalExpPlanMigrationVistor.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/LogicalExpPlanMigrationVistor.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,347 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.pig.impl.logicalLayer.ExpressionOperator;
+import org.apache.pig.impl.logicalLayer.FrontendException;
+import org.apache.pig.impl.logicalLayer.LOAdd;
+import org.apache.pig.impl.logicalLayer.LOAnd;
+import org.apache.pig.impl.logicalLayer.LOBinCond;
+import org.apache.pig.impl.logicalLayer.LOCast;
+import org.apache.pig.impl.logicalLayer.LOConst;
+import org.apache.pig.impl.logicalLayer.LODivide;
+import org.apache.pig.impl.logicalLayer.LOEqual;
+import org.apache.pig.impl.logicalLayer.LOGreaterThan;
+import org.apache.pig.impl.logicalLayer.LOGreaterThanEqual;
+import org.apache.pig.impl.logicalLayer.LOIsNull;
+import org.apache.pig.impl.logicalLayer.LOLesserThan;
+import org.apache.pig.impl.logicalLayer.LOLesserThanEqual;
+import org.apache.pig.impl.logicalLayer.LOMapLookup;
+import org.apache.pig.impl.logicalLayer.LOMod;
+import org.apache.pig.impl.logicalLayer.LOMultiply;
+import org.apache.pig.impl.logicalLayer.LONegative;
+import org.apache.pig.impl.logicalLayer.LONot;
+import org.apache.pig.impl.logicalLayer.LONotEqual;
+import org.apache.pig.impl.logicalLayer.LOOr;
+import org.apache.pig.impl.logicalLayer.LOProject;
+import org.apache.pig.impl.logicalLayer.LORegexp;
+import org.apache.pig.impl.logicalLayer.LOSubtract;
+import org.apache.pig.impl.logicalLayer.LOUserFunc;
+import org.apache.pig.impl.logicalLayer.LOVisitor;
+import org.apache.pig.impl.logicalLayer.LogicalOperator;
+import org.apache.pig.impl.logicalLayer.LogicalPlan;
+import org.apache.pig.impl.logicalLayer.schema.Schema.FieldSchema;
+import org.apache.pig.impl.plan.DependencyOrderWalker;
+import org.apache.pig.impl.plan.VisitorException;
+import org.apache.pig.newplan.logical.expression.AddExpression;
+import org.apache.pig.newplan.logical.expression.AndExpression;
+import org.apache.pig.newplan.logical.expression.BinCondExpression;
+import org.apache.pig.newplan.logical.expression.CastExpression;
+import org.apache.pig.newplan.logical.expression.ConstantExpression;
+import org.apache.pig.newplan.logical.expression.DereferenceExpression;
+import org.apache.pig.newplan.logical.expression.DivideExpression;
+import org.apache.pig.newplan.logical.expression.EqualExpression;
+import org.apache.pig.newplan.logical.expression.GreaterThanEqualExpression;
+import org.apache.pig.newplan.logical.expression.GreaterThanExpression;
+import org.apache.pig.newplan.logical.expression.IsNullExpression;
+import org.apache.pig.newplan.logical.expression.LessThanEqualExpression;
+import org.apache.pig.newplan.logical.expression.LessThanExpression;
+import org.apache.pig.newplan.logical.expression.LogicalExpression;
+import org.apache.pig.newplan.logical.expression.MapLookupExpression;
+import org.apache.pig.newplan.logical.expression.ModExpression;
+import org.apache.pig.newplan.logical.expression.MultiplyExpression;
+import org.apache.pig.newplan.logical.expression.NegativeExpression;
+import org.apache.pig.newplan.logical.expression.NotEqualExpression;
+import org.apache.pig.newplan.logical.expression.NotExpression;
+import org.apache.pig.newplan.logical.expression.OrExpression;
+import org.apache.pig.newplan.logical.expression.ProjectExpression;
+import org.apache.pig.newplan.logical.expression.RegexExpression;
+import org.apache.pig.newplan.logical.expression.SubtractExpression;
+import org.apache.pig.newplan.logical.expression.UserFuncExpression;
+import org.apache.pig.newplan.logical.relational.LogicalRelationalOperator;
+import org.apache.pig.newplan.logical.relational.LogicalSchema;
+
+//visitor to translate expressions
+public class LogicalExpPlanMigrationVistor extends LOVisitor { 
+    
+    protected org.apache.pig.newplan.logical.expression.LogicalExpressionPlan exprPlan;
+    protected HashMap<LogicalOperator, LogicalExpression> exprOpsMap;
+    protected LogicalRelationalOperator attachedRelationalOp;
+    protected LogicalPlan outerPlan;
+    
+    public LogicalExpPlanMigrationVistor(LogicalPlan expressionPlan, LogicalRelationalOperator attachedOperator, LogicalPlan outerPlan) {
+        super(expressionPlan, new DependencyOrderWalker<LogicalOperator, LogicalPlan>(expressionPlan));
+        exprPlan = new org.apache.pig.newplan.logical.expression.LogicalExpressionPlan();
+        exprOpsMap = new HashMap<LogicalOperator, LogicalExpression>();
+        attachedRelationalOp = attachedOperator;
+        this.outerPlan = outerPlan;
+    }    
+
+    private void translateConnection(LogicalOperator oldOp, org.apache.pig.newplan.Operator newOp) {       
+       List<LogicalOperator> preds = mPlan.getPredecessors(oldOp); 
+       
+       // the dependency relationship of new expression plan is opposite to the old logical plan
+       // for example, a+b, in old plan, "add" is a leave, and "a" and "b" are roots
+       // in new plan, "add" is root, and "a" and "b" are leaves.
+       if(preds != null) {            
+           for(LogicalOperator pred: preds) {
+               org.apache.pig.newplan.Operator newPred = exprOpsMap.get(pred);
+               newOp.getPlan().connect(newOp, newPred);                 
+           }
+       }        
+   }
+    
+    public void visit(LOProject project) throws VisitorException {
+        int col = project.getCol();
+        
+        LogicalExpression pe;
+        if (project.getPlan().getPredecessors(project)!=null && project.getPlan().getPredecessors(project).get(0)
+                instanceof LOProject) {
+            List<Integer> columnNums = new ArrayList<Integer>();
+            columnNums.add(col);
+            pe = new DereferenceExpression(exprPlan, columnNums);
+        }
+        else {
+            LogicalOperator lg = project.getExpression();
+            LogicalOperator succed = outerPlan.getSuccessors(lg).get(0);
+            int input = outerPlan.getPredecessors(succed).indexOf(lg);
+            pe = new ProjectExpression(exprPlan, input, project.isStar()?-1:col, attachedRelationalOp);
+        }
+        
+        exprPlan.add(pe);
+        exprOpsMap.put(project, pe);       
+        translateConnection(project, pe);                       
+    }
+    
+    public void visit(LOConst con) throws VisitorException{
+        ConstantExpression ce = null;
+        try {
+            ce = new ConstantExpression(exprPlan, con.getValue(), Util.translateFieldSchema(con.getFieldSchema()));
+        } catch (FrontendException e) {
+            throw new VisitorException(e);
+        }
+        
+        exprPlan.add(ce);
+        exprOpsMap.put(con, ce);       
+        translateConnection(con, ce);
+    }
+    
+    public void visit(LOGreaterThan op) throws VisitorException {
+        ExpressionOperator left = op.getLhsOperand();
+        ExpressionOperator right = op.getRhsOperand();
+                
+        GreaterThanExpression eq = new GreaterThanExpression
+        (exprPlan, exprOpsMap.get(left), exprOpsMap.get(right));
+        exprOpsMap.put(op, eq);
+    }
+
+    public void visit(LOLesserThan op) throws VisitorException {
+        ExpressionOperator left = op.getLhsOperand();
+        ExpressionOperator right = op.getRhsOperand();
+                
+        LessThanExpression eq = new LessThanExpression
+        (exprPlan, exprOpsMap.get(left), exprOpsMap.get(right));
+        exprOpsMap.put(op, eq);
+    }
+
+    public void visit(LOGreaterThanEqual op) throws VisitorException {
+        ExpressionOperator left = op.getLhsOperand();
+        ExpressionOperator right = op.getRhsOperand();
+                
+        GreaterThanEqualExpression eq = new GreaterThanEqualExpression
+        (exprPlan, exprOpsMap.get(left), exprOpsMap.get(right));
+        exprOpsMap.put(op, eq);
+    }
+
+    public void visit(LOLesserThanEqual op) throws VisitorException {
+        ExpressionOperator left = op.getLhsOperand();
+        ExpressionOperator right = op.getRhsOperand();
+                
+        LessThanEqualExpression eq = new LessThanEqualExpression
+        (exprPlan, exprOpsMap.get(left), exprOpsMap.get(right));
+        exprOpsMap.put(op, eq);
+    }
+
+    public void visit(LOEqual op) throws VisitorException {     
+        ExpressionOperator left = op.getLhsOperand();
+        ExpressionOperator right = op.getRhsOperand();
+                
+        EqualExpression eq = new EqualExpression(exprPlan, exprOpsMap.get(left), exprOpsMap.get(right));
+        exprOpsMap.put(op, eq);
+    }
+
+    public void visit(LOUserFunc op) throws VisitorException {
+        UserFuncExpression exp = new UserFuncExpression(exprPlan, op.getFuncSpec());
+        
+        List<ExpressionOperator> args = op.getArguments();
+        
+        for( ExpressionOperator arg : args ) {
+            LogicalExpression expArg = exprOpsMap.get(arg);
+            exprPlan.connect(exp, expArg);
+        }
+        
+        exprOpsMap.put(op, exp);
+    }
+
+    public void visit(LOBinCond op) throws VisitorException {
+        ExpressionOperator condition = op.getCond();
+        ExpressionOperator left = op.getLhsOp();
+        ExpressionOperator right = op.getRhsOp();
+        
+        BinCondExpression exp = new BinCondExpression(exprPlan, 
+                exprOpsMap.get(condition), exprOpsMap.get(left), exprOpsMap.get(right));
+        exprOpsMap.put(op, exp);
+    }
+
+    public void visit(LOCast cast) throws VisitorException {
+        ExpressionOperator exp = cast.getExpression();
+        
+        CastExpression c = null;
+        try {
+            c = new CastExpression(exprPlan, exprOpsMap.get(exp), Util.translateFieldSchema(cast.getFieldSchema()));
+        } catch (FrontendException e) {
+            throw new VisitorException(e);
+        }
+        c.setFuncSpec(cast.getLoadFuncSpec());
+        exprOpsMap.put(cast, c);
+    }
+    
+    public void visit(LORegexp binOp) throws VisitorException {
+        ExpressionOperator left = binOp.getLhsOperand();
+        ExpressionOperator right = binOp.getRhsOperand();
+        
+        RegexExpression ae = new RegexExpression(exprPlan
+                , exprOpsMap.get(left), exprOpsMap.get(right));
+        exprOpsMap.put(binOp, ae);
+    }
+
+    public void visit(LONotEqual op) throws VisitorException {
+        ExpressionOperator left = op.getLhsOperand();
+        ExpressionOperator right = op.getRhsOperand();
+                
+        NotEqualExpression eq = new NotEqualExpression(exprPlan, 
+                exprOpsMap.get(left), exprOpsMap.get(right));
+        exprOpsMap.put(op, eq);
+    }
+
+    public void visit(LOAdd binOp) throws VisitorException {        
+        ExpressionOperator left = binOp.getLhsOperand();
+        ExpressionOperator right = binOp.getRhsOperand();
+        
+        AddExpression ae = new AddExpression(exprPlan,
+                exprOpsMap.get(left), exprOpsMap.get(right));
+        exprOpsMap.put(binOp, ae);
+    }
+
+    public void visit(LOSubtract binOp) throws VisitorException {
+        ExpressionOperator left = binOp.getLhsOperand();
+        ExpressionOperator right = binOp.getRhsOperand();
+        
+        SubtractExpression ae = new SubtractExpression(exprPlan, 
+                exprOpsMap.get(left), exprOpsMap.get(right));
+        exprOpsMap.put(binOp, ae);
+    }
+
+    public void visit(LOMultiply binOp) throws VisitorException {
+        ExpressionOperator left = binOp.getLhsOperand();
+        ExpressionOperator right = binOp.getRhsOperand();
+        
+        MultiplyExpression ae = new MultiplyExpression(exprPlan,
+                exprOpsMap.get(left), exprOpsMap.get(right));
+        exprOpsMap.put(binOp, ae);
+    }
+
+    public void visit(LODivide binOp) throws VisitorException {
+        ExpressionOperator left = binOp.getLhsOperand();
+        ExpressionOperator right = binOp.getRhsOperand();
+        
+        DivideExpression ae = new DivideExpression(exprPlan,
+                exprOpsMap.get(left), exprOpsMap.get(right));
+        exprOpsMap.put(binOp, ae);
+    }
+
+    public void visit(LOMod binOp) throws VisitorException {
+        ExpressionOperator left = binOp.getLhsOperand();
+        ExpressionOperator right = binOp.getRhsOperand();
+        
+        ModExpression ae = new ModExpression(exprPlan, 
+                exprOpsMap.get(left), exprOpsMap.get(right));
+        exprOpsMap.put(binOp, ae);
+    }
+
+    
+    public void visit(LONegative uniOp) throws VisitorException {
+        ExpressionOperator exp = uniOp.getOperand();
+        NegativeExpression op = new NegativeExpression(exprPlan, exprOpsMap.get(exp));
+        exprOpsMap.put(uniOp, op);
+    }
+
+    public void visit(LOMapLookup colOp) throws VisitorException {
+        FieldSchema fieldSchema;
+        try {
+            fieldSchema = colOp.getFieldSchema();
+        } catch (FrontendException e) {
+            throw new VisitorException( e.getMessage() );
+        }
+        
+        LogicalSchema.LogicalFieldSchema logfieldSchema = 
+            new LogicalSchema.LogicalFieldSchema( fieldSchema.alias, 
+                    Util.translateSchema(fieldSchema.schema), fieldSchema.type);
+        
+        LogicalExpression map = exprOpsMap.get( colOp.getMap() );
+        
+        MapLookupExpression op = new MapLookupExpression(exprPlan, 
+                colOp.getLookUpKey(),  logfieldSchema);
+        
+        exprPlan.connect(op, map);
+        
+        exprOpsMap.put(colOp, op);
+    }
+
+    public void visit(LOAnd binOp) throws VisitorException {
+        ExpressionOperator left = binOp.getLhsOperand();
+        ExpressionOperator right = binOp.getRhsOperand();
+                
+        AndExpression ae = new AndExpression(exprPlan, exprOpsMap.get(left), exprOpsMap.get(right));
+        exprOpsMap.put(binOp, ae);            
+    }
+
+    public void visit(LOOr binOp) throws VisitorException {
+        ExpressionOperator left = binOp.getLhsOperand();
+        ExpressionOperator right = binOp.getRhsOperand();
+                
+        OrExpression ae = new OrExpression(exprPlan, exprOpsMap.get(left), exprOpsMap.get(right));
+        exprOpsMap.put(binOp, ae);
+    }
+
+    public void visit(LONot uniOp) throws VisitorException {
+        ExpressionOperator exp = uniOp.getOperand();
+        NotExpression not = new NotExpression(exprPlan, exprOpsMap.get(exp));
+        exprOpsMap.put(uniOp, not);
+    }
+
+    public void visit(LOIsNull uniOp) throws VisitorException {
+        ExpressionOperator exp = uniOp.getOperand();
+        IsNullExpression isNull = new IsNullExpression(exprPlan, exprOpsMap.get(exp));
+        exprOpsMap.put(uniOp, isNull);
+    }
+}
\ No newline at end of file

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/LogicalPlanMigrationVistor.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/LogicalPlanMigrationVistor.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/LogicalPlanMigrationVistor.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/LogicalPlanMigrationVistor.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,371 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.pig.impl.io.FileSpec;
+import org.apache.pig.impl.logicalLayer.LOCogroup;
+import org.apache.pig.impl.logicalLayer.LOCross;
+import org.apache.pig.impl.logicalLayer.LODistinct;
+import org.apache.pig.impl.logicalLayer.LOFilter;
+import org.apache.pig.impl.logicalLayer.LOForEach;
+import org.apache.pig.impl.logicalLayer.LOGenerate;
+import org.apache.pig.impl.logicalLayer.LOJoin;
+import org.apache.pig.impl.logicalLayer.LOLimit;
+import org.apache.pig.impl.logicalLayer.LOLoad;
+import org.apache.pig.impl.logicalLayer.LOSort;
+import org.apache.pig.impl.logicalLayer.LOSplit;
+import org.apache.pig.impl.logicalLayer.LOSplitOutput;
+import org.apache.pig.impl.logicalLayer.LOStore;
+import org.apache.pig.impl.logicalLayer.LOStream;
+import org.apache.pig.impl.logicalLayer.LOUnion;
+import org.apache.pig.impl.logicalLayer.LOVisitor;
+import org.apache.pig.impl.logicalLayer.LogicalOperator;
+import org.apache.pig.impl.logicalLayer.LogicalPlan;
+import org.apache.pig.impl.logicalLayer.LOCogroup.GROUPTYPE;
+import org.apache.pig.impl.logicalLayer.LOJoin.JOINTYPE;
+import org.apache.pig.impl.plan.DependencyOrderWalker;
+import org.apache.pig.impl.plan.PlanWalker;
+import org.apache.pig.impl.plan.VisitorException;
+import org.apache.pig.impl.util.MultiMap;
+import org.apache.pig.newplan.logical.expression.LogicalExpressionPlan;
+import org.apache.pig.newplan.logical.relational.LogicalRelationalOperator;
+import org.apache.pig.newplan.logical.relational.LogicalSchema;
+
+/**
+ * Translate old logical plan into new logical plan
+ */
+public class LogicalPlanMigrationVistor extends LOVisitor { 
+    private org.apache.pig.newplan.logical.relational.LogicalPlan logicalPlan;
+    private HashMap<LogicalOperator, LogicalRelationalOperator> opsMap;
+   
+    public LogicalPlanMigrationVistor(LogicalPlan plan) {
+        super(plan, new DependencyOrderWalker<LogicalOperator, LogicalPlan>(plan));
+        logicalPlan = new org.apache.pig.newplan.logical.relational.LogicalPlan();
+        opsMap = new HashMap<LogicalOperator, LogicalRelationalOperator>();
+    }    
+    
+    private void translateConnection(LogicalOperator oldOp, org.apache.pig.newplan.Operator newOp) {       
+        List<LogicalOperator> preds = mPlan.getPredecessors(oldOp); 
+        
+        if(preds != null) {            
+            for(LogicalOperator pred: preds) {
+                org.apache.pig.newplan.Operator newPred = opsMap.get(pred);
+                newOp.getPlan().connect(newPred, newOp);                 
+            }
+        }        
+    }      
+    
+    private LogicalExpressionPlan translateExpressionPlan(LogicalPlan lp, LogicalRelationalOperator op) throws VisitorException {
+        PlanWalker<LogicalOperator, LogicalPlan> childWalker = 
+            new DependencyOrderWalker<LogicalOperator, LogicalPlan>(lp);
+        
+        LogicalExpPlanMigrationVistor childPlanVisitor = new LogicalExpPlanMigrationVistor(lp, op, mPlan);
+        
+        childWalker.walk(childPlanVisitor);
+        return childPlanVisitor.exprPlan;
+    }
+      
+    public org.apache.pig.newplan.logical.relational.LogicalPlan getNewLogicalPlan() {
+        return logicalPlan;
+    }
+    
+    public void visit(LOCogroup cg) throws VisitorException {
+        
+        // Get the GroupType information
+        org.apache.pig.newplan.logical.relational.LOCogroup.GROUPTYPE grouptype;
+        if( cg.getGroupType() == GROUPTYPE.COLLECTED ) {
+            grouptype = org.apache.pig.newplan.logical.relational.LOCogroup.GROUPTYPE.COLLECTED;
+        } else {
+            grouptype = org.apache.pig.newplan.logical.relational.LOCogroup.GROUPTYPE.REGULAR;
+        }
+        
+        // Convert the multimap of expressionplans to a new way
+        ArrayList<LogicalOperator> inputs = (ArrayList<LogicalOperator>) cg.getInputs();
+        MultiMap<Integer, LogicalExpressionPlan> newExpressionPlans = 
+            new MultiMap<Integer, LogicalExpressionPlan>();
+        
+        org.apache.pig.newplan.logical.relational.LOCogroup newCogroup =
+            new org.apache.pig.newplan.logical.relational.LOCogroup
+            (logicalPlan, newExpressionPlans, grouptype, cg.getInner(), 
+                    cg.getRequestedParallelism() );
+        
+        for( int i = 0; i < inputs.size(); i++ ) {
+            ArrayList<LogicalPlan> plans = 
+                (ArrayList<LogicalPlan>) cg.getGroupByPlans().get(inputs.get(i));
+            for( LogicalPlan plan : plans ) {
+                LogicalExpressionPlan expPlan = translateExpressionPlan(plan, newCogroup);
+                newExpressionPlans.put(Integer.valueOf(i), expPlan);
+            }
+        }
+        
+        newCogroup.setAlias(cg.getAlias());
+        
+        logicalPlan.add(newCogroup);
+        opsMap.put(cg, newCogroup);
+        translateConnection(cg, newCogroup);
+    }
+
+    public void visit(LOJoin loj) throws VisitorException {
+        // List of join predicates 
+        List<LogicalOperator> inputs = loj.getInputs();
+        
+        // mapping of inner plans for each input
+        MultiMap<Integer, LogicalExpressionPlan> joinPlans = 
+                        new MultiMap<Integer, LogicalExpressionPlan>();
+        
+        JOINTYPE type = loj.getJoinType();
+        org.apache.pig.newplan.logical.relational.LOJoin.JOINTYPE newType = org.apache.pig.newplan.logical.relational.LOJoin.JOINTYPE.HASH;;
+        switch(type) {        
+        case REPLICATED:
+            newType = org.apache.pig.newplan.logical.relational.LOJoin.JOINTYPE.REPLICATED;
+            break;        	
+        case SKEWED:
+            newType = org.apache.pig.newplan.logical.relational.LOJoin.JOINTYPE.SKEWED;
+            break;
+        case MERGE:
+            newType = org.apache.pig.newplan.logical.relational.LOJoin.JOINTYPE.MERGE;
+            break;        
+        }
+        
+        boolean[] isInner = loj.getInnerFlags();
+        org.apache.pig.newplan.logical.relational.LOJoin join = 
+            new org.apache.pig.newplan.logical.relational.LOJoin(logicalPlan, joinPlans, newType, isInner);
+        
+        for (int i=0; i<inputs.size(); i++) {
+            List<LogicalPlan> plans = (List<LogicalPlan>) loj.getJoinPlans().get(inputs.get(i));
+            for (LogicalPlan lp : plans) {                               
+                joinPlans.put(i, translateExpressionPlan(lp, join));
+            }        
+        }
+        
+        join.setAlias(loj.getAlias());
+        join.setRequestedParallelism(loj.getRequestedParallelism());
+        
+        logicalPlan.add(join);
+        opsMap.put(loj, join);       
+        translateConnection(loj, join);           
+    }
+
+    public void visit(LOCross cross) throws VisitorException {
+        // List of join predicates 
+        org.apache.pig.newplan.logical.relational.LOCross newCross = 
+            new org.apache.pig.newplan.logical.relational.LOCross(logicalPlan);
+     
+        newCross.setAlias(cross.getAlias());
+        newCross.setRequestedParallelism(cross.getRequestedParallelism());
+        
+        logicalPlan.add(newCross);
+        opsMap.put(cross, newCross);       
+        translateConnection(cross, newCross);           
+    }
+    
+    public void visit(LOForEach forEach) throws VisitorException {
+        
+        org.apache.pig.newplan.logical.relational.LOForEach newForeach = 
+                new org.apache.pig.newplan.logical.relational.LOForEach(logicalPlan);
+        
+        org.apache.pig.newplan.logical.relational.LogicalPlan innerPlan = 
+            new org.apache.pig.newplan.logical.relational.LogicalPlan();
+        
+        newForeach.setInnerPlan(innerPlan);
+        
+        List<LogicalExpressionPlan> expPlans = new ArrayList<LogicalExpressionPlan>();
+        
+        List<Boolean> fl = forEach.getFlatten();
+        boolean[] flat = new boolean[fl.size()];
+        for(int i=0; i<fl.size(); i++) {
+            flat[i] = fl.get(i);
+        }
+        org.apache.pig.newplan.logical.relational.LOGenerate gen = 
+            new org.apache.pig.newplan.logical.relational.LOGenerate(innerPlan, expPlans, flat);
+        
+        innerPlan.add(gen);                
+        
+        List<LogicalPlan> ll = forEach.getForEachPlans();
+        for(int i=0; i<ll.size(); i++) {
+            LogicalPlan lp = ll.get(i);
+            ForeachInnerPlanVisitor v = new ForeachInnerPlanVisitor(newForeach, forEach, lp, mPlan);
+            v.visit();
+            
+            expPlans.add(v.exprPlan);
+        }
+        
+        newForeach.setAlias(forEach.getAlias());
+        newForeach.setRequestedParallelism(forEach.getRequestedParallelism());
+        
+        logicalPlan.add(newForeach);
+        opsMap.put(forEach, newForeach);       
+        translateConnection(forEach, newForeach);
+    }
+
+    public void visit(LOSort sort) throws VisitorException {
+        List<LogicalPlan> sortPlans = sort.getSortColPlans();
+        List<LogicalExpressionPlan> newSortPlans = new ArrayList<LogicalExpressionPlan>();
+        
+        org.apache.pig.newplan.logical.relational.LOSort newSort = 
+            new org.apache.pig.newplan.logical.relational.LOSort(logicalPlan, 
+                    newSortPlans, sort.getAscendingCols(), sort.getUserFunc());
+        
+        for (LogicalPlan sortPlan : sortPlans) {
+            LogicalExpressionPlan newSortPlan = translateExpressionPlan(sortPlan, newSort);
+            newSortPlans.add(newSortPlan);
+        }
+        
+        newSort.setAlias(sort.getAlias());
+        newSort.setRequestedParallelism(sort.getRequestedParallelism());
+        newSort.setLimit(sort.getLimit());
+        logicalPlan.add(newSort);
+        opsMap.put(sort, newSort);
+        translateConnection(sort, newSort);
+    }
+
+    public void visit(LOLimit limit) throws VisitorException {
+        org.apache.pig.newplan.logical.relational.LOLimit newLimit = 
+            new org.apache.pig.newplan.logical.relational.LOLimit(logicalPlan, limit.getLimit());
+        
+        newLimit.setAlias(limit.getAlias());
+        newLimit.setRequestedParallelism(limit.getRequestedParallelism());
+        
+        logicalPlan.add(newLimit);
+        opsMap.put(limit, newLimit);
+        translateConnection(limit, newLimit);
+    }
+    
+    public void visit(LOStream stream) throws VisitorException {
+        org.apache.pig.newplan.logical.relational.LOStream newStream = 
+            new org.apache.pig.newplan.logical.relational.LOStream(logicalPlan,
+                    stream.getExecutableManager(), stream.getStreamingCommand());
+        
+        newStream.setAlias(stream.getAlias());
+        newStream.setRequestedParallelism(stream.getRequestedParallelism());
+        
+        logicalPlan.add(newStream);
+        opsMap.put(stream, newStream);
+        translateConnection(stream, newStream);
+    }
+    
+    public void visit(LOFilter filter) throws VisitorException {
+        org.apache.pig.newplan.logical.relational.LOFilter newFilter = new org.apache.pig.newplan.logical.relational.LOFilter(logicalPlan);
+        
+        LogicalPlan filterPlan = filter.getComparisonPlan();
+        LogicalExpressionPlan newFilterPlan = translateExpressionPlan(filterPlan, newFilter);
+      
+        newFilter.setFilterPlan(newFilterPlan);
+        newFilter.setAlias(filter.getAlias());
+        newFilter.setRequestedParallelism(filter.getRequestedParallelism());
+        
+        logicalPlan.add(newFilter);
+        opsMap.put(filter, newFilter);       
+        translateConnection(filter, newFilter);
+    }
+
+    public void visit(LOSplit split) throws VisitorException {
+        org.apache.pig.newplan.logical.relational.LOSplit newSplit = 
+            new org.apache.pig.newplan.logical.relational.LOSplit(logicalPlan);
+     
+        newSplit.setAlias(split.getAlias());
+        newSplit.setRequestedParallelism(split.getRequestedParallelism());
+        
+        logicalPlan.add(newSplit);
+        opsMap.put(split, newSplit);
+        translateConnection(split, newSplit);
+    }
+
+    public void visit(LOGenerate g) throws VisitorException {
+        throw new VisitorException("LOGenerate is not supported.");
+    }
+    
+    public void visit(LOLoad load) throws VisitorException{      
+        FileSpec fs = load.getInputFile();
+        
+        LogicalSchema s = null;
+        try {
+            s = Util.translateSchema(load.getSchema());
+        }catch(Exception e) {
+            throw new VisitorException("Failed to translate schema.", e);
+        }
+        
+        org.apache.pig.newplan.logical.relational.LOLoad ld = 
+            new org.apache.pig.newplan.logical.relational.LOLoad(fs, s, logicalPlan, load.getConfiguration());
+        
+        ld.setAlias(load.getAlias());
+        ld.setRequestedParallelism(load.getRequestedParallelism());
+        
+        logicalPlan.add(ld);        
+        opsMap.put(load, ld);
+        translateConnection(load, ld);
+    }
+    
+
+    public void visit(LOStore store) throws VisitorException{
+        org.apache.pig.newplan.logical.relational.LOStore newStore = 
+                new org.apache.pig.newplan.logical.relational.LOStore(logicalPlan, store.getOutputFile());    	
+       
+        newStore.setAlias(store.getAlias());
+        newStore.setRequestedParallelism(store.getRequestedParallelism());
+        
+        logicalPlan.add(newStore);
+        opsMap.put(store, newStore);       
+        translateConnection(store, newStore);
+    }    
+
+    public void visit(LOUnion union) throws VisitorException {
+        org.apache.pig.newplan.logical.relational.LOUnion newUnion = 
+            new org.apache.pig.newplan.logical.relational.LOUnion(logicalPlan);
+        
+        newUnion.setAlias(union.getAlias());
+        newUnion.setRequestedParallelism(union.getRequestedParallelism());
+        logicalPlan.add(newUnion);
+        opsMap.put(union, newUnion);
+        translateConnection(union, newUnion);
+    }
+    
+    public void visit(LOSplitOutput splitOutput) throws VisitorException {
+        org.apache.pig.newplan.logical.relational.LOSplitOutput newSplitOutput = 
+            new org.apache.pig.newplan.logical.relational.LOSplitOutput(logicalPlan);
+        
+        LogicalPlan filterPlan = splitOutput.getConditionPlan();
+        LogicalExpressionPlan newFilterPlan = translateExpressionPlan(filterPlan, newSplitOutput);
+      
+        newSplitOutput.setFilterPlan(newFilterPlan);
+        newSplitOutput.setAlias(splitOutput.getAlias());
+        newSplitOutput.setRequestedParallelism(splitOutput.getRequestedParallelism());
+        
+        logicalPlan.add(newSplitOutput);
+        opsMap.put(splitOutput, newSplitOutput);
+        translateConnection(splitOutput, newSplitOutput);
+    }
+
+    public void visit(LODistinct distinct) throws VisitorException {
+        org.apache.pig.newplan.logical.relational.LODistinct newDistinct = 
+            new org.apache.pig.newplan.logical.relational.LODistinct(logicalPlan);
+        
+        newDistinct.setAlias(distinct.getAlias());
+        newDistinct.setRequestedParallelism(distinct.getRequestedParallelism());
+        
+        logicalPlan.add(newDistinct);
+        opsMap.put(distinct, newDistinct);
+        translateConnection(distinct, newDistinct);
+    }
+    
+    
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/Util.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/Util.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/Util.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/Util.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,143 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.pig.impl.logicalLayer.FrontendException;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+import org.apache.pig.impl.util.Pair;
+import org.apache.pig.newplan.Operator;
+import org.apache.pig.newplan.logical.expression.LogicalExpressionPlan;
+import org.apache.pig.newplan.logical.expression.ProjectExpression;
+import org.apache.pig.newplan.logical.relational.LOForEach;
+import org.apache.pig.newplan.logical.relational.LOGenerate;
+import org.apache.pig.newplan.logical.relational.LOInnerLoad;
+import org.apache.pig.newplan.logical.relational.LogicalPlan;
+import org.apache.pig.newplan.logical.relational.LogicalRelationalOperator;
+import org.apache.pig.newplan.logical.relational.LogicalSchema;
+
+public class Util {
+    public static 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);
+        }
+        
+        s2.setTwoLevelAccessRequired(schema.isTwoLevelAccessRequired());
+        
+        return s2;
+    }
+    
+    public static LogicalSchema.LogicalFieldSchema translateFieldSchema(Schema.FieldSchema fs) {      
+        LogicalSchema newSchema = null;
+        if (fs.schema!=null) {
+            newSchema = translateSchema(fs.schema);
+        }
+        
+        LogicalSchema.LogicalFieldSchema newFs = new LogicalSchema.LogicalFieldSchema(null, newSchema, fs.type);
+        return newFs;
+    }
+    
+    public static Schema translateSchema(LogicalSchema schema) {       
+        if (schema == null) {
+            return null;
+        }
+        
+        Schema s2 = new Schema();
+        List<LogicalSchema.LogicalFieldSchema> ll = schema.getFields();
+        for (LogicalSchema.LogicalFieldSchema f: ll) {
+            Schema.FieldSchema f2 = null;
+            try {
+                f2 = new Schema.FieldSchema(f.alias, translateSchema(f.schema), f.type);
+                s2.add(f2);
+            } catch (FrontendException e) {
+            }
+        }
+        
+        s2.setTwoLevelAccessRequired(schema.isTwoLevelAccessRequired());
+        
+        return s2;
+    }
+    
+    public static Schema.FieldSchema translateFieldSchema(LogicalSchema.LogicalFieldSchema fs) {      
+        Schema newSchema = null;
+        if (fs.schema!=null) {
+            newSchema = translateSchema(fs.schema);
+        }
+        
+        Schema.FieldSchema newFs = null;
+        try {
+            newFs = new Schema.FieldSchema(null, newSchema, fs.type);
+        } catch (FrontendException e) {
+        }
+        return newFs;
+    }
+    
+    public static LOForEach addForEachAfter(LogicalPlan plan, LogicalRelationalOperator op,
+            Set<Integer> columnsToDrop) throws IOException {
+        LOForEach foreach = new LOForEach(plan);
+        
+        plan.add(foreach);
+        List<Operator> next = plan.getSuccessors(op);
+        if (next != null) {
+            LogicalRelationalOperator nextOp = (LogicalRelationalOperator)next.get(0);
+            Pair<Integer, Integer> pos = plan.disconnect(op, nextOp);
+            plan.connect(foreach, pos.first, nextOp, pos.second);
+        }
+        
+        plan.connect(op, foreach);
+        
+        LogicalPlan innerPlan = new LogicalPlan();
+        foreach.setInnerPlan(innerPlan);
+        
+        LogicalSchema schema = op.getSchema();
+        
+        // build foreach inner plan
+        List<LogicalExpressionPlan> exps = new ArrayList<LogicalExpressionPlan>();
+        LOGenerate gen = new LOGenerate(innerPlan, exps, new boolean[schema.size()-columnsToDrop.size()]);
+        innerPlan.add(gen);
+        
+        for (int i=0, j=0; i<schema.size(); i++) {
+            if (columnsToDrop.contains(i)) {
+                continue;
+            }
+            
+            LOInnerLoad innerLoad = new LOInnerLoad(innerPlan, foreach, i);
+            innerPlan.add(innerLoad);
+            innerPlan.connect(innerLoad, gen);
+            
+            LogicalExpressionPlan exp = new LogicalExpressionPlan();
+            ProjectExpression prj = new ProjectExpression(exp, j++, 0, gen);
+            exp.add(prj);
+            exps.add(exp);
+        }
+        return foreach;
+    }
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/AddExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/AddExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/AddExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/AddExpression.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,79 @@
+/*
+ * 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.expression;
+
+import java.io.IOException;
+
+import org.apache.pig.newplan.Operator;
+import org.apache.pig.newplan.OperatorPlan;
+import org.apache.pig.newplan.PlanVisitor;
+import org.apache.pig.newplan.logical.relational.LogicalSchema;
+
+/**
+ * Add Operator
+ */
+public class AddExpression extends BinaryExpression {
+
+    /**
+     * Will add this operator to the plan and connect it to the 
+     * left and right hand side operators.
+     * @param plan plan this operator is part of
+     * @param lhs expression on its left hand side
+     * @param rhs expression on its right hand side
+     */
+    public AddExpression(OperatorPlan plan,
+                         LogicalExpression lhs,
+                         LogicalExpression rhs) {
+        super("Add", plan, lhs, rhs);
+    }
+
+    /**
+     * @link org.apache.pig.experimental.plan.Operator#accept(org.apache.pig.experimental.plan.PlanVisitor)
+     */
+    @Override
+    public void accept(PlanVisitor v) throws IOException {
+        if (!(v instanceof LogicalExpressionVisitor)) {
+            throw new IOException("Expected LogicalExpressionVisitor");
+        }
+        ((LogicalExpressionVisitor)v).visit(this);
+    }
+    
+    @Override
+    public boolean isEqual(Operator other) {
+        if (other != null && other instanceof AddExpression) {
+            AddExpression ao = (AddExpression)other;
+            try {
+                return ao.getLhs().isEqual(getLhs()) && ao.getRhs().isEqual(getRhs());
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        } else {
+            return false;
+        }
+    }
+    
+    @Override
+    public LogicalSchema.LogicalFieldSchema getFieldSchema() throws IOException {
+        if (fieldSchema!=null)
+            return fieldSchema;
+        fieldSchema = new LogicalSchema.LogicalFieldSchema(null, null, getLhs().getType());
+        uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
+        return fieldSchema;
+    }
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/AllSameExpressionVisitor.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/AllSameExpressionVisitor.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/AllSameExpressionVisitor.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/AllSameExpressionVisitor.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,157 @@
+/*
+ * 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.expression;
+
+import java.io.IOException;
+
+import org.apache.pig.newplan.OperatorPlan;
+import org.apache.pig.newplan.PlanWalker;
+
+public abstract class AllSameExpressionVisitor extends LogicalExpressionVisitor {
+
+    public AllSameExpressionVisitor(OperatorPlan plan, PlanWalker walker) {
+        super(plan, walker);
+    }
+    
+    /**
+     * Method to call on every node in the logical expression plan.
+     * @param op Node that is currently being visited.
+     */
+    abstract protected void execute(LogicalExpression op) throws IOException;
+    
+    @Override
+    public void visit(AndExpression andExpr) throws IOException {
+        execute(andExpr);
+    }
+    
+    @Override
+    public void visit(OrExpression exp) throws IOException {
+        execute(exp);
+    }
+
+    @Override
+    public void visit(EqualExpression equal) throws IOException {
+        execute(equal);
+    }
+    
+    @Override
+    public void visit(ProjectExpression project) throws IOException {
+        execute(project);
+    }
+    
+    @Override
+    public void visit(ConstantExpression constant) throws IOException {
+        execute(constant);
+    }
+    
+    @Override
+    public void visit(CastExpression cast) throws IOException {
+        execute(cast);
+    }
+
+    @Override
+    public void visit(GreaterThanExpression greaterThanExpression) throws IOException {
+        execute(greaterThanExpression);
+    }
+    
+    @Override
+    public void visit(GreaterThanEqualExpression op) throws IOException {
+        execute(op);
+    }
+
+    @Override
+    public void visit(LessThanExpression lessThanExpression) throws IOException {
+        execute(lessThanExpression);
+    }
+    
+    @Override
+    public void visit(LessThanEqualExpression op) throws IOException {
+        execute(op);
+    }
+
+    @Override
+    public void visit(NotEqualExpression op) throws IOException {
+        execute(op);
+    }
+
+    @Override
+    public void visit(NotExpression op) throws IOException {
+        execute(op);
+    }
+
+    @Override
+    public void visit(IsNullExpression op) throws IOException {
+        execute(op);
+    }
+    
+    @Override
+    public void visit(NegativeExpression op) throws IOException {
+        execute(op);
+    }
+    
+    @Override
+    public void visit(AddExpression op) throws IOException {
+        execute(op);
+    }
+    
+    @Override
+    public void visit(SubtractExpression op) throws IOException {
+        execute(op);
+    }
+    
+    @Override
+    public void visit(MultiplyExpression op) throws IOException {
+        execute(op);
+    }
+    
+    @Override
+    public void visit(ModExpression op) throws IOException {
+        execute(op);
+    }
+    
+    @Override
+    public void visit(DivideExpression op) throws IOException {
+        execute(op);
+    }
+
+    @Override
+    public void visit(MapLookupExpression op) throws IOException {
+        execute(op);
+    }
+
+    @Override
+    public void visit(BinCondExpression op) throws IOException {
+        execute(op);
+    }
+
+    @Override
+    public void visit(UserFuncExpression op) throws IOException {
+        execute(op);
+    }
+
+    @Override
+    public void visit(DereferenceExpression derefenceExpression) throws IOException {
+        execute(derefenceExpression);
+    }
+
+    @Override
+    public void visit(RegexExpression op) throws IOException {
+        execute(op);
+    }
+
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/AndExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/AndExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/AndExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/AndExpression.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,80 @@
+/*
+ * 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.expression;
+
+import java.io.IOException;
+
+import org.apache.pig.data.DataType;
+import org.apache.pig.newplan.Operator;
+import org.apache.pig.newplan.OperatorPlan;
+import org.apache.pig.newplan.PlanVisitor;
+import org.apache.pig.newplan.logical.relational.LogicalSchema;
+
+/**
+ * Boolean and expression.
+ */
+public class AndExpression extends BinaryExpression {
+
+    /**
+     * Will add this operator to the plan and connect it to the 
+     * left and right hand side operators.
+     * @param plan plan this operator is part of
+     * @param lhs expression on its left hand side
+     * @param rhs expression on its right hand side
+     */
+    public AndExpression(OperatorPlan plan,
+                         LogicalExpression lhs,
+                         LogicalExpression rhs) {
+        super("And", plan, lhs, rhs);
+    }
+
+    /**
+     * @link org.apache.pig.experimental.plan.Operator#accept(org.apache.pig.experimental.plan.PlanVisitor)
+     */
+    @Override
+    public void accept(PlanVisitor v) throws IOException {
+        if (!(v instanceof LogicalExpressionVisitor)) {
+            throw new IOException("Expected LogicalExpressionVisitor");
+        }
+        ((LogicalExpressionVisitor)v).visit(this);
+    }
+    
+    @Override
+    public boolean isEqual(Operator other) {
+        if (other != null && other instanceof AndExpression) {
+            AndExpression ao = (AndExpression)other;
+            try {
+                return ao.getLhs().isEqual(getLhs()) && ao.getRhs().isEqual(getRhs());
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        } else {
+            return false;
+        }
+    }
+    
+    @Override
+    public LogicalSchema.LogicalFieldSchema getFieldSchema() throws IOException {
+        if (fieldSchema!=null)
+            return fieldSchema;
+        fieldSchema = new LogicalSchema.LogicalFieldSchema(null, null, DataType.BOOLEAN);
+        uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
+        return fieldSchema;
+    }
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/BagDereferenceExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/BagDereferenceExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/BagDereferenceExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/BagDereferenceExpression.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1 @@
+package org.apache.pig.newplan.logical.expression;

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/BinCondExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/BinCondExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/BinCondExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/BinCondExpression.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,109 @@
+/*
+ * 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.expression;
+
+import java.io.IOException;
+
+import org.apache.pig.newplan.Operator;
+import org.apache.pig.newplan.OperatorPlan;
+import org.apache.pig.newplan.PlanVisitor;
+import org.apache.pig.newplan.logical.relational.LogicalSchema;
+
+public class BinCondExpression extends LogicalExpression {
+
+    /**
+     * Will add this operator to the plan and connect it to the 
+     * left and right hand side operators and the condition operator
+     * @param plan plan this operator is part of
+     * @param lhs expression on its left hand side
+     * @param rhs expression on its right hand side
+     */
+    public BinCondExpression(OperatorPlan plan,
+                            LogicalExpression condition,
+                            LogicalExpression lhs,
+                            LogicalExpression rhs) {
+        super("BinCond", plan);
+        plan.add(this);
+        plan.connect(this, condition);
+        plan.connect(this, lhs);
+        plan.connect(this, rhs);
+    }
+    
+    /**
+     * Returns the operator which handles this condition
+     * @return expression which handles the condition
+     * @throws IOException
+     */
+    public LogicalExpression getCondition() throws IOException {
+        return (LogicalExpression)plan.getSuccessors(this).get(0);
+    }
+
+    /**
+     * Get the left hand side of this expression.
+     * @return expression on the left hand side
+     * @throws IOException 
+     */
+    public LogicalExpression getLhs() throws IOException {
+        return (LogicalExpression)plan.getSuccessors(this).get(1);        
+    }
+
+    /**
+     * Get the right hand side of this expression.
+     * @return expression on the right hand side
+     * @throws IOException 
+     */
+    public LogicalExpression getRhs() throws IOException {
+        return (LogicalExpression)plan.getSuccessors(this).get(2);
+    }
+
+    /**
+     * @link org.apache.pig.experimental.plan.Operator#accept(org.apache.pig.experimental.plan.PlanVisitor)
+     */
+    @Override
+    public void accept(PlanVisitor v) throws IOException {
+        if (!(v instanceof LogicalExpressionVisitor)) {
+            throw new IOException("Expected LogicalExpressionVisitor");
+        }
+        ((LogicalExpressionVisitor)v).visit(this);
+    }
+    
+    @Override
+    public boolean isEqual(Operator other) {
+        if (other != null && other instanceof BinCondExpression) {
+            BinCondExpression ao = (BinCondExpression)other;
+            try {
+                return ao.getCondition().isEqual(getCondition()) && 
+                ao.getLhs().isEqual(getLhs()) && ao.getRhs().isEqual(getRhs());
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        } else {
+            return false;
+        }
+    }
+    
+    @Override
+    public LogicalSchema.LogicalFieldSchema getFieldSchema() throws IOException {
+        if (fieldSchema!=null)
+            return fieldSchema;
+        fieldSchema = new LogicalSchema.LogicalFieldSchema(null, null, getLhs().getType());
+        uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
+        return fieldSchema;
+    }
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/BinaryExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/BinaryExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/BinaryExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/BinaryExpression.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,66 @@
+/*
+ * 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.expression;
+
+import java.io.IOException;
+
+import org.apache.pig.newplan.OperatorPlan;
+
+/**
+ * Superclass for all binary expressions
+ *
+ */
+public abstract class BinaryExpression extends LogicalExpression {
+    
+    /**
+     * Will add this operator to the plan and connect it to the 
+     * left and right hand side operators.
+     * @param name of the operator
+     * @param plan plan this operator is part of
+     * @param lhs expression on its left hand side
+     * @param rhs expression on its right hand side
+     */
+    public BinaryExpression(String name,
+                            OperatorPlan plan,
+                            LogicalExpression lhs,
+                            LogicalExpression rhs) {
+        super(name, plan);
+        plan.add(this);
+        plan.connect(this, lhs);
+        plan.connect(this, rhs);
+    }
+
+    /**
+     * Get the left hand side of this binary expression.
+     * @return expression on the left hand side
+     * @throws IOException 
+     */
+    public LogicalExpression getLhs() throws IOException {
+        return (LogicalExpression)plan.getSuccessors(this).get(0);        
+    }
+
+    /**
+     * Get the right hand side of this binary expression.
+     * @return expression on the right hand side
+     * @throws IOException 
+     */
+    public LogicalExpression getRhs() throws IOException {
+        return (LogicalExpression)plan.getSuccessors(this).get(1);
+    }    
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/CastExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/CastExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/CastExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/CastExpression.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,87 @@
+/*
+ * 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.expression;
+
+import java.io.IOException;
+
+import org.apache.pig.FuncSpec;
+import org.apache.pig.newplan.Operator;
+import org.apache.pig.newplan.OperatorPlan;
+import org.apache.pig.newplan.PlanVisitor;
+import org.apache.pig.newplan.logical.relational.LogicalSchema;
+
+public class CastExpression extends UnaryExpression {
+    private FuncSpec castFunc;
+    private LogicalSchema.LogicalFieldSchema castSchema;
+
+    public CastExpression(OperatorPlan plan, LogicalExpression exp, LogicalSchema.LogicalFieldSchema fs) {
+        super("Cast", plan, exp);
+        castSchema = fs;
+    }
+
+    @Override
+    public void accept(PlanVisitor v) throws IOException {
+        if (!(v instanceof LogicalExpressionVisitor)) {
+            throw new IOException("Expected LogicalExpressionVisitor");
+        }
+        ((LogicalExpressionVisitor)v).visit(this);
+    }
+
+    /**
+     * Set the <code>FuncSpec</code> that performs the casting functionality
+     * @param spec the <code>FuncSpec</code> that does the casting
+     */
+    public void setFuncSpec(FuncSpec spec) {
+        castFunc = spec;
+    }
+    
+    /**
+     * Get the <code>FuncSpec</code> that performs the casting functionality
+     * @return the <code>FuncSpec</code> that does the casting
+     */
+    public FuncSpec getFuncSpec() {
+        return castFunc;
+    }
+
+    @Override
+    public boolean isEqual(Operator other) {
+        if (other != null && other instanceof CastExpression) { 
+            CastExpression of = (CastExpression)other;
+            try {
+                return plan.isEqual(of.plan) && getExpression().isEqual( of.getExpression() );
+            } catch (IOException e) {
+                return false;
+            }
+        } else {
+            return false;
+        }
+    }
+    
+    @Override
+    public LogicalSchema.LogicalFieldSchema getFieldSchema() throws IOException {
+        if (fieldSchema!=null)
+            return fieldSchema;
+        fieldSchema = new LogicalSchema.LogicalFieldSchema(null, castSchema.schema, castSchema.type);
+        uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
+        // Bring back the top level uid, this is not changed
+        LogicalExpression exp = (LogicalExpression)plan.getSuccessors(this).get(0);
+        fieldSchema.uid = exp.getFieldSchema().uid;
+        return fieldSchema;
+    }
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ColumnExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ColumnExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ColumnExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ColumnExpression.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,38 @@
+/*
+ * 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.expression;
+
+import org.apache.pig.newplan.OperatorPlan;
+
+/**
+ * Super class for all column expressions, including projection, constants, and deferences.
+ *
+ */
+public abstract class ColumnExpression extends LogicalExpression {
+
+    /**
+     * 
+     * @param name of the operator
+     * @param plan LogicalExpressionPlan this column expression is part of
+     */
+    public ColumnExpression(String name, OperatorPlan plan) {
+        super(name, plan);
+    }
+
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ConstantExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ConstantExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ConstantExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ConstantExpression.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,96 @@
+/*
+ * 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.expression;
+
+import java.io.IOException;
+
+import org.apache.pig.newplan.Operator;
+import org.apache.pig.newplan.OperatorPlan;
+import org.apache.pig.newplan.PlanVisitor;
+import org.apache.pig.newplan.logical.relational.LogicalSchema.LogicalFieldSchema;
+
+/**
+ * A constant
+ *
+ */
+public class ConstantExpression extends ColumnExpression {
+    
+    // Stupid Java needs a union
+    Object val;
+    LogicalFieldSchema mValueSchema;
+    
+    /**
+     * Adds expression to the plan 
+     * @param plan LogicalExpressionPlan this constant is a part of.
+     * @param val Value of this constant.
+     * @param mValueSchema field schema of the constant. 
+     */
+    public ConstantExpression(OperatorPlan plan, Object val, LogicalFieldSchema mValueSchema) {
+        super("Constant", plan);
+        this.val = val;
+        this.mValueSchema = mValueSchema;
+        plan.add(this);
+    }
+
+    /**
+     * @link org.apache.pig.experimental.plan.Operator#accept(org.apache.pig.experimental.plan.PlanVisitor)
+     */
+    @Override
+    public void accept(PlanVisitor v) throws IOException {
+        if (!(v instanceof LogicalExpressionVisitor)) {
+            throw new IOException("Expected LogicalExpressionVisitor");
+        }
+        ((LogicalExpressionVisitor)v).visit(this);
+
+    }
+
+    /**
+     * Get the value of this constant.
+     * @return value of the constant
+     */
+    public Object getValue() {
+        return val;
+    }
+    
+    public LogicalFieldSchema getValueSchema() {
+        return mValueSchema;
+    }
+
+    
+    @Override
+    public boolean isEqual(Operator other) {
+        if (other != null && other instanceof ConstantExpression) {
+            ConstantExpression co = (ConstantExpression)other;
+            return co.getValueSchema().isEqual(mValueSchema) && ( ( co.val == null && val == null ) 
+                    || ( co != null && co.val.equals(val) ) );
+        } else {
+            return false;
+        }
+    }
+    
+    @Override
+    public LogicalFieldSchema getFieldSchema() throws IOException {
+        if (fieldSchema!=null)
+            return fieldSchema;
+        fieldSchema = mValueSchema;
+        uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
+        return fieldSchema;
+    }
+
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/DereferenceExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/DereferenceExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/DereferenceExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/DereferenceExpression.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,152 @@
+/*
+ * 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.expression;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.pig.data.DataType;
+import org.apache.pig.newplan.Operator;
+import org.apache.pig.newplan.OperatorPlan;
+import org.apache.pig.newplan.PlanVisitor;
+import org.apache.pig.newplan.logical.relational.LogicalSchema;
+import org.apache.pig.newplan.logical.relational.LogicalSchema.LogicalFieldSchema;
+
+/**
+ * 
+ * This is a special case Expression and violates some of the rules of an
+ * Expression.
+ * Violation:
+ *   It has multiple Uids ( though not tracked there can be multiple uids
+ *      for this expression )
+ * 
+ * This is a special operator which handles the case described below
+ * Tuple( a:int, b:bag{ b_a:int, b_b:float } ) --> 
+ * BagDereference ( 0 ) --> project( 0, 1 ) --> bag{ b_a:float }
+ * 
+ * 
+ * 
+ * i.e. First input ( 0 ), second column ( 1 ) and first column of the bag.
+ *
+ */
+public class DereferenceExpression extends ColumnExpression {
+    
+    private List<Integer> columns;// The column in the input bag which the project references.
+    // Count is zero based.
+    
+    public DereferenceExpression(OperatorPlan plan, int colNum) {
+        super( "Dereference", plan );
+        columns = new ArrayList<Integer>();
+        columns.add(colNum);
+    }
+
+    public DereferenceExpression(OperatorPlan plan, List<Integer> columnNums) {
+        super( "Dereference", plan );
+        columns = new ArrayList<Integer>();
+        columns.addAll(columnNums);
+    }
+
+    /**
+     * @link org.apache.pig.experimental.plan.Operator#accept(org.apache.pig.experimental.plan.PlanVisitor)
+     */
+    @Override
+    public void accept(PlanVisitor v) throws IOException {
+        if (!(v instanceof LogicalExpressionVisitor)) {
+            throw new IOException("Expected LogicalExpressionVisitor");
+        }
+        ((LogicalExpressionVisitor)v).visit(this);
+    }
+    
+    public List<Integer> getBagColumns() {
+        return columns;
+    }
+    
+    public void setBagColumns(List<Integer> columns) {
+        this.columns = columns;
+    }
+    
+    @Override
+    public boolean isEqual(Operator other) {
+        if (other != null && other instanceof DereferenceExpression) {
+            DereferenceExpression po = (DereferenceExpression)other;
+            try {
+                if( po.columns.size() != columns.size() ) {
+                    return false;
+                }
+                return po.columns.containsAll(columns) && getReferredExpression().isEqual(po.getReferredExpression());
+            } catch (IOException e) {
+                return false;
+            }
+        } else {
+            return false;
+        }
+    }
+    
+    public LogicalExpression getReferredExpression() throws IOException {
+        if( plan.getSuccessors(this).size() < 1 ) {
+            throw new IOException("Could not find a related project Expression for Dereference");
+        }
+        return (LogicalExpression) plan.getSuccessors(this).get(0);
+    }
+    
+    public String toString() {
+        StringBuilder msg = new StringBuilder();
+        try {
+            msg.append("(Name: " + name + " Type: ");
+            if (fieldSchema!=null)
+                msg.append(DataType.findTypeName(getFieldSchema().type));
+            else
+                msg.append("null");
+            msg.append(" Uid: ");
+            if (fieldSchema!=null)
+                msg.append(getFieldSchema().uid);
+            else
+                msg.append("null");
+            msg.append(" Column:" + columns);
+            msg.append(")");
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+        return msg.toString();
+    }
+    
+    @Override
+    public LogicalSchema.LogicalFieldSchema getFieldSchema() throws IOException {
+        if (fieldSchema!=null)
+            return fieldSchema;
+        LogicalExpression successor = (LogicalExpression)plan.getSuccessors(this).get(0);
+        LogicalFieldSchema predFS = successor.getFieldSchema();
+        if (predFS!=null) {
+            LogicalSchema innerSchema = new LogicalSchema();
+            if (columns.size()>1 || predFS.type==DataType.BAG) {
+                for (int column:columns) {
+                    innerSchema.addField(predFS.schema.getField(column));
+                }
+                fieldSchema = new LogicalSchema.LogicalFieldSchema(null, innerSchema, predFS.type, 
+                        LogicalExpression.getNextUid());
+            }
+            else { // Dereference a field out of a tuple
+                fieldSchema = predFS.schema.getField(columns.get(0));
+            }
+        }
+        return fieldSchema;
+    }
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/DivideExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/DivideExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/DivideExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/DivideExpression.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,79 @@
+/*
+ * 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.expression;
+
+import java.io.IOException;
+
+import org.apache.pig.newplan.Operator;
+import org.apache.pig.newplan.OperatorPlan;
+import org.apache.pig.newplan.PlanVisitor;
+import org.apache.pig.newplan.logical.relational.LogicalSchema;
+
+/**
+ * Divide Operator
+ */
+public class DivideExpression extends BinaryExpression {
+
+    /**
+     * Will add this operator to the plan and connect it to the 
+     * left and right hand side operators.
+     * @param plan plan this operator is part of
+     * @param lhs expression on its left hand side
+     * @param rhs expression on its right hand side
+     */
+    public DivideExpression(OperatorPlan plan,
+                         LogicalExpression lhs,
+                         LogicalExpression rhs) {
+        super("Divide", plan, lhs, rhs);
+    }
+
+    /**
+     * @link org.apache.pig.experimental.plan.Operator#accept(org.apache.pig.experimental.plan.PlanVisitor)
+     */
+    @Override
+    public void accept(PlanVisitor v) throws IOException {
+        if (!(v instanceof LogicalExpressionVisitor)) {
+            throw new IOException("Expected LogicalExpressionVisitor");
+        }
+        ((LogicalExpressionVisitor)v).visit(this);
+    }
+    
+    @Override
+    public boolean isEqual(Operator other) {
+        if (other != null && other instanceof DivideExpression) {
+            DivideExpression ao = (DivideExpression)other;
+            try {
+                return ao.getLhs().isEqual(getLhs()) && ao.getRhs().isEqual(getRhs());
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        } else {
+            return false;
+        }
+    }
+    
+    @Override
+    public LogicalSchema.LogicalFieldSchema getFieldSchema() throws IOException {
+        if (fieldSchema!=null)
+            return fieldSchema;
+        fieldSchema = new LogicalSchema.LogicalFieldSchema(null, null, getLhs().getType());
+        uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
+        return fieldSchema;
+    }
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/EqualExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/EqualExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/EqualExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/EqualExpression.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,82 @@
+/*
+ * 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.expression;
+
+import java.io.IOException;
+
+import org.apache.pig.data.DataType;
+import org.apache.pig.newplan.Operator;
+import org.apache.pig.newplan.OperatorPlan;
+import org.apache.pig.newplan.PlanVisitor;
+import org.apache.pig.newplan.logical.relational.LogicalSchema;
+
+/**
+ * Equality test expression.
+ */
+public class EqualExpression extends BinaryExpression {
+
+    /**
+     * Will add this operator to the plan and connect it to the 
+     * left and right hand side operators.
+     * @param plan plan this operator is part of
+     * @param lhs expression on its left hand side
+     * @param rhs expression on its right hand side
+     */
+    public EqualExpression(OperatorPlan plan,
+                           LogicalExpression lhs,
+                           LogicalExpression rhs) {
+        super("Equal", plan, lhs, rhs);
+    }
+
+    /**
+     * @link org.apache.pig.experimental.plan.Operator#accept(org.apache.pig.experimental.plan.PlanVisitor)
+     */
+    @Override
+    public void accept(PlanVisitor v) throws IOException {
+        if (!(v instanceof LogicalExpressionVisitor)) {
+            throw new IOException("Expected LogicalExpressionVisitor");
+        }
+        ((LogicalExpressionVisitor)v).visit(this);
+    }
+    
+    @Override
+    public boolean isEqual(Operator other) {
+        if (other != null && other instanceof EqualExpression) {
+            EqualExpression eo = (EqualExpression)other;
+            try {
+                return eo.getLhs().isEqual(
+                        getLhs()) && 
+                eo.getRhs().isEqual(getRhs());
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        } else {
+            return false;
+        }
+    }
+    
+    @Override
+    public LogicalSchema.LogicalFieldSchema getFieldSchema() throws IOException {
+        if (fieldSchema!=null)
+            return fieldSchema;
+        fieldSchema = new LogicalSchema.LogicalFieldSchema(null, null, DataType.BOOLEAN);
+        uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
+        return fieldSchema;
+    }
+}



Mime
View raw message