Author: gates
Date: Tue May 13 10:11:43 2008
New Revision: 655950

URL: http://svn.apache.org/viewvc?rev=655950&view=rev
Log:
Shubham's bincond and unary operators patch.


Added:
    
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/topLevelOperators/expressionOperators/POBinCond.java
    
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/topLevelOperators/expressionOperators/unaryExprOps/
    
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/topLevelOperators/expressionOperators/unaryExprOps/PONegative.java
    
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/topLevelOperators/expressionOperators/unaryExprOps/UnaryExpressionOperator.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestPOBinCond.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestPONegative.java
Modified:
    
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/plans/ExprPlanVisitor.java

Modified: 
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/plans/ExprPlanVisitor.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/plans/ExprPlanVisitor.java?rev=655950&r1=655949&r2=655950&view=diff
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/plans/ExprPlanVisitor.java
 (original)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/plans/ExprPlanVisitor.java
 Tue May 13 10:11:43 2008
@@ -21,6 +21,7 @@
 import org.apache.commons.logging.LogFactory;
 import 
org.apache.pig.impl.physicalLayer.topLevelOperators.expressionOperators.ConstantExpression;
 import 
org.apache.pig.impl.physicalLayer.topLevelOperators.expressionOperators.ExpressionOperator;
+import 
org.apache.pig.impl.physicalLayer.topLevelOperators.expressionOperators.POBinCond;
 import 
org.apache.pig.impl.physicalLayer.topLevelOperators.expressionOperators.POProject;
 //import 
org.apache.pig.impl.physicalLayer.topLevelOperators.expressionOperators.binaryExprOps.comparators.EqualToExpr;
 //import 
org.apache.pig.impl.physicalLayer.topLevelOperators.expressionOperators.binaryExprOps.comparators.GTOrEqualToExpr;
@@ -35,6 +36,7 @@
 import 
org.apache.pig.impl.physicalLayer.topLevelOperators.expressionOperators.binaryExprOps.comparators.LTOrEqualToExpr;
 import 
org.apache.pig.impl.physicalLayer.topLevelOperators.expressionOperators.binaryExprOps.comparators.LessThanExpr;
 import 
org.apache.pig.impl.physicalLayer.topLevelOperators.expressionOperators.binaryExprOps.comparators.NotEqualToExpr;
+import 
org.apache.pig.impl.physicalLayer.topLevelOperators.expressionOperators.unaryExprOps.PONegative;
 import org.apache.pig.impl.plan.PlanWalker;
 
 /**
@@ -105,4 +107,14 @@
         //do nothing
     }
 
+       public void visitBinCond(POBinCond binCond) {
+               // do nothing
+               
+       }
+
+       public void visitNegative(PONegative negative) {
+               //do nothing
+               
+       }
+
 }

Added: 
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/topLevelOperators/expressionOperators/POBinCond.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/topLevelOperators/expressionOperators/POBinCond.java?rev=655950&view=auto
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/topLevelOperators/expressionOperators/POBinCond.java
 (added)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/topLevelOperators/expressionOperators/POBinCond.java
 Tue May 13 10:11:43 2008
@@ -0,0 +1,155 @@
+/*
+ * 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.impl.physicalLayer.topLevelOperators.expressionOperators;
+
+import java.util.Map;
+
+import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.data.DataBag;
+import org.apache.pig.data.DataByteArray;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.logicalLayer.OperatorKey;
+import org.apache.pig.impl.physicalLayer.Result;
+import org.apache.pig.impl.physicalLayer.plans.ExprPlan;
+import org.apache.pig.impl.physicalLayer.plans.ExprPlanVisitor;
+import 
org.apache.pig.impl.physicalLayer.topLevelOperators.expressionOperators.ExpressionOperator;
+import org.apache.pig.impl.plan.VisitorException;
+
+public class POBinCond extends ExpressionOperator {
+       ExpressionOperator cond;
+       ExpressionOperator lhs;
+       ExpressionOperator rhs;
+       
+       public POBinCond(OperatorKey k) {
+               super(k);
+               // TODO Auto-generated constructor stub
+       }
+       
+       public POBinCond(OperatorKey k, int rp) {
+               super(k, rp);
+       }
+       
+       public POBinCond(OperatorKey k, int rp, ExpressionOperator cond, 
ExpressionOperator lhs, ExpressionOperator rhs) {
+               super(k, rp);
+               this.cond = cond;
+               this.lhs = lhs;
+               this.rhs = rhs;
+       }
+       
+       /*private Result getNext() throws ExecException {
+               
+               Result res = cond.processInput();
+               return ((Boolean)res.result) == true ? lhs.processInput() : 
rhs.processInput();
+       }*/
+
+       @Override
+       public Result getNext(Boolean b) throws ExecException {
+               Result res = cond.getNext(b);
+               return ((Boolean)res.result) == true ? lhs.getNext(b) : 
rhs.getNext(b);
+               
+       }
+
+       @Override
+       public Result getNext(DataBag db) throws ExecException {
+               Result res = cond.getNext(db);
+               return ((Boolean)res.result) == true ? lhs.getNext(db) : 
rhs.getNext(db);
+       }
+
+       @Override
+       public Result getNext(DataByteArray ba) throws ExecException {
+               Result res = cond.getNext(ba);
+               return ((Boolean)res.result) == true ? lhs.getNext(ba) : 
rhs.getNext(ba);
+       }
+
+       @Override
+       public Result getNext(Double d) throws ExecException {
+               Result res = cond.getNext(d);
+               return ((Boolean)res.result) == true ? lhs.getNext(d) : 
rhs.getNext(d);
+       }
+
+       @Override
+       public Result getNext(Float f) throws ExecException {
+               Result res = cond.getNext(f);
+               return ((Boolean)res.result) == true ? lhs.getNext(f) : 
rhs.getNext(f);
+       }
+
+       @Override
+       public Result getNext(Integer i) throws ExecException {
+               Result res = cond.getNext(i);
+               return ((Boolean)res.result) == true ? lhs.getNext(i) : 
rhs.getNext(i);
+       }
+
+       @Override
+       public Result getNext(Long l) throws ExecException {
+               Result res = cond.getNext(l);
+               return ((Boolean)res.result) == true ? lhs.getNext(l) : 
rhs.getNext(l);
+       }
+
+       @Override
+       public Result getNext(Map m) throws ExecException {
+               Result res = cond.getNext(m);
+               return ((Boolean)res.result) == true ? lhs.getNext(m) : 
rhs.getNext(m);
+       }
+
+       @Override
+       public Result getNext(String s) throws ExecException {
+               Result res = cond.getNext(s);
+               return ((Boolean)res.result) == true ? lhs.getNext(s) : 
rhs.getNext(s);
+       }
+
+       @Override
+       public Result getNext(Tuple t) throws ExecException {
+               Result res = cond.getNext(t);
+               return ((Boolean)res.result) == true ? lhs.getNext(t) : 
rhs.getNext(t);
+       }
+
+       @Override
+       public void visit(ExprPlanVisitor v) throws VisitorException {
+               v.visitBinCond(this);
+       }
+
+       @Override
+       public String name() {
+               return "POBinCond - " + mKey.toString();
+       }
+       
+       @Override
+       public void attachInput(Tuple t) {
+               cond.attachInput(t);
+               lhs.attachInput(t);
+               rhs.attachInput(t);
+       }
+       
+       public void setCond(ExpressionOperator condOp) {
+               this.cond = condOp;
+       }
+       
+       public void setRhs(ExpressionOperator rhs) {
+               this.rhs = rhs;
+       }
+       
+       public void setLhs(ExpressionOperator lhs) {
+               this.lhs = lhs;
+       }
+
+       @Override
+       public boolean supportsMultipleInputs() {
+               return true;
+       }
+
+}

Added: 
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/topLevelOperators/expressionOperators/unaryExprOps/PONegative.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/topLevelOperators/expressionOperators/unaryExprOps/PONegative.java?rev=655950&view=auto
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/topLevelOperators/expressionOperators/unaryExprOps/PONegative.java
 (added)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/topLevelOperators/expressionOperators/unaryExprOps/PONegative.java
 Tue May 13 10:11:43 2008
@@ -0,0 +1,98 @@
+/*
+ * 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.impl.physicalLayer.topLevelOperators.expressionOperators.unaryExprOps;
+
+import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.impl.logicalLayer.OperatorKey;
+import org.apache.pig.impl.physicalLayer.POStatus;
+import org.apache.pig.impl.physicalLayer.Result;
+import org.apache.pig.impl.physicalLayer.plans.ExprPlanVisitor;
+import 
org.apache.pig.impl.physicalLayer.topLevelOperators.expressionOperators.ExpressionOperator;
+import org.apache.pig.impl.plan.VisitorException;
+
+public class PONegative extends UnaryExpressionOperator {
+
+       public PONegative(OperatorKey k, int rp) {
+               super(k, rp);
+               
+       }
+
+       public PONegative(OperatorKey k) {
+               super(k);
+               
+       }
+       
+       public PONegative(OperatorKey k, int rp, ExpressionOperator input) {
+               super(k, rp);
+               this.input = input;
+       }
+
+       @Override
+       public void visit(ExprPlanVisitor v) throws VisitorException {
+               v.visitNegative(this);
+       }
+
+       @Override
+       public String name() {
+               // TODO Auto-generated method stub
+               return "PONegative - " + mKey.toString();
+       }
+
+       @Override
+       public Result getNext(Double d) throws ExecException {
+               Result res = input.getNext(d);
+               if(res.returnStatus == POStatus.STATUS_OK) {
+                       res.result = -1*((Double)res.result);
+               }
+               return res;
+       }
+
+       @Override
+       public Result getNext(Float f) throws ExecException {
+               Result res = input.getNext(f);
+               if(res.returnStatus == POStatus.STATUS_OK) {
+                       res.result = -1*((Float)res.result);
+               }
+               return res;
+       }
+
+       @Override
+       public Result getNext(Integer i) throws ExecException {
+               Result res = input.getNext(i);
+               if(res.returnStatus == POStatus.STATUS_OK) {
+                       res.result = -1*((Integer)res.result);
+               }
+               return res;
+       }
+
+       @Override
+       public Result getNext(Long l) throws ExecException {
+               Result res = input.getNext(l);
+               if(res.returnStatus == POStatus.STATUS_OK) {
+                       res.result = -1*((Long)res.result);
+               }
+               return res;
+       }
+       
+       public void setInput(ExpressionOperator in) {
+               this.input = in;
+       }
+       
+       
+
+}

Added: 
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/topLevelOperators/expressionOperators/unaryExprOps/UnaryExpressionOperator.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/topLevelOperators/expressionOperators/unaryExprOps/UnaryExpressionOperator.java?rev=655950&view=auto
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/topLevelOperators/expressionOperators/unaryExprOps/UnaryExpressionOperator.java
 (added)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/topLevelOperators/expressionOperators/unaryExprOps/UnaryExpressionOperator.java
 Tue May 13 10:11:43 2008
@@ -0,0 +1,47 @@
+/*
+ * 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.impl.physicalLayer.topLevelOperators.expressionOperators.unaryExprOps;
+
+import org.apache.pig.impl.logicalLayer.OperatorKey;
+import org.apache.pig.impl.physicalLayer.plans.ExprPlanVisitor;
+import 
org.apache.pig.impl.physicalLayer.topLevelOperators.expressionOperators.ExpressionOperator;
+import org.apache.pig.impl.plan.VisitorException;
+
+public abstract class UnaryExpressionOperator extends ExpressionOperator {
+
+       ExpressionOperator input;
+       
+       public UnaryExpressionOperator(OperatorKey k, int rp) {
+               super(k, rp);
+               
+       }
+
+       public UnaryExpressionOperator(OperatorKey k) {
+               super(k);
+               
+       }
+
+       @Override
+       public boolean supportsMultipleInputs() {
+               // TODO Auto-generated method stub
+               return false;
+       }
+       
+       
+
+}

Added: incubator/pig/branches/types/test/org/apache/pig/test/TestPOBinCond.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/test/org/apache/pig/test/TestPOBinCond.java?rev=655950&view=auto
==============================================================================
--- incubator/pig/branches/types/test/org/apache/pig/test/TestPOBinCond.java 
(added)
+++ incubator/pig/branches/types/test/org/apache/pig/test/TestPOBinCond.java 
Tue May 13 10:11:43 2008
@@ -0,0 +1,107 @@
+/*
+ * 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.test;
+
+import java.util.Iterator;
+import java.util.Random;
+
+import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.data.BagFactory;
+import org.apache.pig.data.DataBag;
+import org.apache.pig.data.DataType;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.TupleFactory;
+import org.apache.pig.impl.logicalLayer.OperatorKey;
+import org.apache.pig.impl.physicalLayer.plans.ExprPlan;
+import 
org.apache.pig.impl.physicalLayer.topLevelOperators.expressionOperators.ConstantExpression;
+import 
org.apache.pig.impl.physicalLayer.topLevelOperators.expressionOperators.ExpressionOperator;
+import 
org.apache.pig.impl.physicalLayer.topLevelOperators.expressionOperators.POBinCond;
+import 
org.apache.pig.impl.physicalLayer.topLevelOperators.expressionOperators.POProject;
+import 
org.apache.pig.impl.physicalLayer.topLevelOperators.expressionOperators.binaryExprOps.comparators.EqualToExpr;
+import org.apache.pig.impl.plan.PlanException;
+import org.apache.pig.test.utils.GenPhyOp;
+import org.junit.Before;
+
+import junit.framework.TestCase;
+
+public class TestPOBinCond extends TestCase {
+       Random r = new Random();
+       DataBag bag = BagFactory.getInstance().newDefaultBag();
+       final int MAX = 10;
+       
+       @Before
+       @Override
+       public void setUp() {
+               for(int i = 0; i < 10; i ++) {
+                       Tuple t = TupleFactory.getInstance().newTuple();
+                       t.append(r.nextInt(2));
+                       t.append(0);
+                       t.append(1);
+                       bag.add(t);
+               }
+       }
+       
+       public void testPOBinCond() throws ExecException, PlanException {
+               ConstantExpression rt = (ConstantExpression) 
GenPhyOp.exprConst();
+               rt.setValue(1);
+               rt.setResultType(DataType.INTEGER);
+               
+               POProject prj1 = GenPhyOp.exprProject();
+               prj1.setColumn(0);
+               prj1.setResultType(DataType.INTEGER);
+               
+               EqualToExpr equal = (EqualToExpr) GenPhyOp.compEqualToExpr();
+               equal.setLhs(prj1);
+               equal.setRhs(rt);
+               
+               POProject prjLhs = GenPhyOp.exprProject();
+               prjLhs.setResultType(DataType.INTEGER);
+               prjLhs.setColumn(1);
+               
+               POProject prjRhs = GenPhyOp.exprProject();
+               prjRhs.setResultType(DataType.INTEGER);
+               prjRhs.setColumn(2);
+               
+               POBinCond op = new POBinCond(new OperatorKey("", r.nextLong()), 
-1, equal, prjLhs, prjRhs);
+               op.setResultType(DataType.INTEGER);
+               
+               ExprPlan plan = new ExprPlan();
+               plan.add(op);
+               plan.add(prjLhs);
+               plan.add(prjRhs);
+               plan.add(equal);
+               plan.connect(equal, op);
+               plan.connect(prjLhs, op);
+               plan.connect(prjRhs, op);
+               
+               plan.add(prj1);
+               plan.add(rt);
+               plan.connect(prj1, equal);
+               plan.connect(rt, equal);
+               
+               for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+                       Tuple t = it.next();
+                       plan.attachInput(t);
+                       Integer i = (Integer) t.get(0);
+                       assertEquals(1, i | (Integer)op.getNext(i).result);
+//                     System.out.println(t + " " + 
op.getNext(i).result.toString());
+               }
+               
+               
+       }
+}

Added: incubator/pig/branches/types/test/org/apache/pig/test/TestPONegative.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/test/org/apache/pig/test/TestPONegative.java?rev=655950&view=auto
==============================================================================
--- incubator/pig/branches/types/test/org/apache/pig/test/TestPONegative.java 
(added)
+++ incubator/pig/branches/types/test/org/apache/pig/test/TestPONegative.java 
Tue May 13 10:11:43 2008
@@ -0,0 +1,148 @@
+/*
+ * 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.test;
+
+import java.util.Iterator;
+import java.util.Random;
+
+import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.data.BagFactory;
+import org.apache.pig.data.DataBag;
+import org.apache.pig.data.DataType;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.TupleFactory;
+import org.apache.pig.impl.logicalLayer.OperatorKey;
+import org.apache.pig.impl.physicalLayer.plans.ExprPlan;
+import 
org.apache.pig.impl.physicalLayer.topLevelOperators.expressionOperators.POProject;
+import 
org.apache.pig.impl.physicalLayer.topLevelOperators.expressionOperators.unaryExprOps.PONegative;
+import org.apache.pig.impl.plan.PlanException;
+import org.junit.Before;
+
+import junit.framework.TestCase;
+
+public class TestPONegative extends TestCase {
+       
+       DataBag bag = BagFactory.getInstance().newDefaultBag();
+       Random r = new Random();
+       TupleFactory tf = TupleFactory.getInstance();
+       final int MAX = 10;
+       
+       public void testPONegInt () throws PlanException, ExecException {
+               for(int i = 0; i < MAX; i++) {
+                       Tuple t = tf.newTuple();
+                       t.append(r.nextInt());
+                       bag.add(t);
+               }
+               
+               POProject prj = new POProject(new OperatorKey("", 
r.nextLong()), -1, 0);
+               prj.setResultType(DataType.INTEGER);
+               PONegative pn = new PONegative(new OperatorKey("", 
r.nextLong()), -1, prj);
+               pn.setResultType(DataType.INTEGER);
+               
+               ExprPlan plan = new ExprPlan();
+               plan.add(prj); plan.add(pn);
+               plan.connect(prj, pn);
+               
+               for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+                       Tuple t = it.next();
+                       plan.attachInput(t);
+                       Integer expected = -(Integer)t.get(0);
+                       int output = (Integer) pn.getNext(expected).result;
+                       assertEquals(expected.intValue(), output);
+               }
+               
+       }
+       
+       public void testPONegLong () throws PlanException, ExecException {
+               for(int i = 0; i < MAX; i++) {
+                       Tuple t = tf.newTuple();
+                       t.append(r.nextLong());
+                       bag.add(t);
+               }
+               
+               POProject prj = new POProject(new OperatorKey("", 
r.nextLong()), -1, 0);
+               prj.setResultType(DataType.LONG);
+               PONegative pn = new PONegative(new OperatorKey("", 
r.nextLong()), -1, prj);
+               pn.setResultType(DataType.LONG);
+               
+               ExprPlan plan = new ExprPlan();
+               plan.add(prj); plan.add(pn);
+               plan.connect(prj, pn);
+               
+               for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+                       Tuple t = it.next();
+                       plan.attachInput(t);
+                       Long expected = -(Long)t.get(0);
+                       long output = (Long) pn.getNext(expected).result;
+                       assertEquals(expected.longValue(), output);
+               }
+               
+       }
+       
+       public void testPONegDouble() throws PlanException, ExecException {
+               for(int i = 0; i < MAX; i++) {
+                       Tuple t = tf.newTuple();
+                       t.append(r.nextDouble());
+                       bag.add(t);
+               }
+               
+               POProject prj = new POProject(new OperatorKey("", 
r.nextLong()), -1, 0);
+               prj.setResultType(DataType.DOUBLE);
+               PONegative pn = new PONegative(new OperatorKey("", 
r.nextLong()), -1, prj);
+               pn.setResultType(DataType.DOUBLE);
+               
+               ExprPlan plan = new ExprPlan();
+               plan.add(prj); plan.add(pn);
+               plan.connect(prj, pn);
+               
+               for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+                       Tuple t = it.next();
+                       plan.attachInput(t);
+                       Double expected = -(Double)t.get(0);
+                       double output = (Double) pn.getNext(expected).result;
+                       assertEquals(expected.doubleValue(), output);
+               }
+               
+       }
+       
+       public void testPONegFloat() throws PlanException, ExecException {
+               for(int i = 0; i < MAX; i++) {
+                       Tuple t = tf.newTuple();
+                       t.append(r.nextFloat());
+                       bag.add(t);
+               }
+               
+               POProject prj = new POProject(new OperatorKey("", 
r.nextLong()), -1, 0);
+               prj.setResultType(DataType.FLOAT);
+               PONegative pn = new PONegative(new OperatorKey("", 
r.nextLong()), -1, prj);
+               pn.setResultType(DataType.FLOAT);
+               
+               ExprPlan plan = new ExprPlan();
+               plan.add(prj); plan.add(pn);
+               plan.connect(prj, pn);
+               
+               for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
+                       Tuple t = it.next();
+                       plan.attachInput(t);
+                       Float expected = -(Float)t.get(0);
+                       float output = (Float) pn.getNext(expected).result;
+                       assertEquals(expected.floatValue(), output);
+               }
+               
+       }
+}


Reply via email to