You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by pr...@apache.org on 2010/02/18 23:20:09 UTC
svn commit: r911616 [2/7] - in /hadoop/pig/branches/load-store-redesign: ./
contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/util/
contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/util/
src/org/apach...
Modified: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/ConstantExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/ConstantExpression.java?rev=911616&r1=911615&r2=911616&view=diff
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/ConstantExpression.java (original)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/ConstantExpression.java Thu Feb 18 22:20:07 2010
@@ -18,6 +18,9 @@
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;
@@ -48,9 +51,9 @@
* @link org.apache.pig.experimental.plan.Operator#accept(org.apache.pig.experimental.plan.PlanVisitor)
*/
@Override
- public void accept(PlanVisitor v) {
+ public void accept(PlanVisitor v) throws IOException {
if (!(v instanceof LogicalExpressionVisitor)) {
- throw new RuntimeException("Expected LogicalExpressionVisitor");
+ throw new IOException("Expected LogicalExpressionVisitor");
}
((LogicalExpressionVisitor)v).visitConstant(this);
@@ -63,5 +66,15 @@
public Object getValue() {
return val;
}
-
+
+ @Override
+ public boolean isEqual(Operator other) {
+ if (other != null && other instanceof ConstantExpression) {
+ ConstantExpression co = (ConstantExpression)other;
+ return co.type == type && ( ( co.val == null && val == null )
+ || ( co != null && co.val.equals(val) ) );
+ } else {
+ return false;
+ }
+ }
}
Modified: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/EqualExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/EqualExpression.java?rev=911616&r1=911615&r2=911616&view=diff
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/EqualExpression.java (original)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/EqualExpression.java Thu Feb 18 22:20:07 2010
@@ -18,7 +18,10 @@
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;
@@ -44,12 +47,26 @@
* @link org.apache.pig.experimental.plan.Operator#accept(org.apache.pig.experimental.plan.PlanVisitor)
*/
@Override
- public void accept(PlanVisitor v) {
+ public void accept(PlanVisitor v) throws IOException {
if (!(v instanceof LogicalExpressionVisitor)) {
- throw new RuntimeException(
- "Expected LogicalExpressionVisitor");
+ throw new IOException("Expected LogicalExpressionVisitor");
}
((LogicalExpressionVisitor)v).visitEqual(this);
}
-
+
+ @Override
+ public boolean isEqual(Operator other) {
+ if (other != null && other instanceof EqualExpression) {
+ EqualExpression eo = (EqualExpression)other;
+ try {
+ return eo.getLhs().isEqual(
+ getLhs()) &&
+ eo.getRhs().isEqual(getRhs());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ return false;
+ }
+ }
}
Added: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/ExpToPhyTranslationVisitor.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/ExpToPhyTranslationVisitor.java?rev=911616&view=auto
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/ExpToPhyTranslationVisitor.java (added)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/ExpToPhyTranslationVisitor.java Thu Feb 18 22:20:07 2010
@@ -0,0 +1,391 @@
+/*
+ * 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 java.util.Map;
+import java.util.Stack;
+
+import org.apache.pig.FuncSpec;
+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.BinaryComparisonOperator;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.ConstantExpression;
+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.POAnd;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POCast;
+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.plans.PhysicalPlan;
+import org.apache.pig.data.DataType;
+import org.apache.pig.experimental.logical.relational.LogicalRelationalOperator;
+import org.apache.pig.experimental.plan.DependencyOrderWalker;
+import org.apache.pig.experimental.plan.Operator;
+import org.apache.pig.experimental.plan.OperatorPlan;
+import org.apache.pig.experimental.plan.PlanWalker;
+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;
+
+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;
+ }
+
+ @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)));
+ // 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);
+
+ 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 visitGreaterThan( GreaterThanExpression op ) throws IOException {
+ String scope = DEFAULT_SCOPE;
+ BinaryComparisonOperator exprOp = new GreaterThanExpr(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);
+
+ 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 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();
+
+ 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 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();
+
+ 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 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();
+
+ 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 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)));
+ } else {
+ exprOp = new POProject(new OperatorKey(scope, nodeGen
+ .getNextNodeId(scope)));
+ }
+ // We dont have aliases in ExpressionOperators
+ // exprOp.setAlias(op.getAlias());
+ exprOp.setResultType(op.getType());
+ exprOp.setColumn(op.getColNum());
+ // TODO implement this
+// exprOp.setStar(op.isStar());
+// exprOp.setOverloaded(op.getOverloaded());
+ logToPhyMap.put(op, exprOp);
+ currentPlan.add(exprOp);
+
+ // We only have one input so connection is required from only one predecessor
+// PhysicalOperator from = logToPhyMap.get(op.findReferent(currentOp));
+// currentPlan.connect(from, exprOp);
+
+// List<Operator> predecessors = lp.getPredecessors(op);
+//
+// // Project might not have any predecessors
+// if (predecessors == null)
+// return;
+//
+// for (Operator lo : predecessors) {
+// 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 Project");
+ }
+
+ @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)));
+ // 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 visitCast( CastExpression op ) throws IOException {
+ String scope = DEFAULT_SCOPE;
+ POCast pCast = new POCast(new OperatorKey(scope, nodeGen
+ .getNextNodeId(scope)));
+// physOp.setAlias(op.getAlias());
+ currentPlan.add(pCast);
+
+ logToPhyMap.put(op, pCast);
+ ExpressionOperator from = (ExpressionOperator) logToPhyMap.get(op
+ .getExpression());
+ pCast.setResultType(op.getType());
+ 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);
+ }
+ }
+}
Added: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/GreaterThanEqualExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/GreaterThanEqualExpression.java?rev=911616&view=auto
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/GreaterThanEqualExpression.java (added)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/GreaterThanEqualExpression.java Thu Feb 18 22:20:07 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.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;
+
+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, 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).visitGreaterThanEqual(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;
+ }
+ }
+}
Added: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/GreaterThanExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/GreaterThanExpression.java?rev=911616&view=auto
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/GreaterThanExpression.java (added)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/GreaterThanExpression.java Thu Feb 18 22:20:07 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.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;
+
+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, 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).visitGreaterThan(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;
+ }
+ }
+}
Added: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/LessThanEqualExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/LessThanEqualExpression.java?rev=911616&view=auto
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/LessThanEqualExpression.java (added)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/LessThanEqualExpression.java Thu Feb 18 22:20:07 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.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;
+
+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, 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).visitLessThanEqual(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;
+ }
+ }
+}
Added: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/LessThanExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/LessThanExpression.java?rev=911616&view=auto
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/LessThanExpression.java (added)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/LessThanExpression.java Thu Feb 18 22:20:07 2010
@@ -0,0 +1,67 @@
+/*
+ * 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;
+
+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, 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).visitLessThan(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;
+ }
+ }
+
+}
Modified: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/LogicalExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/LogicalExpression.java?rev=911616&r1=911615&r2=911616&view=diff
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/LogicalExpression.java (original)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/LogicalExpression.java Thu Feb 18 22:20:07 2010
@@ -18,6 +18,9 @@
package org.apache.pig.experimental.logical.expression;
+import java.io.IOException;
+
+import org.apache.pig.experimental.logical.relational.LogicalRelationalOperator;
import org.apache.pig.experimental.plan.Operator;
import org.apache.pig.experimental.plan.OperatorPlan;
@@ -28,9 +31,19 @@
*/
public abstract class LogicalExpression extends Operator {
+ static long nextUid = 1;
protected byte type;
- protected long uid;
+ protected long uid = -1;
+ 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
@@ -55,15 +68,30 @@
* @return unique identifier
*/
public long getUid() {
+ if (uid == -1) {
+ throw new RuntimeException("getUid called before uid set");
+ }
return uid;
}
/**
- * Set the unique identify for this expression
- * @param uid unique identifier
+ * Set the uid. For most expressions this will get a new uid.
+ * ProjectExpression needs to override this and find its uid from its
+ * predecessor.
+ * @param currentOp Current LogicalRelationalOperator that this expression operator
+ * is attached to. Passed so that projection operators can determine their uid.
+ * @throws IOException
*/
- public void setUid(long uid) {
- this.uid = uid;
+ public void setUid(LogicalRelationalOperator currentOp) throws IOException {
+ uid = getNextUid();
+ }
+
+ /**
+ * Hard code the uid. This should only be used in testing, never in real
+ * code.
+ * @param uid value to set uid to
+ */
+ public void neverUseForRealSetUid(long uid) {
+ this.uid = uid;
}
-
}
Modified: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/LogicalExpressionPlan.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/LogicalExpressionPlan.java?rev=911616&r1=911615&r2=911616&view=diff
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/LogicalExpressionPlan.java (original)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/LogicalExpressionPlan.java Thu Feb 18 22:20:07 2010
@@ -18,11 +18,30 @@
package org.apache.pig.experimental.logical.expression;
+import java.util.List;
+
import org.apache.pig.experimental.plan.BaseOperatorPlan;
+import org.apache.pig.experimental.plan.Operator;
+import org.apache.pig.experimental.plan.OperatorPlan;
/**
* 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;
+ }
+ }
}
Modified: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/LogicalExpressionVisitor.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/LogicalExpressionVisitor.java?rev=911616&r1=911615&r2=911616&view=diff
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/LogicalExpressionVisitor.java (original)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/LogicalExpressionVisitor.java Thu Feb 18 22:20:07 2010
@@ -18,6 +18,7 @@
package org.apache.pig.experimental.logical.expression;
+import java.io.IOException;
import org.apache.pig.experimental.plan.OperatorPlan;
import org.apache.pig.experimental.plan.PlanVisitor;
import org.apache.pig.experimental.plan.PlanWalker;
@@ -38,18 +39,33 @@
}
}
- public void visitAnd(AndExpression andExpr) {
+ public void visitAnd(AndExpression andExpr) throws IOException {
+ }
+
+ public void visitOr(OrExpression exp) throws IOException {
}
- public void visitEqual(EqualExpression equal) {
+ public void visitEqual(EqualExpression equal) throws IOException {
}
- public void visitProject(ProjectExpression project) {
+ public void visitProject(ProjectExpression project) throws IOException {
}
- public void visitConstant(ConstantExpression constant) {
+ public void visitConstant(ConstantExpression constant) throws IOException {
}
+ public void visitCast(CastExpression cast) throws IOException {
+ }
+
+ public void visitGreaterThan(GreaterThanExpression greaterThanExpression) throws IOException {
+ }
+ public void visitGreaterThanEqual(GreaterThanEqualExpression op) throws IOException {
+ }
+ public void visitLessThan(LessThanExpression lessThanExpression) throws IOException {
+ }
+
+ public void visitLessThanEqual(LessThanEqualExpression op) throws IOException {
+ }
}
Added: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/OrExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/OrExpression.java?rev=911616&view=auto
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/OrExpression.java (added)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/OrExpression.java Thu Feb 18 22:20:07 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;
+
+/**
+ * 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, 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).visitOr(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;
+ }
+
+ }
+
+}
Modified: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/ProjectExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/ProjectExpression.java?rev=911616&r1=911615&r2=911616&view=diff
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/ProjectExpression.java (original)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/ProjectExpression.java Thu Feb 18 22:20:07 2010
@@ -18,6 +18,12 @@
package org.apache.pig.experimental.logical.expression;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.pig.experimental.logical.relational.LogicalRelationalOperator;
+import org.apache.pig.experimental.logical.relational.LogicalSchema;
+import org.apache.pig.experimental.plan.Operator;
import org.apache.pig.experimental.plan.OperatorPlan;
import org.apache.pig.experimental.plan.PlanVisitor;
@@ -58,9 +64,9 @@
* @link org.apache.pig.experimental.plan.Operator#accept(org.apache.pig.experimental.plan.PlanVisitor)
*/
@Override
- public void accept(PlanVisitor v) {
+ public void accept(PlanVisitor v) throws IOException {
if (!(v instanceof LogicalExpressionVisitor)) {
- throw new RuntimeException("Expected LogicalExpressionVisitor");
+ throw new IOException("Expected LogicalExpressionVisitor");
}
((LogicalExpressionVisitor)v).visitProject(this);
@@ -104,4 +110,44 @@
this.type = type;
}
+ @Override
+ public void setUid(LogicalRelationalOperator currentOp) throws IOException {
+ LogicalRelationalOperator referent = findReferent(currentOp);
+
+ LogicalSchema schema = referent.getSchema();
+ if (schema != null) {
+ uid = schema.getField(col).uid;
+ }
+ }
+
+ /**
+ * 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(LogicalRelationalOperator currentOp) throws IOException {
+ List<Operator> preds;
+ preds = currentOp.getPlan().getPredecessors(currentOp);
+ if (preds == null || preds.size() - 1 < input) {
+ 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;
+ }
+ }
}
Added: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/UnaryExpression.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/UnaryExpression.java?rev=911616&view=auto
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/UnaryExpression.java (added)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/expression/UnaryExpression.java Thu Feb 18 22:20:07 2010
@@ -0,0 +1,62 @@
+/*
+ * 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.plan.Operator;
+import org.apache.pig.experimental.plan.OperatorPlan;
+
+/**
+ * Superclass for all unary expressions
+ *
+ */
+public abstract class UnaryExpression extends LogicalExpression {
+
+ /**
+ * Will add this operator to the plan and connect it to the
+ * left and right hand side operators.
+ * @param name of the operator
+ * @param plan plan this operator is part of
+ * @param b Datatype of this expression
+ * @param exp expression that this expression operators on
+ */
+ public UnaryExpression(String name,
+ OperatorPlan plan,
+ byte b,
+ LogicalExpression exp) {
+ super(name, plan, b);
+ plan.add(this);
+ plan.connect(this, exp);
+ }
+
+ /**
+ * Get the expression that this unary expression operators on.
+ * @return expression on the left hand side
+ * @throws IOException
+ */
+ public LogicalExpression getExpression() throws IOException {
+ List<Operator> preds = plan.getSuccessors(this);
+ if(preds == null) {
+ return null;
+ }
+ return (LogicalExpression)preds.get(0);
+ }
+}
Added: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/AllExpressionVisitor.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/AllExpressionVisitor.java?rev=911616&view=auto
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/AllExpressionVisitor.java (added)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/AllExpressionVisitor.java Thu Feb 18 22:20:07 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.experimental.logical.optimizer;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import org.apache.pig.experimental.logical.expression.LogicalExpressionPlan;
+import org.apache.pig.experimental.logical.expression.LogicalExpressionVisitor;
+import org.apache.pig.experimental.logical.relational.LOFilter;
+import org.apache.pig.experimental.logical.relational.LOForEach;
+import org.apache.pig.experimental.logical.relational.LOGenerate;
+import org.apache.pig.experimental.logical.relational.LOInnerLoad;
+import org.apache.pig.experimental.logical.relational.LOJoin;
+import org.apache.pig.experimental.logical.relational.LogicalPlanVisitor;
+import org.apache.pig.experimental.logical.relational.LogicalRelationalOperator;
+import org.apache.pig.experimental.plan.OperatorPlan;
+import org.apache.pig.experimental.plan.PlanWalker;
+
+/**
+ * A visitor that walks a logical plan and then applies a given
+ * LogicalExpressionVisitor to all expressions it encounters.
+ *
+ */
+public abstract class AllExpressionVisitor extends LogicalPlanVisitor {
+
+ protected LogicalExpressionVisitor exprVisitor;
+ protected LogicalRelationalOperator currentOp;
+
+ /**
+ * @param plan LogicalPlan to visit
+ * @param walker Walker to use to visit the plan.
+ */
+ public AllExpressionVisitor(OperatorPlan plan,
+ PlanWalker walker) {
+ super(plan, walker);
+ }
+
+ /**
+ * Get a new instance of the expression visitor to apply to
+ * a given expression.
+ * @param expr LogicalExpressionPlan that will be visited
+ * @return a new LogicalExpressionVisitor for that expression
+ */
+ abstract protected LogicalExpressionVisitor getVisitor(LogicalExpressionPlan expr);
+
+ @Override
+ public void visitLOFilter(LOFilter filter) throws IOException {
+ currentOp = filter;
+ LogicalExpressionVisitor v = getVisitor(filter.getFilterPlan());
+ v.visit();
+ }
+
+ @Override
+ public void visitLOJoin(LOJoin join) throws IOException {
+ currentOp = join;
+ Collection<LogicalExpressionPlan> c = join.getExpressionPlans();
+ for (LogicalExpressionPlan plan : c) {
+ LogicalExpressionVisitor v = getVisitor(plan);
+ v.visit();
+ }
+ }
+
+ @Override
+ public void visitLOForEach(LOForEach foreach) throws IOException {
+ currentOp = foreach;
+ // We have an Inner OperatorPlan in ForEach, so we go ahead
+ // and work on that plan
+ OperatorPlan innerPlan = foreach.getInnerPlan();
+ PlanWalker newWalker = currentWalker.spawnChildWalker(innerPlan);
+ pushWalker(newWalker);
+ currentWalker.walk(this);
+ popWalker();
+ }
+
+ @Override
+ public void visitLOGenerate(LOGenerate gen ) throws IOException {
+ currentOp = gen;
+ Collection<LogicalExpressionPlan> plans = gen.getOutputPlans();
+ for( LogicalExpressionPlan plan : plans ) {
+ LogicalExpressionVisitor v = getVisitor(plan);
+ v.visit();
+ }
+ }
+}
Added: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/AllSameVisitor.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/AllSameVisitor.java?rev=911616&view=auto
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/AllSameVisitor.java (added)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/AllSameVisitor.java Thu Feb 18 22:20:07 2010
@@ -0,0 +1,74 @@
+/*
+ * 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.optimizer;
+
+import java.io.IOException;
+
+import org.apache.pig.experimental.logical.relational.LOFilter;
+import org.apache.pig.experimental.logical.relational.LOJoin;
+import org.apache.pig.experimental.logical.relational.LOLoad;
+import org.apache.pig.experimental.logical.relational.LOStore;
+import org.apache.pig.experimental.logical.relational.LogicalPlanVisitor;
+import org.apache.pig.experimental.logical.relational.LogicalRelationalOperator;
+import org.apache.pig.experimental.plan.OperatorPlan;
+import org.apache.pig.experimental.plan.PlanWalker;
+
+/**
+ * A visitor that walks the logical plan and calls the same method on every
+ * type of node. Subclasses can extend this and implement the execute
+ * method, and this method will be called on every node in the graph.
+ *
+ */
+public abstract class AllSameVisitor extends LogicalPlanVisitor {
+
+ /**
+ * @param plan OperatorPlan to visit
+ * @param walker Walker to use to visit the plan
+ */
+ public AllSameVisitor(OperatorPlan plan, PlanWalker walker) {
+ super(plan, walker);
+ }
+
+ /**
+ * Method to call on every node in the logical plan.
+ * @param op Node that is currently being visited.
+ */
+ abstract protected void execute(LogicalRelationalOperator op) throws IOException;
+
+ @Override
+ public void visitLOFilter(LOFilter filter) throws IOException {
+ execute(filter);
+ }
+
+ @Override
+ public void visitLOJoin(LOJoin join) throws IOException {
+ execute(join);
+ }
+
+ @Override
+ public void visitLOLoad(LOLoad load) throws IOException {
+ execute(load);
+ }
+
+ @Override
+ public void visitLOStore(LOStore store) throws IOException {
+ execute(store);
+ }
+
+}
Added: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/LogicalPlanOptimizer.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/LogicalPlanOptimizer.java?rev=911616&view=auto
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/LogicalPlanOptimizer.java (added)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/LogicalPlanOptimizer.java Thu Feb 18 22:20:07 2010
@@ -0,0 +1,85 @@
+/*
+ * 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.optimizer;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.pig.experimental.logical.rules.FilterAboveForeach;
+import org.apache.pig.experimental.logical.rules.MergeFilter;
+import org.apache.pig.experimental.logical.rules.PushUpFilter;
+import org.apache.pig.experimental.logical.rules.SplitFilter;
+import org.apache.pig.experimental.plan.OperatorPlan;
+import org.apache.pig.experimental.plan.optimizer.PlanOptimizer;
+import org.apache.pig.experimental.plan.optimizer.Rule;
+
+public class LogicalPlanOptimizer extends PlanOptimizer {
+
+ public LogicalPlanOptimizer(OperatorPlan p, int iterations) {
+ super(p, null, iterations);
+ ruleSets = buildRuleSets();
+ addListeners();
+ }
+
+ protected List<Set<Rule>> buildRuleSets() {
+ List<Set<Rule>> ls = new ArrayList<Set<Rule>>();
+
+ // Split Set
+ // This set of rules does splitting of operators only.
+ // It does not move operators
+ Set<Rule> s = new HashSet<Rule>();
+ ls.add(s);
+ // add split filter rule
+ Rule r = new SplitFilter("SplitFilter");
+ s.add(r);
+
+
+
+
+ // Push Set,
+ // This set does moving of operators only.
+ s = new HashSet<Rule>();
+ ls.add(s);
+ // add push up filter rule
+ r = new PushUpFilter("PushUpFilter");
+ s.add(r);
+ r = new FilterAboveForeach("FilterAboveForEachWithFlatten");
+ s.add(r);
+
+
+
+
+ // Merge Set
+ // This Set merges operators but does not move them.
+ s = new HashSet<Rule>();
+ ls.add(s);
+ // add merge filter rule
+ r = new MergeFilter("MergeFilter");
+ s.add(r);
+
+
+ return ls;
+ }
+
+ private void addListeners() {
+ addPlanTransformListener(new SchemaPatcher());
+ addPlanTransformListener(new ProjectionPatcher());
+ }
+}
Added: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/ProjectionPatcher.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/ProjectionPatcher.java?rev=911616&view=auto
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/ProjectionPatcher.java (added)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/ProjectionPatcher.java Thu Feb 18 22:20:07 2010
@@ -0,0 +1,99 @@
+/*
+ * 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.optimizer;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.pig.experimental.logical.expression.LogicalExpressionPlan;
+import org.apache.pig.experimental.logical.expression.LogicalExpressionVisitor;
+import org.apache.pig.experimental.logical.expression.ProjectExpression;
+import org.apache.pig.experimental.logical.relational.LogicalRelationalOperator;
+import org.apache.pig.experimental.logical.relational.LogicalSchema;
+import org.apache.pig.experimental.plan.DepthFirstWalker;
+import org.apache.pig.experimental.plan.Operator;
+import org.apache.pig.experimental.plan.OperatorPlan;
+import org.apache.pig.experimental.plan.optimizer.PlanTransformListener;
+
+/**
+ * A PlanTransformListener that will patch up references in projections.
+ *
+ */
+public class ProjectionPatcher implements PlanTransformListener {
+
+ /**
+ * @link org.apache.pig.experimental.plan.optimizer.PlanTransformListener#transformed(org.apache.pig.experimental.plan.OperatorPlan, org.apache.pig.experimental.plan.OperatorPlan)
+ */
+ @Override
+ public void transformed(OperatorPlan fp, OperatorPlan tp)
+ throws IOException {
+ ProjectionFinder pf = new ProjectionFinder(tp);
+ pf.visit();
+ }
+
+ private static class ProjectionRewriter extends LogicalExpressionVisitor {
+
+ private LogicalRelationalOperator currentOp;
+
+ ProjectionRewriter(OperatorPlan p, LogicalRelationalOperator cop) {
+ super(p, new DepthFirstWalker(p));
+ currentOp = cop;
+ }
+
+ @Override
+ public void visitProject(ProjectExpression p) throws IOException {
+ // Get the uid for this projection. It must match the uid of the
+ // value it is projecting.
+ long myUid = p.getUid();
+
+ // Find the operator this projection references
+ LogicalRelationalOperator pred = p.findReferent(currentOp);
+
+ // Get the schema for this operator and search it for the matching uid
+ int match = -1;
+ LogicalSchema schema = pred.getSchema();
+ List<LogicalSchema.LogicalFieldSchema> fields = schema.getFields();
+ for (int i = 0; i < fields.size(); i++) {
+ if (fields.get(i).uid == myUid) {
+ match = i;
+ break;
+ }
+ }
+ if (match == -1) {
+ throw new IOException("Couldn't find matching uid for project");
+ }
+ p.setColNum(match);
+ }
+
+ }
+
+ private static class ProjectionFinder extends AllExpressionVisitor {
+
+ public ProjectionFinder(OperatorPlan plan) {
+ super(plan, new DepthFirstWalker(plan));
+ }
+
+ @Override
+ protected LogicalExpressionVisitor getVisitor(LogicalExpressionPlan expr) {
+ return new ProjectionRewriter(expr, currentOp);
+ }
+
+ }
+
+}
Added: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/SchemaPatcher.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/SchemaPatcher.java?rev=911616&view=auto
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/SchemaPatcher.java (added)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/SchemaPatcher.java Thu Feb 18 22:20:07 2010
@@ -0,0 +1,63 @@
+/*
+ * 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.optimizer;
+
+import java.io.IOException;
+
+import org.apache.pig.experimental.logical.relational.LogicalRelationalOperator;
+import org.apache.pig.experimental.plan.DependencyOrderWalker;
+import org.apache.pig.experimental.plan.OperatorPlan;
+import org.apache.pig.experimental.plan.optimizer.PlanTransformListener;
+
+/**
+ * A PlanTransformListener for the logical optimizer that will patch up schemas
+ * after a plan has been transformed.
+ *
+ */
+public class SchemaPatcher implements PlanTransformListener {
+
+ /**
+ * @throws IOException
+ * @link org.apache.pig.experimental.plan.optimizer.PlanTransformListener#transformed(org.apache.pig.experimental.plan.OperatorPlan, org.apache.pig.experimental.plan.OperatorPlan)
+ */
+ @Override
+ public void transformed(OperatorPlan fp, OperatorPlan tp) throws IOException {
+ // Walk the transformed plan and clean out the schemas and call
+ // getSchema again on each node. This will cause each node
+ // to regenerate its schema from its parent.
+
+ SchemaVisitor sv = new SchemaVisitor(tp);
+ sv.visit();
+ }
+
+ private static class SchemaVisitor extends AllSameVisitor {
+
+ public SchemaVisitor(OperatorPlan plan) {
+ super(plan, new DependencyOrderWalker(plan));
+ }
+
+ @Override
+ protected void execute(LogicalRelationalOperator op) throws IOException {
+ op.resetSchema();
+ op.getSchema();
+ }
+
+ }
+
+}
Added: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/UidStamper.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/UidStamper.java?rev=911616&view=auto
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/UidStamper.java (added)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/optimizer/UidStamper.java Thu Feb 18 22:20:07 2010
@@ -0,0 +1,138 @@
+/*
+ * 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.optimizer;
+
+import java.io.IOException;
+import java.util.List;
+
+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.EqualExpression;
+import org.apache.pig.experimental.logical.expression.GreaterThanEqualExpression;
+import org.apache.pig.experimental.logical.expression.GreaterThanExpression;
+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.LogicalExpressionVisitor;
+import org.apache.pig.experimental.logical.expression.OrExpression;
+import org.apache.pig.experimental.logical.expression.ProjectExpression;
+import org.apache.pig.experimental.logical.relational.LOLoad;
+import org.apache.pig.experimental.logical.relational.LogicalSchema;
+import org.apache.pig.experimental.logical.relational.LogicalSchema.LogicalFieldSchema;
+import org.apache.pig.experimental.plan.DependencyOrderWalker;
+import org.apache.pig.experimental.plan.DepthFirstWalker;
+import org.apache.pig.experimental.plan.OperatorPlan;
+
+/**
+ * A Visitor to stamp every part of every expression in a tree with a uid.
+ */
+public class UidStamper extends AllExpressionVisitor {
+
+ /**
+ * @param plan LogicalPlan that this stamper will act on.
+ */
+ public UidStamper(OperatorPlan plan) {
+ super(plan, new DependencyOrderWalker(plan));
+ }
+
+ class ExprUidStamper extends LogicalExpressionVisitor {
+ protected ExprUidStamper(OperatorPlan plan) {
+ super(plan, new DepthFirstWalker(plan));
+ }
+
+
+ @Override
+ public void visitAnd(AndExpression andExpr) throws IOException {
+ andExpr.setUid(currentOp);
+ }
+
+ @Override
+ public void visitOr(OrExpression op) throws IOException {
+ op.setUid(currentOp);
+ }
+
+ @Override
+ public void visitEqual(EqualExpression equal) throws IOException {
+ equal.setUid(currentOp);
+ }
+
+ @Override
+ public void visitGreaterThan(GreaterThanExpression greaterThanExpression) throws IOException {
+ greaterThanExpression.setUid(currentOp);
+ }
+
+ @Override
+ public void visitGreaterThanEqual(GreaterThanEqualExpression op) throws IOException {
+ op.setUid(currentOp);
+ }
+
+ @Override
+ public void visitLessThan(LessThanExpression lessThanExpression) throws IOException {
+ lessThanExpression.setUid(currentOp);
+ }
+
+ @Override
+ public void visitLessThanEqual(LessThanEqualExpression op) throws IOException {
+ op.setUid(currentOp);
+ }
+
+ @Override
+ public void visitProject(ProjectExpression project) throws IOException {
+ project.setUid(currentOp);
+ }
+
+ @Override
+ public void visitConstant(ConstantExpression constant) throws IOException {
+ constant.setUid(currentOp);
+ }
+
+ @Override
+ public void visitCast(CastExpression cast) throws IOException {
+ cast.setUid(currentOp);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.pig.experimental.logical.optimizer.AllExpressionVisitor#getVisitor(org.apache.pig.experimental.logical.expression.LogicalExpressionPlan)
+ */
+ @Override
+ protected LogicalExpressionVisitor getVisitor(LogicalExpressionPlan expr) {
+ return new ExprUidStamper(expr);
+ }
+
+ @Override
+ public void visitLOLoad(LOLoad load) throws IOException {
+ super.visitLOLoad(load);
+
+ LogicalSchema s = load.getSchema();
+ stampSchema(s);
+ }
+
+ private void stampSchema(LogicalSchema s) {
+ if (s != null) {
+ List<LogicalFieldSchema> l = s.getFields();
+ for(LogicalFieldSchema f: l) {
+ f.uid = LogicalExpression.getNextUid();
+ stampSchema(f.schema);
+ }
+ }
+ }
+}
Added: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/relational/LOFilter.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/relational/LOFilter.java?rev=911616&view=auto
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/relational/LOFilter.java (added)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/relational/LOFilter.java Thu Feb 18 22:20:07 2010
@@ -0,0 +1,83 @@
+/**
+ * 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.relational;
+
+import java.io.IOException;
+
+//import org.apache.commons.logging.Log;
+//import org.apache.commons.logging.LogFactory;
+import org.apache.pig.experimental.logical.expression.LogicalExpressionPlan;
+import org.apache.pig.experimental.plan.Operator;
+import org.apache.pig.experimental.plan.PlanVisitor;
+
+public class LOFilter extends LogicalRelationalOperator {
+
+ private static final long serialVersionUID = 2L;
+ private LogicalExpressionPlan filterPlan;
+ //private static Log log = LogFactory.getLog(LOFilter.class);
+
+
+ public LOFilter(LogicalPlan plan) {
+ super("LOFilter", plan);
+ }
+
+ public LOFilter(LogicalPlan plan, LogicalExpressionPlan filterPlan) {
+ super("LOFilter", plan);
+ this.filterPlan = filterPlan;
+ }
+
+ public LogicalExpressionPlan getFilterPlan() {
+ return filterPlan;
+ }
+
+ public void setFilterPlan(LogicalExpressionPlan filterPlan) {
+ this.filterPlan = filterPlan;
+ }
+
+ @Override
+ public LogicalSchema getSchema() {
+ LogicalRelationalOperator input = null;
+ try {
+ input = (LogicalRelationalOperator)plan.getPredecessors(this).get(0);
+ }catch(Exception e) {
+ throw new RuntimeException("Unable to get predecessor of LOFilter.", e);
+ }
+
+ schema = input.getSchema();
+ return schema;
+ }
+
+ @Override
+ public void accept(PlanVisitor v) throws IOException {
+ if (!(v instanceof LogicalPlanVisitor)) {
+ throw new IOException("Expected LogicalPlanVisitor");
+ }
+ ((LogicalPlanVisitor)v).visitLOFilter(this);
+ }
+
+ @Override
+ public boolean isEqual(Operator other) {
+ if (other != null && other instanceof LOFilter) {
+ LOFilter of = (LOFilter)other;
+ return filterPlan.isEqual(of.filterPlan) && checkEquality(of);
+ } else {
+ return false;
+ }
+ }
+}
+
Added: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/relational/LOForEach.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/relational/LOForEach.java?rev=911616&view=auto
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/relational/LOForEach.java (added)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/relational/LOForEach.java Thu Feb 18 22:20:07 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.experimental.logical.relational;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.pig.experimental.plan.Operator;
+import org.apache.pig.experimental.plan.OperatorPlan;
+import org.apache.pig.experimental.plan.PlanVisitor;
+
+public class LOForEach extends LogicalRelationalOperator {
+
+ private static final long serialVersionUID = 2L;
+
+ private LogicalPlan innerPlan;
+
+ public LOForEach(OperatorPlan plan) {
+ super("LOForEach", plan);
+ }
+
+ public LogicalPlan getInnerPlan() {
+ return innerPlan;
+ }
+
+ public void setInnerPlan(LogicalPlan p) {
+ innerPlan = p;
+ }
+
+ @Override
+ public boolean isEqual(Operator other) {
+ if (!(other instanceof LOForEach)) {
+ return false;
+ }
+
+ return innerPlan.isEqual(((LOForEach)other).innerPlan);
+ }
+
+ @Override
+ public LogicalSchema getSchema() {
+ if (schema != null) {
+ return schema;
+ }
+
+ List<Operator> ll = innerPlan.getSinks();
+ if (ll != null) {
+ schema = ((LogicalRelationalOperator)ll.get(0)).getSchema();
+ }
+
+ return schema;
+ }
+
+ @Override
+ public void accept(PlanVisitor v) throws IOException {
+ if (!(v instanceof LogicalPlanVisitor)) {
+ throw new IOException("Expected LogicalPlanVisitor");
+ }
+ ((LogicalPlanVisitor)v).visitLOForEach(this);
+ }
+
+}
Added: hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/relational/LOGenerate.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/relational/LOGenerate.java?rev=911616&view=auto
==============================================================================
--- hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/relational/LOGenerate.java (added)
+++ hadoop/pig/branches/load-store-redesign/src/org/apache/pig/experimental/logical/relational/LOGenerate.java Thu Feb 18 22:20:07 2010
@@ -0,0 +1,151 @@
+/*
+ * 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.relational;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.pig.data.DataType;
+import org.apache.pig.experimental.logical.expression.LogicalExpression;
+import org.apache.pig.experimental.logical.expression.LogicalExpressionPlan;
+import org.apache.pig.experimental.logical.expression.ProjectExpression;
+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;
+
+public class LOGenerate extends LogicalRelationalOperator {
+ private List<LogicalExpressionPlan> outputPlans;
+ private boolean[] flattenFlags;
+
+ public LOGenerate(OperatorPlan plan, List<LogicalExpressionPlan> ps, boolean[] flatten) {
+ super("LOGenerate", plan);
+ outputPlans = ps;
+ flattenFlags = flatten;
+ }
+
+ @Override
+ public LogicalSchema getSchema() {
+ if (schema != null) {
+ return schema;
+ }
+
+ schema = new LogicalSchema();
+
+ for(int i=0; i<outputPlans.size(); i++) {
+ LogicalExpression exp = (LogicalExpression)outputPlans.get(i).getSinks().get(0);
+ byte t = exp.getType();
+ LogicalSchema fieldSchema = null;
+ String alias = null;
+
+ // if type is primitive, just add to schema
+ if (t != DataType.TUPLE && t != DataType.BAG) {
+ LogicalFieldSchema f = new LogicalSchema.LogicalFieldSchema(alias, fieldSchema, t, exp.getUid());
+ schema.addField(f);
+ continue;
+ }
+
+ // for tuple and bag type, if there is projection, calculate schema of this field
+ if (exp instanceof ProjectExpression) {
+ LogicalRelationalOperator op = null;
+ try{
+ op = ((ProjectExpression)exp).findReferent(this);
+ }catch(Exception e) {
+ throw new RuntimeException(e);
+ }
+ LogicalSchema s = op.getSchema();
+ if (s != null) {
+ fieldSchema = s.getField(((ProjectExpression)exp).getColNum()).schema;
+ alias = s.getField(((ProjectExpression)exp).getColNum()).alias;
+ }
+ }
+
+ // if flatten is set, set schema of tuple field to this schema
+ if (flattenFlags[i]) {
+ if (t == DataType.BAG) {
+ // if it is bag of tuples, get the schema of tuples
+ if (fieldSchema != null && fieldSchema.size() == 1
+ && fieldSchema.getField(0).type == DataType.TUPLE) {
+
+ fieldSchema = fieldSchema.getField(0).schema;
+ }else {
+ fieldSchema = null;
+ }
+ }
+
+ if (fieldSchema != null) {
+ List<LogicalFieldSchema> ll = fieldSchema.getFields();
+ for(LogicalFieldSchema f: ll) {
+ schema.addField(f);
+ }
+ } else {
+ schema = null;
+ break;
+ }
+ } else {
+ LogicalFieldSchema f = new LogicalSchema.LogicalFieldSchema(alias, fieldSchema, t, exp.getUid());
+ schema.addField(f);
+ }
+ }
+
+ return schema;
+ }
+
+ public List<LogicalExpressionPlan> getOutputPlans() {
+ return outputPlans;
+ }
+
+ public boolean[] getFlattenFlags() {
+ return flattenFlags;
+ }
+
+ @Override
+ public boolean isEqual(Operator other) {
+ if (!(other instanceof LOGenerate)) {
+ return false;
+ }
+
+ List<LogicalExpressionPlan> otherPlan = ((LOGenerate)other).getOutputPlans();
+ boolean[] fs = ((LOGenerate)other).getFlattenFlags();
+
+ if (outputPlans.size() != otherPlan.size()) {
+ return false;
+ }
+
+ for(int i=0; i<outputPlans.size(); i++) {
+ if (flattenFlags[i] != fs[i]) {
+ return false;
+ }
+
+ if (!outputPlans.get(i).isEqual(otherPlan.get(i))) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public void accept(PlanVisitor v) throws IOException {
+ if (!(v instanceof LogicalPlanVisitor)) {
+ throw new IOException("Expected LogicalPlanVisitor");
+ }
+ ((LogicalPlanVisitor)v).visitLOGenerate(this);
+ }
+
+}