You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by ga...@apache.org on 2010/03/05 22:55:20 UTC
svn commit: r919634 [1/3] - in /hadoop/pig/trunk: src/org/apache/pig/
src/org/apache/pig/backend/hadoop/executionengine/
src/org/apache/pig/experimental/logical/
src/org/apache/pig/experimental/logical/expression/
src/org/apache/pig/experimental/logica...
Author: gates
Date: Fri Mar 5 21:55:19 2010
New Revision: 919634
URL: http://svn.apache.org/viewvc?rev=919634&view=rev
Log:
Experimental optimizer incremental patch. Added more expression operators and some bug fixes.
Added:
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/AddExpression.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/DivideExpression.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/IsNullExpression.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/MapLookupExpression.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/ModExpression.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/MultiplyExpression.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/NegativeExpression.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/NotEqualExpression.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/NotExpression.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/SubtractExpression.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/optimizer/PlanPrinter.java
Modified:
hadoop/pig/trunk/src/org/apache/pig/PigServer.java
hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/HExecutionEngine.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/LogicalPlanMigrationVistor.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/ExpToPhyTranslationVisitor.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/LogicalExpression.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/LogicalExpressionVisitor.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/ProjectExpression.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/optimizer/AllExpressionVisitor.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/optimizer/AllSameVisitor.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/optimizer/LogicalPlanOptimizer.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/optimizer/UidStamper.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/relational/LOForEach.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/relational/LOGenerate.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/relational/LOInnerLoad.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/relational/LOLoad.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/relational/LogToPhyTranslationVisitor.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/relational/LogicalPlan.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/relational/LogicalRelationalOperator.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/relational/LogicalSchema.java
hadoop/pig/trunk/src/org/apache/pig/experimental/logical/rules/FilterAboveForeach.java
hadoop/pig/trunk/src/org/apache/pig/experimental/plan/BaseOperatorPlan.java
hadoop/pig/trunk/src/org/apache/pig/experimental/plan/Operator.java
hadoop/pig/trunk/src/org/apache/pig/experimental/plan/OperatorPlan.java
hadoop/pig/trunk/src/org/apache/pig/experimental/plan/OperatorSubPlan.java
hadoop/pig/trunk/test/org/apache/pig/test/TestExperimentalFilterAboveForeach.java
hadoop/pig/trunk/test/org/apache/pig/test/TestExperimentalListener.java
hadoop/pig/trunk/test/org/apache/pig/test/TestExperimentalLogToPhyTranslationVisitor.java
hadoop/pig/trunk/test/org/apache/pig/test/TestExperimentalLogicalOptimizer.java
hadoop/pig/trunk/test/org/apache/pig/test/TestExperimentalOperatorPlan.java
hadoop/pig/trunk/test/org/apache/pig/test/TestLogicalPlanMigrationVisitor.java
Modified: hadoop/pig/trunk/src/org/apache/pig/PigServer.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/PigServer.java?rev=919634&r1=919633&r2=919634&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/PigServer.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/PigServer.java Fri Mar 5 21:55:19 2010
@@ -52,6 +52,10 @@
import org.apache.pig.builtin.PigStorage;
import org.apache.pig.data.DataBag;
import org.apache.pig.data.Tuple;
+import org.apache.pig.experimental.logical.LogicalPlanMigrationVistor;
+import org.apache.pig.experimental.logical.optimizer.LogicalPlanOptimizer;
+import org.apache.pig.experimental.logical.optimizer.PlanPrinter;
+import org.apache.pig.experimental.logical.optimizer.UidStamper;
import org.apache.pig.impl.PigContext;
import org.apache.pig.impl.io.FileLocalizer;
import org.apache.pig.impl.logicalLayer.FrontendException;
@@ -619,6 +623,20 @@
}
PhysicalPlan pp = compilePp(lp);
lp.explain(lps, format, verbose);
+ if( pigContext.getProperties().getProperty("pig.usenewlogicalplan", "false").equals("true") ) {
+ LogicalPlanMigrationVistor migrator = new LogicalPlanMigrationVistor(lp);
+ migrator.visit();
+ org.apache.pig.experimental.logical.relational.LogicalPlan newPlan = migrator.getNewLogicalPlan();
+
+ // set uids
+ UidStamper stamper = new UidStamper(newPlan);
+ stamper.visit();
+
+ LogicalPlanOptimizer optimizer = new LogicalPlanOptimizer(newPlan, 3);
+ optimizer.optimize();
+
+ newPlan.explain(lps, format, verbose);
+ }
pp.explain(pps, format, verbose);
pigContext.getExecutionEngine().explain(pp, eps, format, verbose);
if (markAsExecute) {
Modified: hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/HExecutionEngine.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/HExecutionEngine.java?rev=919634&r1=919633&r2=919634&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/HExecutionEngine.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/HExecutionEngine.java Fri Mar 5 21:55:19 2010
@@ -25,12 +25,12 @@
import java.net.SocketException;
import java.net.SocketImplFactory;
import java.net.URL;
-import java.util.Collection;
-import java.util.List;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -49,18 +49,17 @@
import org.apache.pig.backend.executionengine.util.ExecTools;
import org.apache.pig.backend.hadoop.datastorage.ConfigurationUtil;
import org.apache.pig.backend.hadoop.datastorage.HDataStorage;
-import org.apache.pig.impl.PigContext;
-import org.apache.pig.impl.io.FileSpec;
-import org.apache.pig.impl.logicalLayer.LogicalPlan;
+import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MapReduceLauncher;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.LogToPhyTranslationVisitor;
-import org.apache.pig.impl.plan.OperatorKey;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhysicalPlan;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.PhysicalOperator;
-import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MapReduceLauncher;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhysicalPlan;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POStore;
import org.apache.pig.experimental.logical.LogicalPlanMigrationVistor;
import org.apache.pig.experimental.logical.optimizer.UidStamper;
-import org.apache.pig.impl.plan.VisitorException;
+import org.apache.pig.impl.PigContext;
+import org.apache.pig.impl.io.FileSpec;
+import org.apache.pig.impl.logicalLayer.LogicalPlan;
+import org.apache.pig.impl.plan.OperatorKey;
import org.apache.pig.tools.pigstats.PigStats;
public class HExecutionEngine implements ExecutionEngine {
Modified: hadoop/pig/trunk/src/org/apache/pig/experimental/logical/LogicalPlanMigrationVistor.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/experimental/logical/LogicalPlanMigrationVistor.java?rev=919634&r1=919633&r2=919634&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/experimental/logical/LogicalPlanMigrationVistor.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/experimental/logical/LogicalPlanMigrationVistor.java Fri Mar 5 21:55:19 2010
@@ -19,26 +19,38 @@
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import org.apache.pig.data.DataType;
+import org.apache.pig.experimental.logical.expression.AddExpression;
import org.apache.pig.experimental.logical.expression.AndExpression;
import org.apache.pig.experimental.logical.expression.CastExpression;
import org.apache.pig.experimental.logical.expression.ConstantExpression;
+import org.apache.pig.experimental.logical.expression.DivideExpression;
import org.apache.pig.experimental.logical.expression.EqualExpression;
import org.apache.pig.experimental.logical.expression.GreaterThanEqualExpression;
import org.apache.pig.experimental.logical.expression.GreaterThanExpression;
+import org.apache.pig.experimental.logical.expression.IsNullExpression;
import org.apache.pig.experimental.logical.expression.LessThanEqualExpression;
import org.apache.pig.experimental.logical.expression.LessThanExpression;
import org.apache.pig.experimental.logical.expression.LogicalExpression;
import org.apache.pig.experimental.logical.expression.LogicalExpressionPlan;
+import org.apache.pig.experimental.logical.expression.MapLookupExpression;
+import org.apache.pig.experimental.logical.expression.ModExpression;
+import org.apache.pig.experimental.logical.expression.MultiplyExpression;
+import org.apache.pig.experimental.logical.expression.NegativeExpression;
+import org.apache.pig.experimental.logical.expression.NotEqualExpression;
+import org.apache.pig.experimental.logical.expression.NotExpression;
import org.apache.pig.experimental.logical.expression.OrExpression;
import org.apache.pig.experimental.logical.expression.ProjectExpression;
+import org.apache.pig.experimental.logical.expression.SubtractExpression;
import org.apache.pig.experimental.logical.relational.LOInnerLoad;
import org.apache.pig.experimental.logical.relational.LogicalRelationalOperator;
import org.apache.pig.experimental.logical.relational.LogicalSchema;
import org.apache.pig.impl.io.FileSpec;
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;
@@ -82,6 +94,7 @@
import org.apache.pig.impl.logicalLayer.LogicalPlan;
import org.apache.pig.impl.logicalLayer.LOJoin.JOINTYPE;
import org.apache.pig.impl.logicalLayer.schema.Schema;
+import org.apache.pig.impl.logicalLayer.schema.Schema.FieldSchema;
import org.apache.pig.impl.plan.DependencyOrderWalker;
import org.apache.pig.impl.plan.PlanWalker;
import org.apache.pig.impl.plan.VisitorException;
@@ -207,12 +220,52 @@
innerPlan.add(gen);
List<LogicalPlan> ll = forEach.getForEachPlans();
+ int index = 0;
for(int i=0; i<ll.size(); i++) {
LogicalPlan lp = ll.get(i);
ForeachInnerPlanVisitor v = new ForeachInnerPlanVisitor(newForeach, forEach, lp);
v.visit();
-
- innerPlan.connect(v.lastOp, gen);
+
+ // get the logical plan for this inner plan and merge it as subplan of LOGenerator
+ if (v.tmpPlan.size() > 0) {
+ // add all operators into innerplan
+ Iterator<org.apache.pig.experimental.plan.Operator> iter = v.tmpPlan.getOperators();
+ while(iter.hasNext()) {
+ innerPlan.add(iter.next());
+ }
+
+ // connect sinks to generator
+ // the list returned may not be in correct order, so check annotation
+ // to guarantee correct order
+ List<org.apache.pig.experimental.plan.Operator> s = v.tmpPlan.getSinks();
+ for(int j=0; j<s.size(); j++) {
+ for(org.apache.pig.experimental.plan.Operator op: s) {
+ if (Integer.valueOf(j+index).equals(op.getAnnotation("inputNo"))) {
+ innerPlan.connect(op, gen);
+ break;
+ }
+ }
+ }
+ index += s.size();
+
+ // copy connections
+ iter = v.tmpPlan.getOperators();
+ while(iter.hasNext()) {
+ org.apache.pig.experimental.plan.Operator op = iter.next();
+ op.removeAnnotation("inputNo");
+ try{
+ List<org.apache.pig.experimental.plan.Operator> succ = v.tmpPlan.getSuccessors(op);
+ if (succ != null) {
+ for(org.apache.pig.experimental.plan.Operator ss: succ) {
+ innerPlan.connect(op, ss);
+ }
+ }
+ }catch(Exception e) {
+ throw new VisitorException(e);
+ }
+ }
+ }
+
expPlans.add(v.exprPlan);
}
@@ -362,7 +415,6 @@
}
public void visit(LOConst con) throws VisitorException{
-
ConstantExpression ce = new ConstantExpression(exprPlan, con.getType(), con.getValue());
exprPlan.add(ce);
@@ -403,7 +455,8 @@
LessThanEqualExpression eq = new LessThanEqualExpression
(exprPlan, exprOpsMap.get(left), exprOpsMap.get(right));
- exprOpsMap.put(op, eq); }
+ exprOpsMap.put(op, eq);
+ }
public void visit(LOEqual op) throws VisitorException {
ExpressionOperator left = op.getLhsOperand();
@@ -435,36 +488,86 @@
}
public void visit(LONotEqual op) throws VisitorException {
- throw new VisitorException("LONotEqual is not supported.");
+ 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 op) throws VisitorException {
- throw new VisitorException("LOAdd is not supported.");
+ public void visit(LOAdd binOp) throws VisitorException {
+ ExpressionOperator left = binOp.getLhsOperand();
+ ExpressionOperator right = binOp.getRhsOperand();
+
+ AddExpression ae = new AddExpression(exprPlan, binOp.getType()
+ , exprOpsMap.get(left), exprOpsMap.get(right));
+ exprOpsMap.put(binOp, ae);
}
- public void visit(LOSubtract op) throws VisitorException {
- throw new VisitorException("LOSubtract is not supported.");
+ public void visit(LOSubtract binOp) throws VisitorException {
+ ExpressionOperator left = binOp.getLhsOperand();
+ ExpressionOperator right = binOp.getRhsOperand();
+
+ SubtractExpression ae = new SubtractExpression(exprPlan, binOp.getType()
+ , exprOpsMap.get(left), exprOpsMap.get(right));
+ exprOpsMap.put(binOp, ae);
}
- public void visit(LOMultiply op) throws VisitorException {
- throw new VisitorException("LOMultiply is not supported.");
+ public void visit(LOMultiply binOp) throws VisitorException {
+ ExpressionOperator left = binOp.getLhsOperand();
+ ExpressionOperator right = binOp.getRhsOperand();
+
+ MultiplyExpression ae = new MultiplyExpression(exprPlan, binOp.getType()
+ , exprOpsMap.get(left), exprOpsMap.get(right));
+ exprOpsMap.put(binOp, ae);
}
- public void visit(LODivide op) throws VisitorException {
- throw new VisitorException("LODivide is not supported.");
+ public void visit(LODivide binOp) throws VisitorException {
+ ExpressionOperator left = binOp.getLhsOperand();
+ ExpressionOperator right = binOp.getRhsOperand();
+
+ DivideExpression ae = new DivideExpression(exprPlan, binOp.getType()
+ , exprOpsMap.get(left), exprOpsMap.get(right));
+ exprOpsMap.put(binOp, ae);
}
- public void visit(LOMod op) throws VisitorException {
- throw new VisitorException("LOMod is not supported.");
+ public void visit(LOMod binOp) throws VisitorException {
+ ExpressionOperator left = binOp.getLhsOperand();
+ ExpressionOperator right = binOp.getRhsOperand();
+
+ ModExpression ae = new ModExpression(exprPlan, binOp.getType()
+ , exprOpsMap.get(left), exprOpsMap.get(right));
+ exprOpsMap.put(binOp, ae);
}
- public void visit(LONegative op) throws VisitorException {
- throw new VisitorException("LONegative is not supported.");
+ public void visit(LONegative uniOp) throws VisitorException {
+ ExpressionOperator exp = uniOp.getOperand();
+ NegativeExpression op = new NegativeExpression(exprPlan, exp.getType(), exprOpsMap.get(exp));
+ exprOpsMap.put(uniOp, op);
}
- public void visit(LOMapLookup op) throws VisitorException {
- throw new VisitorException("LOMapLookup is not supported.");
+ 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,
+ translateSchema(fieldSchema.schema), fieldSchema.type);
+
+ LogicalExpression map = exprOpsMap.get( colOp.getMap() );
+
+ MapLookupExpression op = new MapLookupExpression(exprPlan,
+ colOp.getValueType(), colOp.getLookUpKey(), logfieldSchema);
+
+ exprPlan.connect(op, map);
+
+ exprOpsMap.put(colOp, op);
}
public void visit(LOAnd binOp) throws VisitorException {
@@ -484,11 +587,15 @@
}
public void visit(LONot uniOp) throws VisitorException {
- throw new VisitorException("LONot is not supported.");
+ ExpressionOperator exp = uniOp.getOperand();
+ NotExpression not = new NotExpression(exprPlan, DataType.BOOLEAN, exprOpsMap.get(exp));
+ exprOpsMap.put(uniOp, not);
}
public void visit(LOIsNull uniOp) throws VisitorException {
- throw new VisitorException("LOIsNull is not supported.");
+ ExpressionOperator exp = uniOp.getOperand();
+ IsNullExpression isNull = new IsNullExpression(exprPlan, DataType.BOOLEAN, exprOpsMap.get(exp));
+ exprOpsMap.put(uniOp, isNull);
}
}
@@ -497,20 +604,28 @@
public class ForeachInnerPlanVisitor extends LogicalExpPlanMigrationVistor {
private org.apache.pig.experimental.logical.relational.LOForEach foreach;
private LOForEach oldForeach;
- private org.apache.pig.experimental.logical.relational.LOGenerate gen;
- private org.apache.pig.experimental.logical.relational.LogicalPlan newInnerPlan;
-
+ private int inputNo;
private HashMap<LogicalOperator, LogicalRelationalOperator> innerOpsMap;
- private LogicalRelationalOperator lastOp;
+ private org.apache.pig.experimental.logical.relational.LogicalPlan tmpPlan;
public ForeachInnerPlanVisitor(org.apache.pig.experimental.logical.relational.LOForEach foreach, LOForEach oldForeach, LogicalPlan plan) {
super(plan);
this.foreach = foreach;
- newInnerPlan = foreach.getInnerPlan();
- gen = (org.apache.pig.experimental.logical.relational.LOGenerate)newInnerPlan.getSinks().get(0);
+ org.apache.pig.experimental.logical.relational.LogicalPlan newInnerPlan = foreach.getInnerPlan();
+ org.apache.pig.experimental.plan.Operator gen = newInnerPlan.getSinks().get(0);
+ try {
+ inputNo = 0;
+ List<org.apache.pig.experimental.plan.Operator> suc = newInnerPlan.getPredecessors(gen);
+ if (suc != null) {
+ inputNo = suc.size();
+ }
+ }catch(Exception e) {
+ throw new RuntimeException(e);
+ }
this.oldForeach = oldForeach;
innerOpsMap = new HashMap<LogicalOperator, LogicalRelationalOperator>();
+ tmpPlan = new org.apache.pig.experimental.logical.relational.LogicalPlan();
}
public void visit(LOProject project) throws VisitorException {
@@ -520,33 +635,21 @@
// if this projection is to get a field from outer plan, change it
// to LOInnerLoad
- LOInnerLoad innerLoad = new LOInnerLoad(newInnerPlan, foreach, project.getCol());
- newInnerPlan.add(innerLoad);
-
- List<LogicalOperator> ll = mPlan.getSuccessors(project);
- if (ll == null || ll.get(0) instanceof ExpressionOperator || project.isStar()) {
- int size = 0;
- try {
- List<org.apache.pig.experimental.plan.Operator> suc = newInnerPlan.getPredecessors(gen);
- if (suc != null) {
- size = suc.size();
- }
- }catch(Exception e) {
- throw new VisitorException(e);
- }
-
- lastOp = innerLoad;
-
- ProjectExpression pe = new ProjectExpression(exprPlan, project.getType(), size, 0);
- exprPlan.add(pe);
- exprOpsMap.put(project, pe);
- translateConnection(project, pe);
- } else {
- innerOpsMap.put(project, innerLoad);
- }
- } else {
- super.visit(project);
- }
+ LOInnerLoad innerLoad = new LOInnerLoad(tmpPlan, foreach, project.getCol());
+ // mark the input index of this subtree under LOGenerate
+ // the successors of innerLoad should also annotatet the same inputNo
+ innerLoad.annotate("inputNo", Integer.valueOf(inputNo));
+ tmpPlan.add(innerLoad);
+ innerOpsMap.put(project, innerLoad);
+ }
+
+ List<LogicalOperator> ll = mPlan.getSuccessors(project);
+ if (ll == null || ll.get(0) instanceof ExpressionOperator) {
+ ProjectExpression pe = new ProjectExpression(exprPlan, project.getType(), inputNo++, 0);
+ exprPlan.add(pe);
+ exprOpsMap.put(project, pe);
+ translateConnection(project, pe);
+ }
}
public void visit(LOForEach foreach) throws VisitorException {
Added: hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/AddExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/AddExpression.java?rev=919634&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/AddExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/AddExpression.java Fri Mar 5 21:55:19 2010
@@ -0,0 +1,71 @@
+/*
+ * 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.experimental.logical.expression;
+
+import java.io.IOException;
+
+import org.apache.pig.experimental.plan.Operator;
+import org.apache.pig.experimental.plan.OperatorPlan;
+import org.apache.pig.experimental.plan.PlanVisitor;
+
+/**
+ * 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 b this is the type of this expression
+ * @param lhs expression on its left hand side
+ * @param rhs expression on its right hand side
+ */
+ public AddExpression(OperatorPlan plan,
+ byte b,
+ LogicalExpression lhs,
+ LogicalExpression rhs) {
+ super("Add", plan, b, 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).visitAdd(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;
+ }
+ }
+}
Added: hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/DivideExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/DivideExpression.java?rev=919634&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/DivideExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/DivideExpression.java Fri Mar 5 21:55:19 2010
@@ -0,0 +1,71 @@
+/*
+ * 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.experimental.logical.expression;
+
+import java.io.IOException;
+
+import org.apache.pig.experimental.plan.Operator;
+import org.apache.pig.experimental.plan.OperatorPlan;
+import org.apache.pig.experimental.plan.PlanVisitor;
+
+/**
+ * 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 b this is the type of this expression
+ * @param lhs expression on its left hand side
+ * @param rhs expression on its right hand side
+ */
+ public DivideExpression(OperatorPlan plan,
+ byte b,
+ LogicalExpression lhs,
+ LogicalExpression rhs) {
+ super("Divide", plan, b, 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).visitDivide(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;
+ }
+ }
+}
Modified: hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/ExpToPhyTranslationVisitor.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/ExpToPhyTranslationVisitor.java?rev=919634&r1=919633&r2=919634&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/ExpToPhyTranslationVisitor.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/ExpToPhyTranslationVisitor.java Fri Mar 5 21:55:19 2010
@@ -26,17 +26,28 @@
import org.apache.pig.PigException;
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.GreaterThanExpr;
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.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.PORelationToExprProject;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.Subtract;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhysicalPlan;
import org.apache.pig.data.DataType;
import org.apache.pig.experimental.logical.relational.LogicalRelationalOperator;
@@ -87,77 +98,18 @@
public PhysicalPlan getPhysicalPlan() {
return currentPlan;
}
-
- @Override
- public void visitAnd( AndExpression op ) throws IOException {
- String scope = DEFAULT_SCOPE;
-// System.err.println("Entering And");
- BinaryComparisonOperator exprOp = new POAnd(new OperatorKey(scope, nodeGen.getNextNodeId(scope)));
- // We dont have aliases in ExpressionOperators
- // exprOp.setAlias(op.getAlias());
- 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);
- }
- }
-// System.err.println("Exiting And");
- }
- @Override
- public void visitOr( OrExpression op ) throws IOException {
- String scope = DEFAULT_SCOPE;
-// System.err.println("Entering Or");
- BinaryComparisonOperator exprOp = new POOr(new OperatorKey(scope, nodeGen.getNextNodeId(scope)));
+ private void attachBinaryComparisonOperator( BinaryExpression op,
+ BinaryComparisonOperator exprOp ) throws IOException {
// We dont have aliases in ExpressionOperators
// exprOp.setAlias(op.getAlias());
- 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);
- }
- }
-// System.err.println("Exiting Or");
- }
-
- @Override
- public void visitEqual( EqualExpression op ) throws IOException {
- String scope = DEFAULT_SCOPE;
- BinaryComparisonOperator exprOp = new EqualToExpr(new OperatorKey(
- scope, nodeGen.getNextNodeId(scope)));
- // 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);
@@ -177,18 +129,17 @@
}
}
- @Override
- public void visitGreaterThan( GreaterThanExpression op ) throws IOException {
- String scope = DEFAULT_SCOPE;
- BinaryComparisonOperator exprOp = new GreaterThanExpr(new OperatorKey(
- scope, nodeGen.getNextNodeId(scope)));
+ private void attachBinaryExpressionOperator( BinaryExpression op,
+ BinaryExpressionOperator exprOp ) throws IOException {
// We dont have aliases in ExpressionOperators
// exprOp.setAlias(op.getAlias());
- exprOp.setOperandType(op.getLhs().getType());
+
+
+ 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);
@@ -207,120 +158,99 @@
}
}
}
+
+ @Override
+ public void visitAnd( 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 visitOr( 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 visitEqual( EqualExpression op ) throws IOException {
+
+ BinaryComparisonOperator exprOp = new EqualToExpr(new OperatorKey(
+ DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));
+
+ attachBinaryComparisonOperator(op, exprOp);
+ }
+
+ @Override
+ public void visitNotEqual( NotEqualExpression op ) throws IOException {
+
+ BinaryComparisonOperator exprOp = new NotEqualToExpr(new OperatorKey(
+ DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));
+
+ attachBinaryComparisonOperator(op, exprOp);
+ }
+
+ @Override
+ public void visitGreaterThan( GreaterThanExpression op ) throws IOException {
+
+ BinaryComparisonOperator exprOp = new GreaterThanExpr(new OperatorKey(
+ DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));
+
+ attachBinaryComparisonOperator(op, exprOp);
+ }
@Override
public void visitGreaterThanEqual( GreaterThanEqualExpression op ) throws IOException {
- String scope = DEFAULT_SCOPE;
+
BinaryComparisonOperator exprOp = new LessThanExpr(new OperatorKey(
- scope, nodeGen.getNextNodeId(scope)));
- // 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();
+ DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));
- 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);
- }
- }
+ attachBinaryComparisonOperator(op, exprOp);
}
@Override
public void visitLessThan( LessThanExpression op ) throws IOException {
- String scope = DEFAULT_SCOPE;
+
BinaryComparisonOperator exprOp = new LessThanExpr(new OperatorKey(
- scope, nodeGen.getNextNodeId(scope)));
- // 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();
+ DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));
- 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);
- }
- }
+ attachBinaryComparisonOperator(op, exprOp);
}
@Override
public void visitLessThanEqual( LessThanEqualExpression op ) throws IOException {
- String scope = DEFAULT_SCOPE;
+
BinaryComparisonOperator exprOp = new LessThanExpr(new OperatorKey(
- scope, nodeGen.getNextNodeId(scope)));
- // 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();
+ DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));
- 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);
- }
- }
+ attachBinaryComparisonOperator(op, exprOp);
}
@Override
public void visitProject(ProjectExpression op) throws IOException {
- String scope = DEFAULT_SCOPE;
// System.err.println("Entering Project");
POProject exprOp;
if(op.getType() == DataType.BAG) {
- exprOp = new PORelationToExprProject(new OperatorKey(scope, nodeGen
- .getNextNodeId(scope)));
+ exprOp = new PORelationToExprProject(new OperatorKey(DEFAULT_SCOPE, nodeGen
+ .getNextNodeId(DEFAULT_SCOPE)));
} else {
- exprOp = new POProject(new OperatorKey(scope, nodeGen
- .getNextNodeId(scope)));
+ exprOp = new POProject(new OperatorKey(DEFAULT_SCOPE, nodeGen
+ .getNextNodeId(DEFAULT_SCOPE)));
}
+
// We dont have aliases in ExpressionOperators
// exprOp.setAlias(op.getAlias());
exprOp.setResultType(op.getType());
exprOp.setColumn(op.getColNum());
+ exprOp.setStar(false);
// TODO implement this
-// exprOp.setStar(op.isStar());
// exprOp.setOverloaded(op.getOverloaded());
logToPhyMap.put(op, exprOp);
currentPlan.add(exprOp);
@@ -349,11 +279,33 @@
}
@Override
+ public void visitMapLookup( 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 visitConstant(org.apache.pig.experimental.logical.expression.ConstantExpression op) throws IOException {
- String scope = DEFAULT_SCOPE;
+
// System.err.println("Entering Constant");
- ConstantExpression ce = new ConstantExpression(new OperatorKey(scope,
- nodeGen.getNextNodeId(scope)));
+ 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());
@@ -366,9 +318,8 @@
@Override
public void visitCast( CastExpression op ) throws IOException {
- String scope = DEFAULT_SCOPE;
- POCast pCast = new POCast(new OperatorKey(scope, nodeGen
- .getNextNodeId(scope)));
+ POCast pCast = new POCast(new OperatorKey(DEFAULT_SCOPE, nodeGen
+ .getNextNodeId(DEFAULT_SCOPE)));
// physOp.setAlias(op.getAlias());
currentPlan.add(pCast);
@@ -388,4 +339,100 @@
throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, e);
}
}
+
+ @Override
+ public void visitNot( 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.setResultType(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 visitIsNull( 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.setResultType(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 visitNegative( 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 visitAdd( AddExpression op ) throws IOException {
+ BinaryExpressionOperator exprOp = new Add(new OperatorKey(DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));
+
+ attachBinaryExpressionOperator(op, exprOp);
+ }
+
+ @Override
+ public void visitSubtract( SubtractExpression op ) throws IOException {
+ BinaryExpressionOperator exprOp = new Subtract(new OperatorKey(DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));
+
+ attachBinaryExpressionOperator(op, exprOp);
+ }
+
+ @Override
+ public void visitMultiply( MultiplyExpression op ) throws IOException {
+ BinaryExpressionOperator exprOp = new Multiply(new OperatorKey(DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));
+
+ attachBinaryExpressionOperator(op, exprOp);
+ }
+
+ @Override
+ public void visitDivide( DivideExpression op ) throws IOException {
+ BinaryExpressionOperator exprOp = new Divide(new OperatorKey(DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));
+
+ attachBinaryExpressionOperator(op, exprOp);
+ }
+
+ @Override
+ public void visitMod( ModExpression op ) throws IOException {
+ BinaryExpressionOperator exprOp = new Mod(new OperatorKey(DEFAULT_SCOPE, nodeGen.getNextNodeId(DEFAULT_SCOPE)));
+
+ attachBinaryExpressionOperator(op, exprOp);
+ }
}
Added: hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/IsNullExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/IsNullExpression.java?rev=919634&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/IsNullExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/IsNullExpression.java Fri Mar 5 21:55:19 2010
@@ -0,0 +1,54 @@
+/*
+ * 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.experimental.logical.expression;
+
+import java.io.IOException;
+
+import org.apache.pig.experimental.plan.Operator;
+import org.apache.pig.experimental.plan.OperatorPlan;
+import org.apache.pig.experimental.plan.PlanVisitor;
+
+public class IsNullExpression extends UnaryExpression {
+
+ public IsNullExpression(OperatorPlan plan, byte b, LogicalExpression exp) {
+ super("IsNull", plan, b, exp);
+ }
+
+ @Override
+ public void accept(PlanVisitor v) throws IOException {
+ if (!(v instanceof LogicalExpressionVisitor)) {
+ throw new IOException("Expected LogicalExpressionVisitor");
+ }
+ ((LogicalExpressionVisitor)v).visitIsNull(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;
+ }
+ }
+}
Modified: hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/LogicalExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/LogicalExpression.java?rev=919634&r1=919633&r2=919634&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/LogicalExpression.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/LogicalExpression.java Fri Mar 5 21:55:19 2010
@@ -20,6 +20,7 @@
import java.io.IOException;
+import org.apache.pig.data.DataType;
import org.apache.pig.experimental.logical.relational.LogicalRelationalOperator;
import org.apache.pig.experimental.plan.Operator;
import org.apache.pig.experimental.plan.OperatorPlan;
@@ -94,4 +95,12 @@
public void neverUseForRealSetUid(long uid) {
this.uid = uid;
}
+
+ public String toString() {
+ StringBuilder msg = new StringBuilder();
+
+ msg.append("(Name: " + name + " Type: " + DataType.findTypeName(type) + " Uid: " + uid + ")");
+
+ return msg.toString();
+ }
}
Modified: hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/LogicalExpressionVisitor.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/LogicalExpressionVisitor.java?rev=919634&r1=919633&r2=919634&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/LogicalExpressionVisitor.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/LogicalExpressionVisitor.java Fri Mar 5 21:55:19 2010
@@ -68,4 +68,34 @@
public void visitLessThanEqual(LessThanEqualExpression op) throws IOException {
}
+
+ public void visitNotEqual(NotEqualExpression op) throws IOException {
+ }
+
+ public void visitNot(NotExpression op ) throws IOException {
+ }
+
+ public void visitIsNull(IsNullExpression op) throws IOException {
+ }
+
+ public void visitNegative(NegativeExpression op) throws IOException {
+ }
+
+ public void visitAdd(AddExpression op) throws IOException {
+ }
+
+ public void visitSubtract(SubtractExpression op) throws IOException {
+ }
+
+ public void visitMultiply(MultiplyExpression op) throws IOException {
+ }
+
+ public void visitMod(ModExpression op) throws IOException {
+ }
+
+ public void visitDivide(DivideExpression op) throws IOException {
+ }
+
+ public void visitMapLookup(MapLookupExpression op) throws IOException {
+ }
}
Added: hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/MapLookupExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/MapLookupExpression.java?rev=919634&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/MapLookupExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/MapLookupExpression.java Fri Mar 5 21:55:19 2010
@@ -0,0 +1,93 @@
+/*
+ * 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.experimental.logical.expression;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.pig.experimental.logical.relational.LogicalSchema;
+import org.apache.pig.experimental.logical.relational.LogicalSchema.LogicalFieldSchema;
+import org.apache.pig.experimental.plan.Operator;
+import org.apache.pig.experimental.plan.OperatorPlan;
+import org.apache.pig.experimental.plan.PlanVisitor;
+import org.apache.pig.impl.logicalLayer.ExpressionOperator;
+import org.apache.pig.impl.logicalLayer.LogicalOperator;
+
+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, byte type, String mapKey,
+ LogicalFieldSchema valueSchema ) {
+ super("Map", plan, type);
+ 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).visitMapLookup(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() {
+ return mValueSchema;
+ }
+
+ public String toString() {
+ StringBuilder msg = new StringBuilder();
+
+ msg.append("(Name: " + name + " Type: " + type + " Uid: " + uid + " Key: " + mMapKey + " Schema: " + mValueSchema + ")");
+
+ return msg.toString();
+ }
+}
Added: hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/ModExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/ModExpression.java?rev=919634&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/ModExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/ModExpression.java Fri Mar 5 21:55:19 2010
@@ -0,0 +1,71 @@
+/*
+ * 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.experimental.logical.expression;
+
+import java.io.IOException;
+
+import org.apache.pig.experimental.plan.Operator;
+import org.apache.pig.experimental.plan.OperatorPlan;
+import org.apache.pig.experimental.plan.PlanVisitor;
+
+/**
+ * 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 b this is the type of this expression
+ * @param lhs expression on its left hand side
+ * @param rhs expression on its right hand side
+ */
+ public ModExpression(OperatorPlan plan,
+ byte b,
+ LogicalExpression lhs,
+ LogicalExpression rhs) {
+ super("Mod", plan, b, 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).visitMod(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;
+ }
+ }
+}
Added: hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/MultiplyExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/MultiplyExpression.java?rev=919634&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/MultiplyExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/MultiplyExpression.java Fri Mar 5 21:55:19 2010
@@ -0,0 +1,71 @@
+/*
+ * 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.experimental.logical.expression;
+
+import java.io.IOException;
+
+import org.apache.pig.experimental.plan.Operator;
+import org.apache.pig.experimental.plan.OperatorPlan;
+import org.apache.pig.experimental.plan.PlanVisitor;
+
+/**
+ * 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 b this is the type of this expression
+ * @param lhs expression on its left hand side
+ * @param rhs expression on its right hand side
+ */
+ public MultiplyExpression(OperatorPlan plan,
+ byte b,
+ LogicalExpression lhs,
+ LogicalExpression rhs) {
+ super("Multiply", plan, b, 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).visitMultiply(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;
+ }
+ }
+}
\ No newline at end of file
Added: hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/NegativeExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/NegativeExpression.java?rev=919634&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/NegativeExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/NegativeExpression.java Fri Mar 5 21:55:19 2010
@@ -0,0 +1,54 @@
+/*
+ * 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.experimental.logical.expression;
+
+import java.io.IOException;
+
+import org.apache.pig.experimental.plan.Operator;
+import org.apache.pig.experimental.plan.OperatorPlan;
+import org.apache.pig.experimental.plan.PlanVisitor;
+
+public class NegativeExpression extends UnaryExpression {
+
+ public NegativeExpression(OperatorPlan plan, byte b, LogicalExpression exp) {
+ super("Negative", plan, b, exp);
+ }
+
+ @Override
+ public void accept(PlanVisitor v) throws IOException {
+ if (!(v instanceof LogicalExpressionVisitor)) {
+ throw new IOException("Expected LogicalExpressionVisitor");
+ }
+ ((LogicalExpressionVisitor)v).visitNegative(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;
+ }
+ }
+}
Added: hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/NotEqualExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/NotEqualExpression.java?rev=919634&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/NotEqualExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/NotEqualExpression.java Fri Mar 5 21:55:19 2010
@@ -0,0 +1,72 @@
+/*
+ * 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.experimental.logical.expression;
+
+import java.io.IOException;
+
+import org.apache.pig.data.DataType;
+import org.apache.pig.experimental.plan.Operator;
+import org.apache.pig.experimental.plan.OperatorPlan;
+import org.apache.pig.experimental.plan.PlanVisitor;
+
+/**
+ * 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, DataType.BOOLEAN, 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).visitNotEqual(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;
+ }
+ }
+}
Added: hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/NotExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/NotExpression.java?rev=919634&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/NotExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/NotExpression.java Fri Mar 5 21:55:19 2010
@@ -0,0 +1,54 @@
+/*
+ * 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.experimental.logical.expression;
+
+import java.io.IOException;
+
+import org.apache.pig.experimental.plan.Operator;
+import org.apache.pig.experimental.plan.OperatorPlan;
+import org.apache.pig.experimental.plan.PlanVisitor;
+
+public class NotExpression extends UnaryExpression {
+
+ public NotExpression(OperatorPlan plan, byte b, LogicalExpression exp) {
+ super("Not", plan, b, exp);
+ }
+
+ @Override
+ public void accept(PlanVisitor v) throws IOException {
+ if (!(v instanceof LogicalExpressionVisitor)) {
+ throw new IOException("Expected LogicalExpressionVisitor");
+ }
+ ((LogicalExpressionVisitor)v).visitNot(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;
+ }
+ }
+}
Modified: hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/ProjectExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/ProjectExpression.java?rev=919634&r1=919633&r2=919634&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/ProjectExpression.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/ProjectExpression.java Fri Mar 5 21:55:19 2010
@@ -117,6 +117,10 @@
LogicalSchema schema = referent.getSchema();
if (schema != null) {
uid = schema.getField(col).uid;
+ } else {
+ // If the schema of referent is null, we kindof create a uid so we
+ // can track it in remaining plan
+ uid = getNextUid();
}
}
@@ -150,4 +154,12 @@
return false;
}
}
+
+ public String toString() {
+ StringBuilder msg = new StringBuilder();
+
+ msg.append("(Name: " + name + " Type: " + type + " Uid: " + uid + " Input: " + input + " Column: " + col + ")");
+
+ return msg.toString();
+ }
}
Added: hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/SubtractExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/SubtractExpression.java?rev=919634&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/SubtractExpression.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/experimental/logical/expression/SubtractExpression.java Fri Mar 5 21:55:19 2010
@@ -0,0 +1,71 @@
+/*
+ * 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.experimental.logical.expression;
+
+import java.io.IOException;
+
+import org.apache.pig.experimental.plan.Operator;
+import org.apache.pig.experimental.plan.OperatorPlan;
+import org.apache.pig.experimental.plan.PlanVisitor;
+
+/**
+ * Subtract Operator
+ */
+public class SubtractExpression 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 b this is the type of this expression
+ * @param lhs expression on its left hand side
+ * @param rhs expression on its right hand side
+ */
+ public SubtractExpression(OperatorPlan plan,
+ byte b,
+ LogicalExpression lhs,
+ LogicalExpression rhs) {
+ super("Subtract", plan, b, 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).visitSubtract(this);
+ }
+
+ @Override
+ public boolean isEqual(Operator other) {
+ if (other != null && other instanceof SubtractExpression) {
+ SubtractExpression ao = (SubtractExpression)other;
+ try {
+ return ao.getLhs().isEqual(getLhs()) && ao.getRhs().isEqual(getRhs());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ return false;
+ }
+ }
+}
\ No newline at end of file
Modified: hadoop/pig/trunk/src/org/apache/pig/experimental/logical/optimizer/AllExpressionVisitor.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/experimental/logical/optimizer/AllExpressionVisitor.java?rev=919634&r1=919633&r2=919634&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/experimental/logical/optimizer/AllExpressionVisitor.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/experimental/logical/optimizer/AllExpressionVisitor.java Fri Mar 5 21:55:19 2010
@@ -98,4 +98,14 @@
v.visit();
}
}
+
+ public void visitLOInnerLoad(LOInnerLoad load) throws IOException {
+ // the expression in LOInnerLoad contains info relative from LOForEach
+ // so use LOForeach as currentOp
+ currentOp = load.getLOForEach();
+ LogicalExpressionPlan exp = load.getExpression();
+
+ LogicalExpressionVisitor v = getVisitor(exp);
+ v.visit();
+ }
}
Modified: hadoop/pig/trunk/src/org/apache/pig/experimental/logical/optimizer/AllSameVisitor.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/experimental/logical/optimizer/AllSameVisitor.java?rev=919634&r1=919633&r2=919634&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/experimental/logical/optimizer/AllSameVisitor.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/experimental/logical/optimizer/AllSameVisitor.java Fri Mar 5 21:55:19 2010
@@ -21,6 +21,7 @@
import java.io.IOException;
import org.apache.pig.experimental.logical.relational.LOFilter;
+import org.apache.pig.experimental.logical.relational.LOForEach;
import org.apache.pig.experimental.logical.relational.LOJoin;
import org.apache.pig.experimental.logical.relational.LOLoad;
import org.apache.pig.experimental.logical.relational.LOStore;
@@ -71,4 +72,7 @@
execute(store);
}
+ public void visitLOForEach(LOForEach foreach) throws IOException {
+ execute(foreach);
+ }
}
Modified: hadoop/pig/trunk/src/org/apache/pig/experimental/logical/optimizer/LogicalPlanOptimizer.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/experimental/logical/optimizer/LogicalPlanOptimizer.java?rev=919634&r1=919633&r2=919634&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/experimental/logical/optimizer/LogicalPlanOptimizer.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/experimental/logical/optimizer/LogicalPlanOptimizer.java Fri Mar 5 21:55:19 2010
@@ -73,6 +73,23 @@
// add merge filter rule
r = new MergeFilter("MergeFilter");
s.add(r);
+
+
+ // Prune Set Marker
+ // This set is used for pruning columns and maps
+ // This set only marks the items required for prunning
+ // Next set does the prunning
+// s = new HashSet<Rule>();
+// ls.add(s);
+// // Add the PruneMap Filter
+// r = new PruneMapKeys("PruneMapKeys");
+// s.add(r);
+//
+// s = new HashSet<Rule>();
+// ls.add(s);
+// // Add the Prunner
+// r = new PruneMapKeys("PruneMapKeys");
+// s.add(r);
return ls;