pig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject svn commit: r982345 [3/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/expression/ExpToPhyTranslationVisitor.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ExpToPhyTranslationVisitor.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ExpToPhyTranslationVisitor.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ExpToPhyTranslationVisitor.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,519 @@
+/*
+ * 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 java.util.Map;
+import java.util.Stack;
+
+import org.apache.pig.ComparisonFunc;
+import org.apache.pig.EvalFunc;
+import org.apache.pig.FuncSpec;
+import org.apache.pig.PigException;
+import org.apache.pig.ResourceSchema;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.LogicalToPhysicalTranslatorException;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.PhysicalOperator;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.Add;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.BinaryComparisonOperator;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.BinaryExpressionOperator;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.ConstantExpression;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.Divide;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.EqualToExpr;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.ExpressionOperator;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.GTOrEqualToExpr;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.GreaterThanExpr;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.LTOrEqualToExpr;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.LessThanExpr;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.Mod;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.Multiply;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.NotEqualToExpr;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POAnd;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POBinCond;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POCast;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POIsNull;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POMapLookUp;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.PONegative;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.PONot;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POOr;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POProject;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.PORegexp;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.PORelationToExprProject;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POUserComparisonFunc;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POUserFunc;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.Subtract;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhysicalPlan;
+import org.apache.pig.impl.PigContext;
+import org.apache.pig.impl.plan.NodeIdGenerator;
+import org.apache.pig.impl.plan.OperatorKey;
+import org.apache.pig.impl.plan.PlanException;
+import org.apache.pig.newplan.DependencyOrderWalker;
+import org.apache.pig.newplan.Operator;
+import org.apache.pig.newplan.OperatorPlan;
+import org.apache.pig.newplan.PlanWalker;
+import org.apache.pig.newplan.logical.Util;
+import org.apache.pig.newplan.logical.relational.LOGenerate;
+import org.apache.pig.newplan.logical.relational.LOInnerLoad;
+import org.apache.pig.newplan.logical.relational.LogicalRelationalOperator;
+
+public class ExpToPhyTranslationVisitor extends LogicalExpressionVisitor {
+
+    // This value points to the current LogicalRelationalOperator we are working on
+    protected LogicalRelationalOperator currentOp;
+    
+    public ExpToPhyTranslationVisitor(OperatorPlan plan, LogicalRelationalOperator op, PhysicalPlan phyPlan, Map<Operator, PhysicalOperator> map) {
+        super(plan, new DependencyOrderWalker(plan));
+        currentOp = op;
+        logToPhyMap = map;
+        currentPlan = phyPlan;
+        currentPlans = new Stack<PhysicalPlan>();
+    }
+    
+    public ExpToPhyTranslationVisitor(OperatorPlan plan, PlanWalker walker, LogicalRelationalOperator op, PhysicalPlan phyPlan, Map<Operator, PhysicalOperator> map) {
+        super(plan, walker);
+        currentOp = op;
+        logToPhyMap = map;
+        currentPlan = phyPlan;
+        currentPlans = new Stack<PhysicalPlan>();
+    }
+    
+    protected Map<Operator, PhysicalOperator> logToPhyMap;
+
+    protected Stack<PhysicalPlan> currentPlans;
+
+    protected PhysicalPlan currentPlan;
+
+    protected NodeIdGenerator nodeGen = NodeIdGenerator.getGenerator();
+
+    protected PigContext pc;
+    
+    public void setPigContext(PigContext pc) {
+        this.pc = pc;
+    }
+
+    public PhysicalPlan getPhysicalPlan() {
+        return currentPlan;
+    }
+    
+    private void attachBinaryComparisonOperator( BinaryExpression op, 
+            BinaryComparisonOperator exprOp ) throws IOException {
+        // We dont have aliases in ExpressionOperators
+        // exprOp.setAlias(op.getAlias());
+        
+        
+        exprOp.setOperandType(op.getLhs().getType());
+        exprOp.setLhs((ExpressionOperator) logToPhyMap.get(op.getLhs()));
+        exprOp.setRhs((ExpressionOperator) logToPhyMap.get(op.getRhs()));
+        OperatorPlan oPlan = op.getPlan();
+
+        currentPlan.add(exprOp);
+        logToPhyMap.put(op, exprOp);
+
+        List<Operator> successors = oPlan.getSuccessors(op);
+        if (successors == null) {
+            return;
+        }
+        for (Operator lo : successors) {
+            PhysicalOperator from = logToPhyMap.get(lo);
+            try {
+                currentPlan.connect(from, exprOp);
+            } catch (PlanException e) {
+                int errCode = 2015;
+                String msg = "Invalid physical operators in the physical plan" ;
+                throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, e);
+            }
+        }
+    }
+    
+    private void attachBinaryExpressionOperator( BinaryExpression op, 
+            BinaryExpressionOperator exprOp ) throws IOException {
+        // We dont have aliases in ExpressionOperators
+        // exprOp.setAlias(op.getAlias());
+        
+        
+        exprOp.setResultType(op.getLhs().getType());
+        exprOp.setLhs((ExpressionOperator) logToPhyMap.get(op.getLhs()));
+        exprOp.setRhs((ExpressionOperator) logToPhyMap.get(op.getRhs()));
+        OperatorPlan oPlan = op.getPlan();
+
+        currentPlan.add(exprOp);
+        logToPhyMap.put(op, exprOp);
+
+        List<Operator> successors = oPlan.getSuccessors(op);
+        if (successors == null) {
+            return;
+        }
+        for (Operator lo : successors) {
+            PhysicalOperator from = logToPhyMap.get(lo);
+            try {
+                currentPlan.connect(from, exprOp);
+            } catch (PlanException e) {
+                int errCode = 2015;
+                String msg = "Invalid physical operators in the physical plan" ;
+                throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, e);
+            }
+        }
+    }
+
+    @Override
+    public void visit( AndExpression op ) throws IOException {
+        
+//        System.err.println("Entering And");
+        BinaryComparisonOperator exprOp = new POAnd(new OperatorKey(DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));
+        
+        attachBinaryComparisonOperator(op, exprOp);
+    }
+    
+    @Override
+    public void visit( OrExpression op ) throws IOException {
+        
+//        System.err.println("Entering Or");
+        BinaryComparisonOperator exprOp = new POOr(new OperatorKey(DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));
+        
+        attachBinaryComparisonOperator(op, exprOp);
+    }
+    
+    @Override
+    public void visit( EqualExpression op ) throws IOException {
+        
+        BinaryComparisonOperator exprOp = new EqualToExpr(new OperatorKey(
+                DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));
+        
+        attachBinaryComparisonOperator(op, exprOp);
+    }
+    
+    @Override
+    public void visit( NotEqualExpression op ) throws IOException {
+        
+        BinaryComparisonOperator exprOp = new NotEqualToExpr(new OperatorKey(
+                DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));
+        
+        attachBinaryComparisonOperator(op, exprOp);
+    }
+    
+    @Override
+    public void visit( GreaterThanExpression op ) throws IOException {
+        
+        BinaryComparisonOperator exprOp = new GreaterThanExpr(new OperatorKey(
+                DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));
+        
+        attachBinaryComparisonOperator(op, exprOp);
+    }
+    
+    @Override
+    public void visit( GreaterThanEqualExpression op ) throws IOException {
+        
+        BinaryComparisonOperator exprOp = new GTOrEqualToExpr(new OperatorKey(
+                DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));
+        
+        attachBinaryComparisonOperator(op, exprOp);
+    }
+    
+    @Override
+    public void visit( LessThanExpression op ) throws IOException {
+        
+        BinaryComparisonOperator exprOp = new LessThanExpr(new OperatorKey(
+                DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));
+        
+        attachBinaryComparisonOperator(op, exprOp);
+    }
+    
+    
+    @Override
+    public void visit( LessThanEqualExpression op ) throws IOException {
+        
+        BinaryComparisonOperator exprOp = new LTOrEqualToExpr(new OperatorKey(
+                DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));
+        
+        attachBinaryComparisonOperator(op, exprOp);
+    }
+    
+    @Override
+    public void visit(ProjectExpression op) throws IOException {
+        POProject exprOp;
+       
+        if(op.getAttachedRelationalOp() instanceof LOGenerate && op.getPlan().getSuccessors(op)==null &&
+            !(op.findReferent() instanceof LOInnerLoad)) {
+            exprOp = new PORelationToExprProject(new OperatorKey(DEFAULT_SCOPE, nodeGen
+                .getNextNodeId(DEFAULT_SCOPE)));
+         } else {
+            exprOp = new POProject(new OperatorKey(DEFAULT_SCOPE, nodeGen
+                .getNextNodeId(DEFAULT_SCOPE)));
+        }
+        
+        exprOp.setResultType(op.getType());
+        exprOp.setColumn(op.getColNum());
+        exprOp.setStar(op.isProjectStar());
+        // TODO implement this
+//        exprOp.setOverloaded(op.getOverloaded());
+        logToPhyMap.put(op, exprOp);
+        currentPlan.add(exprOp);        
+    }
+    
+    @Override
+    public void visit( MapLookupExpression op ) throws IOException {
+        ExpressionOperator physOp = new POMapLookUp(new OperatorKey(DEFAULT_SCOPE,
+                nodeGen.getNextNodeId(DEFAULT_SCOPE)));
+        ((POMapLookUp)physOp).setLookUpKey(op.getLookupKey() );
+        physOp.setResultType(op.getType());
+        physOp.setAlias(op.getFieldSchema().alias);
+        currentPlan.add(physOp);
+
+        logToPhyMap.put(op, physOp);
+
+        ExpressionOperator from = (ExpressionOperator) logToPhyMap.get(op
+                .getMap());
+        try {
+            currentPlan.connect(from, physOp);
+        } catch (PlanException e) {
+            int errCode = 2015;
+            String msg = "Invalid physical operators in the physical plan" ;
+            throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, e);
+        }
+    }
+    
+    @Override
+    public void visit(org.apache.pig.newplan.logical.expression.ConstantExpression op) throws IOException {
+        
+//        System.err.println("Entering Constant");
+        ConstantExpression ce = new ConstantExpression(new OperatorKey(DEFAULT_SCOPE,
+                nodeGen.getNextNodeId(DEFAULT_SCOPE)));
+        // We dont have aliases in ExpressionOperators
+        // ce.setAlias(op.getAlias());
+        ce.setValue(op.getValue());
+        ce.setResultType(op.getType());
+        //this operator doesn't have any predecessors
+        currentPlan.add(ce);
+        logToPhyMap.put(op, ce);
+//        System.err.println("Exiting Constant");
+    }
+    
+    @Override
+    public void visit( CastExpression op ) throws IOException {
+        POCast pCast = new POCast(new OperatorKey(DEFAULT_SCOPE, nodeGen
+                .getNextNodeId(DEFAULT_SCOPE)));
+//        physOp.setAlias(op.getAlias());
+        currentPlan.add(pCast);
+
+        logToPhyMap.put(op, pCast);
+        ExpressionOperator from = (ExpressionOperator) logToPhyMap.get(op
+                .getExpression());
+        pCast.setResultType(op.getType());
+        pCast.setFieldSchema(new ResourceSchema.ResourceFieldSchema(Util.translateFieldSchema(op.getFieldSchema())));
+        FuncSpec lfSpec = op.getFuncSpec();
+        if(null != lfSpec) {
+            pCast.setFuncSpec(lfSpec);
+        }
+        try {
+            currentPlan.connect(from, pCast);
+        } catch (PlanException e) {
+            int errCode = 2015;
+            String msg = "Invalid physical operators in the physical plan" ;
+            throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, e);
+        }
+    }
+    
+    @Override
+    public void visit( NotExpression op ) throws IOException {
+        
+        PONot pNot = new PONot(new OperatorKey(DEFAULT_SCOPE, nodeGen
+                .getNextNodeId(DEFAULT_SCOPE)));
+//        physOp.setAlias(op.getAlias());
+        currentPlan.add(pNot);
+
+        logToPhyMap.put(op, pNot);
+        ExpressionOperator from = (ExpressionOperator) logToPhyMap.get(op
+                .getExpression());
+        pNot.setExpr(from);
+        pNot.setResultType(op.getType());
+        pNot.setOperandType(op.getType());
+        try {
+            currentPlan.connect(from, pNot);
+        } catch (PlanException e) {
+            int errCode = 2015;
+            String msg = "Invalid physical operators in the physical plan" ;
+            throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, e);
+        }
+    }
+    
+    @Override
+    public void visit( IsNullExpression op ) throws IOException {
+        POIsNull pIsNull = new POIsNull(new OperatorKey(DEFAULT_SCOPE, nodeGen
+                .getNextNodeId(DEFAULT_SCOPE)));
+//        physOp.setAlias(op.getAlias());
+        currentPlan.add(pIsNull);
+
+        logToPhyMap.put(op, pIsNull);
+        ExpressionOperator from = (ExpressionOperator) logToPhyMap.get(op
+                .getExpression());
+        pIsNull.setExpr(from);
+        pIsNull.setResultType(op.getType());
+        pIsNull.setOperandType(op.getType());
+        try {
+            currentPlan.connect(from, pIsNull);
+        } catch (PlanException e) {
+            int errCode = 2015;
+            String msg = "Invalid physical operators in the physical plan" ;
+            throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, e);
+        }
+    }
+
+    @Override
+    public void visit( NegativeExpression op ) throws IOException {
+        PONegative pNegative = new PONegative(new OperatorKey(DEFAULT_SCOPE, nodeGen
+                .getNextNodeId(DEFAULT_SCOPE)));
+//        physOp.setAlias(op.getAlias());
+        currentPlan.add(pNegative);
+
+        logToPhyMap.put(op, pNegative);
+        ExpressionOperator from = (ExpressionOperator) logToPhyMap.get(op
+                .getExpression());
+        pNegative.setResultType(op.getType());        
+        try {
+            currentPlan.connect(from, pNegative);
+        } catch (PlanException e) {
+            int errCode = 2015;
+            String msg = "Invalid physical operators in the physical plan" ;
+            throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, e);
+        }
+    }
+    
+    @Override
+    public void visit( AddExpression op ) throws IOException {        
+        BinaryExpressionOperator exprOp = new Add(new OperatorKey(DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));        
+        
+        attachBinaryExpressionOperator(op, exprOp);
+    }
+    
+    @Override
+    public void visit( RegexExpression op ) throws IOException {        
+        BinaryExpressionOperator exprOp = new PORegexp(new OperatorKey(DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));        
+        
+        attachBinaryExpressionOperator(op, exprOp);
+    }
+    
+    @Override
+    public void visit( SubtractExpression op ) throws IOException {        
+        BinaryExpressionOperator exprOp = new Subtract(new OperatorKey(DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));        
+        
+        attachBinaryExpressionOperator(op, exprOp);
+    }
+    
+    @Override
+    public void visit( MultiplyExpression op ) throws IOException {        
+        BinaryExpressionOperator exprOp = new Multiply(new OperatorKey(DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));        
+        
+        attachBinaryExpressionOperator(op, exprOp);
+    }
+    
+    @Override
+    public void visit( DivideExpression op ) throws IOException {        
+        BinaryExpressionOperator exprOp = new Divide(new OperatorKey(DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));        
+        
+        attachBinaryExpressionOperator(op, exprOp);
+    }
+    
+    @Override
+    public void visit( ModExpression op ) throws IOException {        
+        BinaryExpressionOperator exprOp = new Mod(new OperatorKey(DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));        
+        
+        attachBinaryExpressionOperator(op, exprOp);
+    }
+    
+    @Override
+    public void visit( BinCondExpression op ) throws IOException {
+        
+        POBinCond exprOp = new POBinCond( new OperatorKey(DEFAULT_SCOPE,
+                nodeGen.getNextNodeId(DEFAULT_SCOPE)) );
+        
+        exprOp.setResultType(op.getType());
+        exprOp.setCond((ExpressionOperator) logToPhyMap.get(op.getCondition()));
+        exprOp.setLhs((ExpressionOperator) logToPhyMap.get(op.getLhs()));
+        exprOp.setRhs((ExpressionOperator) logToPhyMap.get(op.getRhs()));
+        OperatorPlan oPlan = op.getPlan();
+
+        currentPlan.add(exprOp);
+        logToPhyMap.put(op, exprOp);
+
+        List<Operator> successors = oPlan.getSuccessors(op);
+        if (successors == null) {
+            return;
+        }
+        for (Operator lo : successors) {
+            PhysicalOperator from = logToPhyMap.get(lo);
+            try {
+                currentPlan.connect(from, exprOp);
+            } catch (PlanException e) {
+                int errCode = 2015;
+                String msg = "Invalid physical operators in the physical plan" ;
+                throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, e);
+            }
+        }
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Override
+    public void visit( UserFuncExpression op ) throws IOException {       
+        Object f = PigContext.instantiateFuncFromSpec(op.getFuncSpec());
+        PhysicalOperator p;
+        if (f instanceof EvalFunc) {
+            p = new POUserFunc(new OperatorKey(DEFAULT_SCOPE, nodeGen
+                    .getNextNodeId(DEFAULT_SCOPE)), -1,
+                    null, op.getFuncSpec(), (EvalFunc) f);
+        } else {
+            p = new POUserComparisonFunc(new OperatorKey(DEFAULT_SCOPE, nodeGen
+                    .getNextNodeId(DEFAULT_SCOPE)), -1,
+                    null, op.getFuncSpec(), (ComparisonFunc) f);
+        }
+        p.setResultType(op.getType());
+        currentPlan.add(p);
+        List<LogicalExpression> fromList = op.getArguments();
+        if(fromList!=null){
+            for (LogicalExpression inputOperator : fromList) {
+                PhysicalOperator from = logToPhyMap.get(inputOperator);
+                try {
+                    currentPlan.connect(from, p);
+                } catch (PlanException e) {
+                    int errCode = 2015;
+                    String msg = "Invalid physical operators in the physical plan" ;
+                    throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, e);
+                }
+            }
+        }
+        logToPhyMap.put(op, p);
+    }
+    
+    @Override
+    public void visit( DereferenceExpression op ) throws IOException {
+        POProject exprOp = new POProject(new OperatorKey(DEFAULT_SCOPE, nodeGen
+                .getNextNodeId(DEFAULT_SCOPE)));
+
+        exprOp.setResultType(op.getType());
+        exprOp.setColumns((ArrayList<Integer>)op.getBagColumns());        
+        exprOp.setStar(false);
+        logToPhyMap.put(op, exprOp);
+        currentPlan.add(exprOp);
+        
+        PhysicalOperator from = logToPhyMap.get( op.getReferredExpression() );
+        
+        if( from != null ) {
+            currentPlan.connect(from, exprOp);
+        }
+    }
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/GreaterThanEqualExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/GreaterThanEqualExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/GreaterThanEqualExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/GreaterThanEqualExpression.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,76 @@
+/*
+ * 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;
+
+public class GreaterThanEqualExpression 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 GreaterThanEqualExpression(OperatorPlan plan,
+                           LogicalExpression lhs,
+                           LogicalExpression rhs) {
+        super("GreaterThanEqual", 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 GreaterThanEqualExpression) {
+            GreaterThanEqualExpression eo = (GreaterThanEqualExpression)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;
+    }
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/GreaterThanExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/GreaterThanExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/GreaterThanExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/GreaterThanExpression.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,76 @@
+/*
+ * 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;
+
+public class GreaterThanExpression 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 GreaterThanExpression(OperatorPlan plan,
+                           LogicalExpression lhs,
+                           LogicalExpression rhs) {
+        super("GreaterThan", 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 GreaterThanExpression) {
+            GreaterThanExpression eo = (GreaterThanExpression)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;
+    }
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/IsNullExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/IsNullExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/IsNullExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/IsNullExpression.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.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;
+
+public class IsNullExpression extends UnaryExpression {
+
+    public IsNullExpression(OperatorPlan plan, LogicalExpression exp) {
+        super("IsNull", plan, exp);        
+    }
+
+    @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 IsNullExpression) { 
+            IsNullExpression of = (IsNullExpression)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, null, DataType.BOOLEAN);
+        uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
+        return fieldSchema;
+    }
+
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LessThanEqualExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LessThanEqualExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LessThanEqualExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LessThanEqualExpression.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,76 @@
+/*
+ * 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;
+
+public class LessThanEqualExpression 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 LessThanEqualExpression(OperatorPlan plan,
+                           LogicalExpression lhs,
+                           LogicalExpression rhs) {
+        super("LessThanEqual", 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 LessThanEqualExpression) {
+            LessThanEqualExpression eo = (LessThanEqualExpression)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;
+    }
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LessThanExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LessThanExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LessThanExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LessThanExpression.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,76 @@
+/*
+ * 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;
+
+public class LessThanExpression 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 LessThanExpression(OperatorPlan plan,
+                           LogicalExpression lhs,
+                           LogicalExpression rhs) {
+        super("LessThan", 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 LessThanExpression) {
+            LessThanExpression eo = (LessThanExpression)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;
+    }
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LogicalExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LogicalExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LogicalExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LogicalExpression.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,101 @@
+/*
+ * 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.logical.relational.LogicalSchema;
+import org.apache.pig.newplan.logical.relational.LogicalSchema.LogicalFieldSchema;
+
+/**
+ * Logical representation of expression operators.  Expression operators have
+ * a data type and a uid.  Uid is a unique id for each expression. 
+ *
+ */
+public abstract class LogicalExpression extends Operator {
+    
+    static long nextUid = 1;
+    protected LogicalSchema.LogicalFieldSchema fieldSchema;
+    protected LogicalSchema.LogicalFieldSchema uidOnlyFieldSchema;
+
+    static public long getNextUid() {
+        return nextUid++;
+    }
+
+    // used for junit test, should not be called elsewhere
+    static public void resetNextUid() {
+        nextUid = 1;
+    }
+    /**
+     * 
+     * @param name of the operator
+     * @param plan LogicalExpressionPlan this is part of
+     */
+    public LogicalExpression(String name, OperatorPlan plan) {
+        super(name, plan);
+    }
+    
+    abstract public LogicalSchema.LogicalFieldSchema getFieldSchema() throws IOException;
+    
+    public void resetFieldSchema() {
+        fieldSchema = null;
+    }
+    
+    /**
+     * Get the data type for this expression.
+     * @return data type, one of the static bytes of DataType
+     */
+    public byte getType() {
+        try {
+            if (getFieldSchema()!=null)
+                return getFieldSchema().type;
+        } catch (IOException e) {
+        }
+        return DataType.UNKNOWN;
+    }
+    
+    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(")");
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+        return msg.toString();
+    }
+    
+    public void neverUseForRealSetFieldSchema(LogicalFieldSchema fs) throws IOException {
+        fieldSchema = fs;
+        uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
+    }
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LogicalExpressionPlan.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LogicalExpressionPlan.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LogicalExpressionPlan.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LogicalExpressionPlan.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,61 @@
+/*
+ * 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.io.PrintStream;
+import java.util.List;
+
+import org.apache.pig.newplan.BaseOperatorPlan;
+import org.apache.pig.newplan.Operator;
+import org.apache.pig.newplan.OperatorPlan;
+import org.apache.pig.newplan.logical.optimizer.ExprPrinter;
+
+/**
+ * A plan containing LogicalExpressionOperators.
+ */
+public class LogicalExpressionPlan extends BaseOperatorPlan {
+    
+    @Override
+    public boolean isEqual(OperatorPlan other) {
+        if (other != null && other instanceof LogicalExpressionPlan) {
+            LogicalExpressionPlan otherPlan = (LogicalExpressionPlan)other;
+            List<Operator> roots = getSources();
+            List<Operator> otherRoots = otherPlan.getSources();
+            if (roots.size() == 0 && otherRoots.size() == 0) return true;
+            if (roots.size() > 1 || otherRoots.size() > 1) {
+                throw new RuntimeException("Found LogicalExpressionPlan with more than one root.  Unexpected.");
+            }
+            return roots.get(0).isEqual(otherRoots.get(0));            
+        } else {
+            return false;
+        }
+    }
+    
+    @Override
+    public void explain(PrintStream ps, String format, boolean verbose) 
+    throws IOException {
+        ps.println("#-----------------------------------------------");
+        ps.println("# New Logical Expression Plan:");
+        ps.println("#-----------------------------------------------");
+
+        ExprPrinter npp = new ExprPrinter(this, ps);
+        npp.visit();
+    }
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LogicalExpressionVisitor.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LogicalExpressionVisitor.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LogicalExpressionVisitor.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LogicalExpressionVisitor.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,114 @@
+/*
+ * 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.PlanVisitor;
+import org.apache.pig.newplan.PlanWalker;
+
+/**
+ * A visitor for expression plans.
+ */
+public abstract class LogicalExpressionVisitor extends PlanVisitor {
+
+    protected LogicalExpressionVisitor(OperatorPlan p,
+                                       PlanWalker walker) {
+        super(p, walker);
+        
+        if (!(plan instanceof LogicalExpressionPlan)) {
+            throw new RuntimeException(
+                "LogicalExpressionVisitor expects to visit " +
+                "expression plans.");
+        }
+    }
+    
+    public void visit(AndExpression op) throws IOException {
+    }
+    
+    public void visit(OrExpression op) throws IOException { 
+    }
+
+    public void visit(EqualExpression op) throws IOException {
+    }
+    
+    public void visit(ProjectExpression op) throws IOException {
+    }
+    
+    public void visit(ConstantExpression op) throws IOException {
+    }
+    
+    public void visit(CastExpression op) throws IOException {
+    }
+
+    public void visit(GreaterThanExpression op) throws IOException {
+    }
+    
+    public void visit(GreaterThanEqualExpression op) throws IOException {
+    }
+
+    public void visit(LessThanExpression op) throws IOException { 
+    }
+    
+    public void visit(LessThanEqualExpression op) throws IOException {
+    }
+
+    public void visit(NotEqualExpression op) throws IOException { 
+    }
+
+    public void visit(NotExpression op ) throws IOException {
+    }
+
+    public void visit(IsNullExpression op) throws IOException {
+    }
+    
+    public void visit(NegativeExpression op) throws IOException {
+    }
+    
+    public void visit(AddExpression op) throws IOException {
+    }
+    
+    public void visit(SubtractExpression op) throws IOException {
+    }
+    
+    public void visit(MultiplyExpression op) throws IOException {
+    }
+    
+    public void visit(ModExpression op) throws IOException {
+    }
+    
+    public void visit(DivideExpression op) throws IOException {
+    }
+
+    public void visit(MapLookupExpression op) throws IOException {
+    }
+
+    public void visit(BinCondExpression op) throws IOException {        
+    }
+
+    public void visit(UserFuncExpression op) throws IOException {
+    }
+
+    public void visit(DereferenceExpression op) throws IOException {
+    }
+
+    public void visit(RegexExpression op) throws IOException {
+    }
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/MapLookupExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/MapLookupExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/MapLookupExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/MapLookupExpression.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,113 @@
+/*
+ * 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.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;
+
+public class MapLookupExpression extends ColumnExpression {
+
+    /**
+     * The key to lookup along with the type and schema corresponding to the
+     * type and schema of the value linked to the key
+     */
+    private String mMapKey;
+    private LogicalFieldSchema mValueSchema;
+    
+    public MapLookupExpression(OperatorPlan plan, String mapKey, 
+            LogicalFieldSchema valueSchema ) {
+        super("Map", plan);
+        mMapKey = mapKey;
+        mValueSchema = valueSchema;
+        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);
+    }
+    
+    @Override
+    public boolean isEqual(Operator other) {
+        if (other != null && other instanceof MapLookupExpression) {
+            MapLookupExpression po = (MapLookupExpression)other;
+            return ( po.mMapKey.compareTo(mMapKey) == 0 ) && 
+            po.mValueSchema.isEqual( mValueSchema );
+        } else {
+            return false;
+        }
+    }
+    
+    public LogicalExpression getMap() throws IOException {
+        List<Operator> preds = plan.getSuccessors(this);
+        if(preds == null) {
+            return null;
+        }
+        return (LogicalExpression)preds.get(0);
+    }
+    
+    public String getLookupKey() {
+        return mMapKey;
+    }
+    
+    public LogicalFieldSchema getFieldSchema() throws IOException {
+        if (fieldSchema!=null)
+            return fieldSchema;
+        if (mValueSchema!=null)
+            fieldSchema = mValueSchema;
+        else
+            fieldSchema = new LogicalSchema.LogicalFieldSchema(null, null, DataType.UNKNOWN);
+        uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
+        return fieldSchema;
+    }
+
+    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(" Key: " + mMapKey);
+            msg.append(")");
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+        return msg.toString();
+    }
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ModExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ModExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ModExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ModExpression.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;
+
+/**
+ * Mod Operator
+ */
+public class ModExpression 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 ModExpression(OperatorPlan plan,
+                         LogicalExpression lhs,
+                         LogicalExpression rhs) {
+        super("Mod", 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 ModExpression) {
+            ModExpression ao = (ModExpression)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/MultiplyExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/MultiplyExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/MultiplyExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/MultiplyExpression.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.newplan.Operator;
+import org.apache.pig.newplan.OperatorPlan;
+import org.apache.pig.newplan.PlanVisitor;
+import org.apache.pig.newplan.logical.relational.LogicalSchema;
+
+/**
+ * Multiply Operator
+ */
+public class MultiplyExpression 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 MultiplyExpression(OperatorPlan plan,
+                         LogicalExpression lhs,
+                         LogicalExpression rhs) {
+        super("Multiply", 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 MultiplyExpression) {
+            MultiplyExpression ao = (MultiplyExpression)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;
+    }
+
+}
\ No newline at end of file

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/NegativeExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/NegativeExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/NegativeExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/NegativeExpression.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,65 @@
+/*
+ * 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 NegativeExpression extends UnaryExpression {
+
+    public NegativeExpression(OperatorPlan plan, LogicalExpression exp) {
+        super("Negative", plan, exp);        
+    }
+
+    @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 NegativeExpression) { 
+            NegativeExpression of = (NegativeExpression)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;
+        LogicalExpression exp = (LogicalExpression)plan.getSuccessors(this).get(0);
+        fieldSchema = new LogicalSchema.LogicalFieldSchema(null, null, exp.getType());
+        uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
+        return fieldSchema;
+    }
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/NotEqualExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/NotEqualExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/NotEqualExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/NotEqualExpression.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;
+
+/**
+ * NotEquality test expression.
+ */
+public class NotEqualExpression 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 NotEqualExpression(OperatorPlan plan,
+                           LogicalExpression lhs,
+                           LogicalExpression rhs) {
+        super("NotEqual", 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 NotEqualExpression) {
+            NotEqualExpression eo = (NotEqualExpression)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;
+    }
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/NotExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/NotExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/NotExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/NotExpression.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+public class NotExpression extends UnaryExpression {
+
+    public NotExpression(OperatorPlan plan, LogicalExpression exp) {
+        super("Not", plan, exp);        
+    }
+
+    @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 NotExpression) { 
+            NotExpression of = (NotExpression)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, null, DataType.BOOLEAN);
+        uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
+        return fieldSchema;
+    }
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/OrExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/OrExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/OrExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/OrExpression.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 OR Expression
+ *
+ */
+public class OrExpression 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 OrExpression(OperatorPlan plan,
+                         LogicalExpression lhs,
+                         LogicalExpression rhs) {
+        super("Or", 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 OrExpression) {
+            OrExpression ao = (OrExpression)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/ProjectExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ProjectExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ProjectExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ProjectExpression.java Wed Aug  4 17:46:42 2010
@@ -0,0 +1,250 @@
+/*
+ * 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.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.LOForEach;
+import org.apache.pig.newplan.logical.relational.LOGenerate;
+import org.apache.pig.newplan.logical.relational.LOInnerLoad;
+import org.apache.pig.newplan.logical.relational.LogicalRelationalOperator;
+import org.apache.pig.newplan.logical.relational.LogicalSchema;
+import org.apache.pig.newplan.logical.relational.LogicalSchema.LogicalFieldSchema;
+
+/**
+ * Projection of columns in an expression.
+ *
+ */
+public class ProjectExpression extends ColumnExpression {
+    
+    private int input; // Which input of the relational operator this project
+                       // is projecting from.  Count is zero based.  So if this
+                       // project is in a filter the input number will always
+                       // be 0 (since filter has only one input).  If it is
+                       // in a join, cross, cogroup, or union it could be
+                       // greater than 0.
+    private int col; // The column in the input which the project references.
+                     // Count is zero based.
+    private LogicalRelationalOperator attachedRelationalOp;
+                      
+    
+    /**
+     * Adds projection to the plan.
+     * @param plan LogicalExpressionPlan this projection will be a part of
+     * @param inputNum Input number this project references.
+     * @param colNum Column number this project references.
+     */
+    public ProjectExpression(OperatorPlan plan,
+                             int inputNum,
+                             int colNum, LogicalRelationalOperator attachedRelationalOp) {
+        super("Project", plan);
+        input = inputNum;
+        col = colNum;
+        plan.add(this);
+        this.attachedRelationalOp = attachedRelationalOp;
+    }
+
+    /**
+     * @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);
+
+    }
+
+    /**
+     * Input number this project references.  This is the input number for the
+     * relational operator that contains this expression.  The count is zero
+     * based.
+     * @return input number
+     */
+    public int getInputNum() {
+        return input;
+    }
+    
+   
+    public void setInputNum(int inputNum) {
+        input = inputNum;
+    }
+    
+    /**
+     * Column number this project references.  The column number is the column
+     * in the relational operator that contains this expression.  The count
+     * is zero based.
+     * @return column number
+     */
+    public int getColNum() {
+        return col;
+    }
+    
+    /**
+     * Set the column number for this project.  This should only be called by
+     * ProjectionPatcher.  Stupid Java needs friends.  
+     * @param colNum new column number for projection
+     */
+    public void setColNum(int colNum) {
+        col = colNum;
+    }
+    
+    public boolean isProjectStar() {
+        return col<0;
+    }
+    
+    @Override
+    public LogicalSchema.LogicalFieldSchema getFieldSchema() throws IOException {
+        if (fieldSchema!=null)
+            return fieldSchema;
+        LogicalRelationalOperator referent = findReferent();
+        
+        LogicalSchema schema = referent.getSchema();
+        
+        if (schema == null) {
+            fieldSchema = new LogicalSchema.LogicalFieldSchema(null, null, DataType.BYTEARRAY);
+            uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
+        } 
+        else {
+            if (attachedRelationalOp instanceof LOGenerate && plan.getSuccessors(this)==null) {
+                if (!(findReferent() instanceof LOInnerLoad)||
+                        ((LOInnerLoad)findReferent()).sourceIsBag()) {
+                    String alias = findReferent().getAlias();
+                    List<LOInnerLoad> innerLoads = LOForEach.findReacheableInnerLoadFromBoundaryProject(this);
+                    
+                    // pull tuple information from innerload
+                    if (innerLoads.get(0).getProjection().getFieldSchema().schema.isTwoLevelAccessRequired()) {
+                        LogicalFieldSchema originalTupleFieldSchema = innerLoads.get(0).getProjection().getFieldSchema().schema.getField(0);
+                        LogicalFieldSchema newTupleFieldSchema = new LogicalFieldSchema(originalTupleFieldSchema.alias,
+                                schema, DataType.TUPLE);
+                        newTupleFieldSchema.uid = originalTupleFieldSchema.uid;
+                        LogicalSchema newTupleSchema = new LogicalSchema();
+                        newTupleSchema.setTwoLevelAccessRequired(true);
+                        newTupleSchema.addField(newTupleFieldSchema);
+                        fieldSchema = new LogicalSchema.LogicalFieldSchema(alias, newTupleSchema, DataType.BAG);
+                    }
+                    else {
+                        fieldSchema = new LogicalSchema.LogicalFieldSchema(alias, schema, DataType.BAG);
+                    }
+                    fieldSchema.uid = innerLoads.get(0).getProjection().getFieldSchema().uid;
+                }
+                else {
+                    fieldSchema = findReferent().getSchema().getField(0);
+                }
+                uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
+            }
+            else {
+                int index = -1;
+                if (!isProjectStar() && uidOnlyFieldSchema!=null) {
+                    long uid = uidOnlyFieldSchema.uid;
+                    for (int i=0;i<schema.size();i++) {
+                        LogicalFieldSchema fs = schema.getField(i);
+                        if (fs.uid==uid) {
+                            index = i;
+                        }
+                    }
+                }
+                if (index==-1)
+                    index = col;
+                
+                if (!isProjectStar()) {
+                    fieldSchema = schema.getField(index);
+                    uidOnlyFieldSchema = fieldSchema.cloneUid();
+                }
+                else {
+                    fieldSchema = new LogicalSchema.LogicalFieldSchema(null, schema.deepCopy(), DataType.TUPLE);
+                    uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
+                }
+            }
+        }
+
+        return fieldSchema;
+    }
+    
+    /**
+     * Find the LogicalRelationalOperator that this projection refers to.
+     * @param currentOp Current operator this projection is attached to
+     * @return LRO this projection refers to
+     * @throws IOException
+     */
+    public LogicalRelationalOperator findReferent() throws IOException {
+        List<Operator> preds;
+        preds = attachedRelationalOp.getPlan().getPredecessors(attachedRelationalOp);
+        if (preds == null || input >= preds.size()) {
+            throw new IOException("Projection with nothing to reference!");
+        }
+            
+        LogicalRelationalOperator pred =
+            (LogicalRelationalOperator)preds.get(input);
+        if (pred == null) {
+            throw new IOException("Found bad operator in logical plan");
+        }
+        return pred;
+    }
+    
+    @Override
+    public boolean isEqual(Operator other) {
+        if (other != null && other instanceof ProjectExpression) {
+            ProjectExpression po = (ProjectExpression)other;
+            return po.input == input && po.col == col;
+        } else {
+            return false;
+        }
+    }
+    
+    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(" Input: " + input + " Column: ");
+            if (isProjectStar())
+                msg.append("(*)");
+            else
+                msg.append(col);
+            msg.append(")");
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+        return msg.toString();
+    }
+    
+    public LogicalRelationalOperator getAttachedRelationalOp() {
+        return attachedRelationalOp;
+    }
+    
+    public void setAttachedRelationalOp(LogicalRelationalOperator attachedRelationalOp) {
+        this.attachedRelationalOp = attachedRelationalOp;
+    }
+}

Added: hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/RegexExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/RegexExpression.java?rev=982345&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/RegexExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/RegexExpression.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;
+
+/**
+ * Regex Operator
+ */
+public class RegexExpression 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 RegexExpression(OperatorPlan plan,
+                         LogicalExpression lhs,
+                         LogicalExpression rhs) {
+        super("Regex", 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 RegexExpression) {
+            RegexExpression ao = (RegexExpression)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;
+    }
+}
\ No newline at end of file



Mime
View raw message