You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by ch...@apache.org on 2012/11/08 18:06:50 UTC
svn commit: r1407167 [4/10] - in /pig/trunk: ./ test/org/apache/pig/test/
test/org/apache/pig/test/pigunit/
Modified: pig/trunk/test/org/apache/pig/test/TestFRJoin.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestFRJoin.java?rev=1407167&r1=1407166&r2=1407167&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestFRJoin.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestFRJoin.java Thu Nov 8 17:06:46 2012
@@ -1,14 +1,12 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
- *
+ * 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.
@@ -17,6 +15,9 @@
*/
package org.apache.pig.test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.HashMap;
@@ -24,9 +25,6 @@ import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
import org.apache.pig.EvalFunc;
import org.apache.pig.ExecType;
import org.apache.pig.FuncSpec;
@@ -52,39 +50,34 @@ import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-@RunWith(JUnit4.class)
-public class TestFRJoin extends TestCase{
+public class TestFRJoin {
private static final String INPUT_FILE = "testFrJoinInput.txt";
private static final String INPUT_FILE2 = "testFrJoinInput2.txt";
private PigServer pigServer;
private static MiniCluster cluster = MiniCluster.buildCluster();
-
- public TestFRJoin() throws ExecException, IOException{
+
+ public TestFRJoin() throws ExecException, IOException {
pigServer = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
-// pigServer = new PigServer(ExecType.LOCAL);
-
}
-
+
@Before
public void setUp() throws Exception {
int LOOP_SIZE = 2;
- String[] input = new String[2*LOOP_SIZE];
+ String[] input = new String[2 * LOOP_SIZE];
int k = 0;
for(int i = 1; i <= LOOP_SIZE; i++) {
String si = i + "";
- for(int j=1;j<=LOOP_SIZE;j++)
+ for (int j = 1; j <= LOOP_SIZE; j++)
input[k++] = si + "\t" + j;
}
Util.createInputFile(cluster, INPUT_FILE, input);
-
- String[] input2 = new String[2*(LOOP_SIZE/2)];
+
+ String[] input2 = new String[2 * (LOOP_SIZE / 2)];
k = 0;
- for(int i = 1; i <= LOOP_SIZE/2; i++) {
+ for (int i = 1; i <= LOOP_SIZE / 2; i++) {
String si = i + "";
- for(int j=1;j<=LOOP_SIZE/2;j++)
+ for (int j = 1; j <= LOOP_SIZE / 2; j++)
input2[k++] = si + "\t" + j;
}
Util.createInputFile(cluster, INPUT_FILE2, input2);
@@ -94,323 +87,334 @@ public class TestFRJoin extends TestCase
public static void oneTimeTearDown() throws Exception {
cluster.shutDown();
}
-
+
@After
public void tearDown() throws Exception {
Util.deleteFile(cluster, INPUT_FILE);
- Util.deleteFile(cluster, INPUT_FILE2 );
+ Util.deleteFile(cluster, INPUT_FILE2);
}
-
- public static class FRJoin extends EvalFunc<DataBag>{
+
+ public static class FRJoin extends EvalFunc<DataBag> {
String repl;
int keyField;
boolean isTblSetUp = false;
Hashtable<String, DataBag> replTbl = new Hashtable<String, DataBag>();
-
- public FRJoin(){
-
+
+ public FRJoin() {
}
- public FRJoin(String repl){
+
+ public FRJoin(String repl) {
this.repl = repl;
}
@Override
public DataBag exec(Tuple input) throws IOException {
- if(!isTblSetUp){
+ if (!isTblSetUp) {
setUpHashTable();
isTblSetUp = true;
}
- try {
- String key = (String) input.get(keyField);
- if(!replTbl.containsKey(key)) return BagFactory.getInstance().newDefaultBag();
- return replTbl.get(key);
- } catch (ExecException e) {
- throw new IOException(e.getMessage());
- }
-
+ String key = (String)input.get(keyField);
+ if (!replTbl.containsKey(key))
+ return BagFactory.getInstance().newDefaultBag();
+ return replTbl.get(key);
}
-
+
private void setUpHashTable() throws IOException {
- FileSpec replFile = new FileSpec(repl,new FuncSpec(PigStorage.class.getName()+"()"));
+ FileSpec replFile = new FileSpec(repl, new FuncSpec(PigStorage.class.getName() + "()"));
POLoad ld = new POLoad(new OperatorKey("Repl File Loader", 1L), replFile);
PigContext pc = new PigContext(ExecType.MAPREDUCE, PigMapReduce.sJobConfInternal.get());
- try {
- pc.connect();
-
- ld.setPc(pc);
- Tuple dummyTuple = null;
- for(Result res=ld.getNext(dummyTuple);res.returnStatus!=POStatus.STATUS_EOP;res=ld.getNext(dummyTuple)){
- Tuple tup = (Tuple) res.result;
- LoadFunc lf = ((LoadFunc)pc.instantiateFuncFromSpec(ld.getLFile().getFuncSpec()));
- String key = lf.getLoadCaster().bytesToCharArray(((DataByteArray)tup.get(keyField)).get());
- Tuple csttup = TupleFactory.getInstance().newTuple(2);
- csttup.set(0, key);
- csttup.set(1, lf.getLoadCaster().bytesToInteger(((DataByteArray)tup.get(1)).get()));
- DataBag vals = null;
- if(replTbl.containsKey(key)){
- vals = replTbl.get(key);
- }
- else{
- vals = BagFactory.getInstance().newDefaultBag();
- replTbl.put(key, vals);
- }
- vals.add(csttup);
+ pc.connect();
+
+ ld.setPc(pc);
+ Tuple dummyTuple = null;
+ for (Result res = ld.getNext(dummyTuple); res.returnStatus != POStatus.STATUS_EOP; res = ld
+ .getNext(dummyTuple)) {
+ Tuple tup = (Tuple)res.result;
+ LoadFunc lf = ((LoadFunc)pc.instantiateFuncFromSpec(ld.getLFile().getFuncSpec()));
+ String key = lf.getLoadCaster().bytesToCharArray(
+ ((DataByteArray)tup.get(keyField)).get());
+ Tuple csttup = TupleFactory.getInstance().newTuple(2);
+ csttup.set(0, key);
+ csttup.set(1, lf.getLoadCaster().bytesToInteger(((DataByteArray)tup.get(1)).get()));
+ DataBag vals = null;
+ if (replTbl.containsKey(key)) {
+ vals = replTbl.get(key);
+ }
+ else {
+ vals = BagFactory.getInstance().newDefaultBag();
+ replTbl.put(key, vals);
}
- } catch (ExecException e) {
- throw new IOException(e.getMessage());
+ vals.add(csttup);
}
}
-
+
}
-
+
@Test
- public void testSortFRJoin() throws IOException{
- pigServer.registerQuery("A = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
- pigServer.registerQuery("B = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
- pigServer.registerQuery("D = ORDER A by y;");
- pigServer.registerQuery("E = ORDER B by y;");
- DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance().newDefaultBag();
- {
- pigServer.registerQuery("C = join D by $0, E by $0 using \'replicated\';");
- Iterator<Tuple> iter = pigServer.openIterator("C");
-
- while(iter.hasNext()) {
- dbfrj.add(iter.next());
- }
- }
- {
- pigServer.registerQuery("C = join D by $0, E by $0;");
- Iterator<Tuple> iter = pigServer.openIterator("C");
-
- while(iter.hasNext()) {
- dbshj.add(iter.next());
- }
- }
- Assert.assertEquals(dbfrj.size(), dbshj.size());
- Assert.assertEquals(true, TestHelper.compareBags(dbfrj, dbshj));
+ public void testSortFRJoin() throws IOException {
+ pigServer.registerQuery("A = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
+ pigServer.registerQuery("B = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
+ pigServer.registerQuery("D = ORDER A by y;");
+ pigServer.registerQuery("E = ORDER B by y;");
+ DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance()
+ .newDefaultBag();
+ {
+ pigServer.registerQuery("C = join D by $0, E by $0 using \'replicated\';");
+ Iterator<Tuple> iter = pigServer.openIterator("C");
+
+ while (iter.hasNext()) {
+ dbfrj.add(iter.next());
+ }
+ }
+ {
+ pigServer.registerQuery("C = join D by $0, E by $0;");
+ Iterator<Tuple> iter = pigServer.openIterator("C");
+
+ while (iter.hasNext()) {
+ dbshj.add(iter.next());
+ }
+ }
+ assertEquals(dbfrj.size(), dbshj.size());
+ assertTrue(TestHelper.compareBags(dbfrj, dbshj));
}
-
+
@Test
- public void testDistinctFRJoin() throws IOException{
+ public void testDistinctFRJoin() throws IOException {
pigServer.registerQuery("A = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
pigServer.registerQuery("B = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
pigServer.registerQuery("D = distinct A ;");
pigServer.registerQuery("E = distinct B ;");
- DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance().newDefaultBag();
+ DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance()
+ .newDefaultBag();
{
pigServer.registerQuery("C = join D by $0, E by $0 using 'replicated';");
Iterator<Tuple> iter = pigServer.openIterator("C");
-
- while(iter.hasNext()) {
+
+ while (iter.hasNext()) {
dbfrj.add(iter.next());
}
}
{
pigServer.registerQuery("C = join D by $0, E by $0;");
Iterator<Tuple> iter = pigServer.openIterator("C");
-
- while(iter.hasNext()) {
+
+ while (iter.hasNext()) {
dbshj.add(iter.next());
}
}
- Assert.assertEquals(dbfrj.size(), dbshj.size());
- Assert.assertEquals(true, TestHelper.compareBags(dbfrj, dbshj));
+ assertEquals(dbfrj.size(), dbshj.size());
+ assertTrue(TestHelper.compareBags(dbfrj, dbshj));
}
-
+
@Test
public void testUDFFRJ() throws IOException {
pigServer.registerQuery("A = LOAD '" + INPUT_FILE + "' as (x:chararray,y:int);");
pigServer.registerQuery("B = LOAD '" + INPUT_FILE + "' as (x:chararray,y:int);");
-
- DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance().newDefaultBag();
+
+ DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance()
+ .newDefaultBag();
{
- String fSpec = FRJoin.class.getName()+ "('" + INPUT_FILE + "')";
+ String fSpec = FRJoin.class.getName() + "('" + INPUT_FILE + "')";
pigServer.registerFunction("FRJ", new FuncSpec(fSpec));
pigServer.registerQuery("C = foreach A generate *, flatten(FRJ(*));");
Iterator<Tuple> iter = pigServer.openIterator("C");
-
- while(iter.hasNext()) {
+
+ while (iter.hasNext()) {
dbfrj.add(iter.next());
}
}
{
pigServer.registerQuery("C = join A by $0, B by $0;");
Iterator<Tuple> iter = pigServer.openIterator("C");
-
- while(iter.hasNext()) {
+
+ while (iter.hasNext()) {
dbshj.add(iter.next());
}
}
- Assert.assertTrue(dbfrj.size()>0 && dbshj.size()>0);
- Assert.assertEquals(true, TestHelper.compareBags(dbfrj, dbshj));
+ assertTrue(dbfrj.size() > 0);
+ assertTrue(dbshj.size() > 0);
+ assertTrue(TestHelper.compareBags(dbfrj, dbshj));
}
-
+
@Test
- public void testFRJoinOut1() throws IOException{
+ public void testFRJoinOut1() throws IOException {
pigServer.registerQuery("A = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
pigServer.registerQuery("B = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
- DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance().newDefaultBag();
+ DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance()
+ .newDefaultBag();
{
pigServer.registerQuery("C = join A by $0, B by $0 using 'replicated';");
Iterator<Tuple> iter = pigServer.openIterator("C");
-
- while(iter.hasNext()) {
+
+ while (iter.hasNext()) {
dbfrj.add(iter.next());
}
}
{
pigServer.registerQuery("C = join A by $0, B by $0;");
Iterator<Tuple> iter = pigServer.openIterator("C");
-
- while(iter.hasNext()) {
+
+ while (iter.hasNext()) {
dbshj.add(iter.next());
}
}
- Assert.assertTrue(dbfrj.size()>0 && dbshj.size()>0);
- Assert.assertEquals(true, TestHelper.compareBags(dbfrj, dbshj));
+ assertTrue(dbfrj.size() > 0);
+ assertTrue(dbshj.size() > 0);
+ assertTrue(TestHelper.compareBags(dbfrj, dbshj));
}
-
+
@Test
- public void testFRJoinOut2() throws IOException{
+ public void testFRJoinOut2() throws IOException {
pigServer.registerQuery("A = LOAD '" + INPUT_FILE + "';");
pigServer.registerQuery("B = LOAD '" + INPUT_FILE + "';");
- DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance().newDefaultBag();
+ DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance()
+ .newDefaultBag();
{
pigServer.registerQuery("C = join A by $0, B by $0 using 'replicated';");
Iterator<Tuple> iter = pigServer.openIterator("C");
-
- while(iter.hasNext()) {
+
+ while (iter.hasNext()) {
dbfrj.add(iter.next());
}
}
{
pigServer.registerQuery("C = join A by $0, B by $0;");
Iterator<Tuple> iter = pigServer.openIterator("C");
-
- while(iter.hasNext()) {
+
+ while (iter.hasNext()) {
dbshj.add(iter.next());
}
}
- Assert.assertTrue(dbfrj.size()>0 && dbshj.size()>0);
- Assert.assertEquals(true, TestHelper.compareBags(dbfrj, dbshj));
+ assertTrue(dbfrj.size() > 0);
+ assertTrue(dbshj.size() > 0);
+ assertTrue(TestHelper.compareBags(dbfrj, dbshj));
}
-
+
@Test
- public void testFRJoinOut3() throws IOException{
+ public void testFRJoinOut3() throws IOException {
pigServer.registerQuery("A = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
pigServer.registerQuery("B = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
pigServer.registerQuery("C = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
- DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance().newDefaultBag();
+ DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance()
+ .newDefaultBag();
{
pigServer.registerQuery("D = join A by $0, B by $0, C by $0 using 'replicated';");
Iterator<Tuple> iter = pigServer.openIterator("D");
-
- while(iter.hasNext()) {
+
+ while (iter.hasNext()) {
dbfrj.add(iter.next());
}
}
{
pigServer.registerQuery("D = join A by $0, B by $0, C by $0;");
Iterator<Tuple> iter = pigServer.openIterator("D");
-
- while(iter.hasNext()) {
+
+ while (iter.hasNext()) {
dbshj.add(iter.next());
}
}
- Assert.assertTrue(dbfrj.size()>0 && dbshj.size()>0);
- Assert.assertEquals(true, TestHelper.compareBags(dbfrj, dbshj));
+ assertTrue(dbfrj.size() > 0);
+ assertTrue(dbshj.size() > 0);
+ assertTrue(TestHelper.compareBags(dbfrj, dbshj));
}
-
+
@Test
- public void testFRJoinOut4() throws IOException{
+ public void testFRJoinOut4() throws IOException {
pigServer.registerQuery("A = LOAD '" + INPUT_FILE + "';");
pigServer.registerQuery("B = LOAD '" + INPUT_FILE + "';");
pigServer.registerQuery("C = LOAD '" + INPUT_FILE + "';");
- DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance().newDefaultBag();
+ DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance()
+ .newDefaultBag();
{
pigServer.registerQuery("D = join A by $0, B by $0, C by $0 using 'replicated';");
Iterator<Tuple> iter = pigServer.openIterator("D");
-
- while(iter.hasNext()) {
+
+ while (iter.hasNext()) {
dbfrj.add(iter.next());
}
}
{
pigServer.registerQuery("D = join A by $0, B by $0, C by $0;");
Iterator<Tuple> iter = pigServer.openIterator("D");
-
- while(iter.hasNext()) {
+
+ while (iter.hasNext()) {
dbshj.add(iter.next());
}
}
- Assert.assertTrue(dbfrj.size()>0 && dbshj.size()>0);
- Assert.assertEquals(true, TestHelper.compareBags(dbfrj, dbshj));
+ assertTrue(dbfrj.size() > 0);
+ assertTrue(dbshj.size() > 0);
+ assertTrue(TestHelper.compareBags(dbfrj, dbshj));
}
-
-
+
+
@Test
- public void testFRJoinOut5() throws IOException{
+ public void testFRJoinOut5() throws IOException {
pigServer.registerQuery("A = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
pigServer.registerQuery("B = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
- DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance().newDefaultBag();
+ DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance()
+ .newDefaultBag();
{
pigServer.registerQuery("C = join A by ($0,$1), B by ($0,$1) using 'replicated';");
Iterator<Tuple> iter = pigServer.openIterator("C");
-
- while(iter.hasNext()) {
+
+ while (iter.hasNext()) {
dbfrj.add(iter.next());
}
}
{
pigServer.registerQuery("C = join A by ($0,$1), B by ($0,$1);");
Iterator<Tuple> iter = pigServer.openIterator("C");
-
- while(iter.hasNext()) {
+
+ while (iter.hasNext()) {
dbshj.add(iter.next());
}
}
- Assert.assertTrue(dbfrj.size()>0 && dbshj.size()>0);
- Assert.assertEquals(true, TestHelper.compareBags(dbfrj, dbshj));
+ assertTrue(dbfrj.size() > 0);
+ assertTrue(dbshj.size() > 0);
+ assertTrue(TestHelper.compareBags(dbfrj, dbshj));
}
-
+
@Test
- public void testFRJoinOut6() throws IOException{
+ public void testFRJoinOut6() throws IOException {
pigServer.registerQuery("A = LOAD '" + INPUT_FILE + "';");
pigServer.registerQuery("B = LOAD '" + INPUT_FILE + "';");
- DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance().newDefaultBag();
+ DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance()
+ .newDefaultBag();
{
pigServer.registerQuery("C = join A by ($0,$1), B by ($0,$1) using 'replicated';");
Iterator<Tuple> iter = pigServer.openIterator("C");
-
- while(iter.hasNext()) {
+
+ while (iter.hasNext()) {
dbfrj.add(iter.next());
}
}
{
pigServer.registerQuery("C = join A by ($0,$1), B by ($0,$1);");
Iterator<Tuple> iter = pigServer.openIterator("C");
-
- while(iter.hasNext()) {
+
+ while (iter.hasNext()) {
dbshj.add(iter.next());
}
}
- Assert.assertTrue(dbfrj.size()>0 && dbshj.size()>0);
- Assert.assertEquals(true, TestHelper.compareBags(dbfrj, dbshj));
+ assertTrue(dbfrj.size() > 0);
+ assertTrue(dbshj.size() > 0);
+ assertTrue(TestHelper.compareBags(dbfrj, dbshj));
}
-
+
@Test
- public void testFRJoinOut7() throws IOException{
+ public void testFRJoinOut7() throws IOException {
pigServer.registerQuery("A = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
pigServer.registerQuery("B = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
- DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance().newDefaultBag();
+ DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance()
+ .newDefaultBag();
{
pigServer.registerQuery("C = join A by $0, B by $0 using 'replicated';");
pigServer.registerQuery("D = join A by $1, B by $1 using 'replicated';");
pigServer.registerQuery("E = union C,D;");
Iterator<Tuple> iter = pigServer.openIterator("E");
-
- while(iter.hasNext()) {
+
+ while (iter.hasNext()) {
dbfrj.add(iter.next());
}
}
@@ -419,34 +423,36 @@ public class TestFRJoin extends TestCase
pigServer.registerQuery("D = join A by $1, B by $1;");
pigServer.registerQuery("E = union C,D;");
Iterator<Tuple> iter = pigServer.openIterator("E");
-
- while(iter.hasNext()) {
+
+ while (iter.hasNext()) {
dbshj.add(iter.next());
}
}
- Assert.assertTrue(dbfrj.size()>0 && dbshj.size()>0);
- Assert.assertEquals(true, TestHelper.compareBags(dbfrj, dbshj));
+ assertTrue(dbfrj.size() > 0);
+ assertTrue(dbshj.size() > 0);
+ assertTrue(TestHelper.compareBags(dbfrj, dbshj));
}
@Test
public void testFRJoinOut8() throws IOException {
pigServer.registerQuery("A = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
pigServer.registerQuery("B = LOAD '" + INPUT_FILE2 + "' as (x:int,y:int);");
- DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance().newDefaultBag();
- Map<String,Tuple> hashFRJoin = new HashMap<String,Tuple>();
- Map<String,Tuple> hashJoin = new HashMap<String,Tuple>();
+ DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance()
+ .newDefaultBag();
+ Map<String, Tuple> hashFRJoin = new HashMap<String, Tuple>();
+ Map<String, Tuple> hashJoin = new HashMap<String, Tuple>();
{
pigServer.registerQuery("C = join A by $0 left, B by $0 using 'replicated';");
pigServer.registerQuery("D = join A by $1 left, B by $1 using 'replicated';");
pigServer.registerQuery("E = union C,D;");
Iterator<Tuple> iter = pigServer.openIterator("E");
-
- while(iter.hasNext()) {
+
+ while (iter.hasNext()) {
Tuple tuple = iter.next();
String Key = tuple.toDelimitedString(",");
- hashFRJoin.put( Key, tuple);
+ hashFRJoin.put(Key, tuple);
dbfrj.add(tuple);
-
+
}
}
{
@@ -454,37 +460,38 @@ public class TestFRJoin extends TestCase
pigServer.registerQuery("D = join A by $1 left, B by $1;");
pigServer.registerQuery("E = union C,D;");
Iterator<Tuple> iter = pigServer.openIterator("E");
- while(iter.hasNext()) {
+ while (iter.hasNext()) {
Tuple tuple = iter.next();
String Key = tuple.toDelimitedString(",");
- hashJoin.put( Key, tuple);
+ hashJoin.put(Key, tuple);
dbshj.add(tuple);
}
}
- Assert.assertTrue(dbfrj.size()>0 && dbshj.size()>0);
-
- Assert.assertEquals(true, TestHelper.compareBags(dbfrj, dbshj));
+ assertTrue(dbfrj.size() > 0);
+ assertTrue(dbshj.size() > 0);
+ assertTrue(TestHelper.compareBags(dbfrj, dbshj));
}
-
+
@Test
public void testFRJoinOut9() throws IOException {
pigServer.registerQuery("A = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
pigServer.registerQuery("B = LOAD '" + INPUT_FILE2 + "' as (x:int,y:int);");
- DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance().newDefaultBag();
- Map<String,Tuple> hashFRJoin = new HashMap<String,Tuple>();
- Map<String,Tuple> hashJoin = new HashMap<String,Tuple>();
+ DataBag dbfrj = BagFactory.getInstance().newDefaultBag(), dbshj = BagFactory.getInstance()
+ .newDefaultBag();
+ Map<String, Tuple> hashFRJoin = new HashMap<String, Tuple>();
+ Map<String, Tuple> hashJoin = new HashMap<String, Tuple>();
{
pigServer.registerQuery("C = join A by $0 left, B by $0 using 'repl';");
pigServer.registerQuery("D = join A by $1 left, B by $1 using 'repl';");
pigServer.registerQuery("E = union C,D;");
Iterator<Tuple> iter = pigServer.openIterator("E");
-
- while(iter.hasNext()) {
+
+ while (iter.hasNext()) {
Tuple tuple = iter.next();
String Key = tuple.toDelimitedString(",");
- hashFRJoin.put( Key, tuple);
+ hashFRJoin.put(Key, tuple);
dbfrj.add(tuple);
-
+
}
}
{
@@ -492,19 +499,20 @@ public class TestFRJoin extends TestCase
pigServer.registerQuery("D = join A by $1 left, B by $1;");
pigServer.registerQuery("E = union C,D;");
Iterator<Tuple> iter = pigServer.openIterator("E");
- while(iter.hasNext()) {
+ while (iter.hasNext()) {
Tuple tuple = iter.next();
String Key = tuple.toDelimitedString(",");
- hashJoin.put( Key, tuple);
+ hashJoin.put(Key, tuple);
dbshj.add(tuple);
}
}
- Assert.assertTrue(dbfrj.size()>0 && dbshj.size()>0);
- Assert.assertEquals(true, TestHelper.compareBags(dbfrj, dbshj));
+ assertTrue(dbfrj.size() > 0);
+ assertTrue(dbshj.size() > 0);
+ assertTrue(TestHelper.compareBags(dbfrj, dbshj));
}
-
+
@Test
- public void testFRJoinSch1() throws IOException{
+ public void testFRJoinSch1() throws IOException {
pigServer.registerQuery("A = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
pigServer.registerQuery("B = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
Schema frjSch = null, shjSch = null;
@@ -512,11 +520,11 @@ public class TestFRJoin extends TestCase
frjSch = pigServer.dumpSchema("C");
pigServer.registerQuery("C = join A by $0, B by $0;");
shjSch = pigServer.dumpSchema("C");
- Assert.assertEquals(true, shjSch.equals(frjSch));
+ assertEquals(shjSch, frjSch);
}
-
+
@Test
- public void testFRJoinSch2() throws IOException{
+ public void testFRJoinSch2() throws IOException {
pigServer.registerQuery("A = LOAD '" + INPUT_FILE + "';");
pigServer.registerQuery("B = LOAD '" + INPUT_FILE + "';");
Schema frjSch = null, shjSch = null;
@@ -524,11 +532,11 @@ public class TestFRJoin extends TestCase
frjSch = pigServer.dumpSchema("C");
pigServer.registerQuery("C = join A by $0, B by $0;");
shjSch = pigServer.dumpSchema("C");
- Assert.assertTrue(shjSch == null);
+ assertNull(shjSch);
}
-
+
@Test
- public void testFRJoinSch3() throws IOException{
+ public void testFRJoinSch3() throws IOException {
pigServer.registerQuery("A = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
pigServer.registerQuery("B = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
pigServer.registerQuery("C = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
@@ -537,11 +545,11 @@ public class TestFRJoin extends TestCase
frjSch = pigServer.dumpSchema("D");
pigServer.registerQuery("D = join A by $0, B by $0, C by $0;");
shjSch = pigServer.dumpSchema("D");
- Assert.assertEquals(true, shjSch.equals(frjSch));
+ assertEquals(shjSch, frjSch);
}
-
+
@Test
- public void testFRJoinSch4() throws IOException{
+ public void testFRJoinSch4() throws IOException {
pigServer.registerQuery("A = LOAD '" + INPUT_FILE + "';");
pigServer.registerQuery("B = LOAD '" + INPUT_FILE + "';");
pigServer.registerQuery("C = LOAD '" + INPUT_FILE + "';");
@@ -550,11 +558,11 @@ public class TestFRJoin extends TestCase
frjSch = pigServer.dumpSchema("D");
pigServer.registerQuery("D = join A by $0, B by $0, C by $0;");
shjSch = pigServer.dumpSchema("D");
- Assert.assertTrue(shjSch == null);
+ assertNull(shjSch);
}
-
+
@Test
- public void testFRJoinSch5() throws IOException{
+ public void testFRJoinSch5() throws IOException {
pigServer.registerQuery("A = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
pigServer.registerQuery("B = LOAD '" + INPUT_FILE + "' as (x:int,y:int);");
Schema frjSch = null, shjSch = null;
@@ -562,11 +570,11 @@ public class TestFRJoin extends TestCase
frjSch = pigServer.dumpSchema("C");
pigServer.registerQuery("C = join A by ($0,$1), B by ($0,$1);");
shjSch = pigServer.dumpSchema("C");
- Assert.assertEquals(true, shjSch.equals(frjSch));
+ assertEquals(shjSch, frjSch);
}
-
+
@Test
- public void testFRJoinSch6() throws IOException{
+ public void testFRJoinSch6() throws IOException {
pigServer.registerQuery("A = LOAD '" + INPUT_FILE + "';");
pigServer.registerQuery("B = LOAD '" + INPUT_FILE + "';");
Schema frjSch = null, shjSch = null;
@@ -574,6 +582,7 @@ public class TestFRJoin extends TestCase
frjSch = pigServer.dumpSchema("C");
pigServer.registerQuery("C = join A by ($0,$1), B by ($0,$1);");
shjSch = pigServer.dumpSchema("C");
- Assert.assertTrue(shjSch == null);
+ assertNull(shjSch);
}
}
+
Modified: pig/trunk/test/org/apache/pig/test/TestFilter.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestFilter.java?rev=1407167&r1=1407166&r2=1407167&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestFilter.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestFilter.java Thu Nov 8 17:06:46 2012
@@ -1,14 +1,12 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
- *
+ * 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.
@@ -17,54 +15,55 @@
*/
package org.apache.pig.test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.POStatus;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.PhysicalOperator;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.Result;
+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.GreaterThanExpr;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POAnd;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POProject;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhysicalPlan;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POFilter;
import org.apache.pig.data.BagFactory;
import org.apache.pig.data.DataBag;
import org.apache.pig.data.DataType;
import org.apache.pig.data.DefaultTuple;
import org.apache.pig.data.Tuple;
import org.apache.pig.data.TupleFactory;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.PhysicalOperator;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.POStatus;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.Result;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhysicalPlan;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POFilter;
-import org.apache.pig.test.PORead;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.*;
import org.apache.pig.test.utils.GenPhyOp;
import org.apache.pig.test.utils.GenRandomData;
import org.apache.pig.test.utils.TestHelper;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-public class TestFilter extends junit.framework.TestCase {
+public class TestFilter {
+ Random r = new Random(42L);
POFilter pass;
-
POFilter fail;
-
Tuple t;
-
DataBag inp;
-
POFilter projFil;
boolean[] nullFlags = new boolean[] { false, true };
-
+
@Before
public void setUp() throws Exception {
pass = GenPhyOp.topFilterOpWithExPlan(50, 25);
fail = GenPhyOp.topFilterOpWithExPlan(25, 50);
}
- private void setUpProjFil(boolean withNulls) throws Exception{
- Random r = new Random();
- if(withNulls)
+ private void setUpProjFil(boolean withNulls) throws Exception {
+ if (withNulls)
inp = GenRandomData.genRandSmallTupDataBagWithNulls(r, 10, 100);
else
inp = GenRandomData.genRandSmallTupDataBag(r, 10, 100);
@@ -81,10 +80,6 @@ public class TestFilter extends junit.fr
inputs.add(inpPrj);
projFil.setInputs(inputs);
}
-
- @After
- public void tearDown() throws Exception {
- }
@Test
public void testGetNextTuple() throws Exception {
@@ -104,59 +99,63 @@ public class TestFilter extends junit.fr
break;
count++;
assertEquals(POStatus.STATUS_OK, res.returnStatus);
- Tuple output = (Tuple) res.result;
- assertEquals("Running testGetNextTuple with nullFlags set to "+ nullFlags[i] + ":", true, TestHelper.bagContains(inp, output));
- assertEquals("Running testGetNextTuple with nullFlags set to "+ nullFlags[i] + ":", true, (Integer) ((Tuple) res.result).get(1) > 50);
+ Tuple output = (Tuple)res.result;
+ assertEquals(
+ "Running testGetNextTuple with nullFlags set to " + nullFlags[i] + ":",
+ true, TestHelper.bagContains(inp, output));
+ assertEquals(
+ "Running testGetNextTuple with nullFlags set to " + nullFlags[i] + ":",
+ true, (Integer)((Tuple)res.result).get(1) > 50);
}
- assertEquals("Running testGetNextTuple with nullFlags set to "+ nullFlags[i] + ":", getExpCount(inp), count);
-
+ assertEquals("Running testGetNextTuple with nullFlags set to " + nullFlags[i] + ":",
+ getExpCount(inp), count);
+
}
}
/**
* @param inp2
* @return
- * @throws ExecException
+ * @throws ExecException
*/
private int getExpCount(DataBag inp2) throws ExecException {
// TODO Auto-generated method stub
int count = 0;
- for(Iterator<Tuple> it = inp2.iterator(); it.hasNext();){
-
+ for (Iterator<Tuple> it = inp2.iterator(); it.hasNext();) {
+
Tuple t = it.next();
- if(t.get(1) != null && (Integer)t.get(1) > 50)
+ if (t.get(1) != null && (Integer)t.get(1) > 50)
count++;
}
-
+
return count;
}
@Test
public void testSimpleFilter() throws Exception {
for (int i = 0; i < nullFlags.length; i++) {
-
// Build the inner expression
POProject p1 = GenPhyOp.exprProject(0);
POProject p2 = GenPhyOp.exprProject(1);
GreaterThanExpr gt = GenPhyOp.compGreaterThanExpr(p1, p2, DataType.INTEGER);
-
+
PhysicalPlan ip = new PhysicalPlan();
ip.add(p1);
ip.add(p2);
ip.add(gt);
ip.connect(p1, gt);
ip.connect(p2, gt);
-
- int[] ints = {0, 1, 1, 0, 1, 1};
+
+ int[] ints = { 0, 1, 1, 0, 1, 1 };
TupleFactory tf = TupleFactory.getInstance();
DataBag inbag = BagFactory.getInstance().newDefaultBag();
Random r = new Random();
- for (int j = 0; j < ints.length; j+=2) {
+ for (int j = 0; j < ints.length; j += 2) {
// if we are testing with nulls
// introduce nulls randomly
- if(nullFlags[i] == true) {
+ if (nullFlags[i] == true) {
int rand = r.nextInt(100);
- if(rand <= 20) {
+ if (rand <= 20) {
Tuple t = tf.newTuple(2);
t.set(0, new Integer(ints[j]));
t.set(1, null);
@@ -164,7 +163,7 @@ public class TestFilter extends junit.fr
} else if (rand > 20 && rand <= 40) {
Tuple t = tf.newTuple(2);
t.set(0, null);
- t.set(1, new Integer(ints[j+1]));
+ t.set(1, new Integer(ints[j + 1]));
inbag.add(t);
} else if (rand > 40 && rand <= 60) {
Tuple t = tf.newTuple(2);
@@ -175,19 +174,19 @@ public class TestFilter extends junit.fr
}
Tuple t = tf.newTuple(2);
t.set(0, new Integer(ints[j]));
- t.set(1, new Integer(ints[j+1]));
+ t.set(1, new Integer(ints[j + 1]));
inbag.add(t);
}
-
+
PORead read = GenPhyOp.topReadOp(inbag);
POFilter filter = GenPhyOp.connectedFilterOp(read);
filter.setPlan(ip);
-
+
PhysicalPlan op = new PhysicalPlan();
op.add(filter);
op.add(read);
op.connect(read, filter);
-
+
DataBag outbag = BagFactory.getInstance().newDefaultBag();
Result res;
Tuple t = tf.newTuple();
@@ -197,37 +196,44 @@ public class TestFilter extends junit.fr
outbag.add((Tuple)res.result);
}
} while (res.returnStatus == POStatus.STATUS_OK);
- assertEquals("Running " + this.getName() + "with nullFlags set to "+ nullFlags[i] + ":", POStatus.STATUS_EOP, res.returnStatus);
- assertEquals("Running " + this.getName() + "with nullFlags set to "+ nullFlags[i] + ":", 1, outbag.size());
+ assertEquals("Running " + this.getClass().getName() + "with nullFlags set to "
+ + nullFlags[i] + ":", POStatus.STATUS_EOP, res.returnStatus);
+ assertEquals("Running " + this.getClass().getName() + "with nullFlags set to "
+ + nullFlags[i] + ":", 1, outbag.size());
Iterator<Tuple> it = outbag.iterator();
- assertTrue("Running " + this.getName() + "with nullFlags set to "+ nullFlags[i] + ":", it.hasNext());
+ assertTrue("Running " + this.getClass().getName() + "with nullFlags set to "
+ + nullFlags[i] + ":", it.hasNext());
t = it.next();
- assertEquals("Running " + this.getName() + "with nullFlags set to "+ nullFlags[i] + ":", 2, t.size());
- assertTrue("Running " + this.getName() + "with nullFlags set to "+ nullFlags[i] + ":", t.get(0) instanceof Integer);
- assertTrue("Running " + this.getName() + "with nullFlags set to "+ nullFlags[i] + ":", t.get(1) instanceof Integer);
+ assertEquals("Running " + this.getClass().getName() + "with nullFlags set to "
+ + nullFlags[i] + ":", 2, t.size());
+ assertTrue("Running " + this.getClass().getName() + "with nullFlags set to "
+ + nullFlags[i] + ":", t.get(0) instanceof Integer);
+ assertTrue("Running " + this.getClass().getName() + "with nullFlags set to "
+ + nullFlags[i] + ":", t.get(1) instanceof Integer);
Integer i1 = (Integer)t.get(0);
Integer i2 = (Integer)t.get(1);
- assertEquals("Running " + this.getName() + "with nullFlags set to "+ nullFlags[i] + ":", 1, (int)i1);
- assertEquals("Running " + this.getName() + "with nullFlags set to "+ nullFlags[i] + ":", 0, (int)i2);
+ assertEquals("Running " + this.getClass().getName() + "with nullFlags set to "
+ + nullFlags[i] + ":", 1, (int)i1);
+ assertEquals("Running " + this.getClass().getName() + "with nullFlags set to "
+ + nullFlags[i] + ":", 0, (int)i2);
}
}
@Test
public void testAndFilter() throws Exception {
-
for (int i = 0; i < nullFlags.length; i++) {
// Build the inner expression
POProject p1 = GenPhyOp.exprProject(0);
ConstantExpression c2 = GenPhyOp.exprConst();
c2.setValue(new Integer(0));
GreaterThanExpr gt = GenPhyOp.compGreaterThanExpr(p1, c2, DataType.INTEGER);
-
+
POProject p3 = GenPhyOp.exprProject(1);
ConstantExpression c = GenPhyOp.exprConst();
c.setValue(new Integer(1));
EqualToExpr eq = GenPhyOp.compEqualToExpr(p3, c, DataType.INTEGER);
POAnd and = GenPhyOp.compAndExpr(gt, eq);
-
+
PhysicalPlan ip = new PhysicalPlan();
ip.add(p1);
ip.add(c2);
@@ -242,17 +248,17 @@ public class TestFilter extends junit.fr
ip.connect(c, eq);
ip.connect(eq, and);
ip.connect(gt, and);
-
- int[] ints = {0, 1, 1, 0, 1, 1};
+
+ int[] ints = { 0, 1, 1, 0, 1, 1 };
TupleFactory tf = TupleFactory.getInstance();
DataBag inbag = BagFactory.getInstance().newDefaultBag();
Random r = new Random();
- for (int j = 0; j < ints.length; j+=2) {
+ for (int j = 0; j < ints.length; j += 2) {
// if we are testing with nulls
// introduce nulls randomly
- if(nullFlags[i] == true) {
+ if (nullFlags[i] == true) {
int rand = r.nextInt(100);
- if(rand <= 20) {
+ if (rand <= 20) {
Tuple t = tf.newTuple(2);
t.set(0, new Integer(ints[j]));
t.set(1, null);
@@ -260,7 +266,7 @@ public class TestFilter extends junit.fr
} else if (rand > 20 && rand <= 40) {
Tuple t = tf.newTuple(2);
t.set(0, null);
- t.set(1, new Integer(ints[j+1]));
+ t.set(1, new Integer(ints[j + 1]));
inbag.add(t);
} else if (rand > 40 && rand <= 60) {
Tuple t = tf.newTuple(2);
@@ -271,19 +277,19 @@ public class TestFilter extends junit.fr
}
Tuple t = tf.newTuple(2);
t.set(0, new Integer(ints[j]));
- t.set(1, new Integer(ints[j+1]));
+ t.set(1, new Integer(ints[j + 1]));
inbag.add(t);
}
-
+
PORead read = GenPhyOp.topReadOp(inbag);
POFilter filter = GenPhyOp.connectedFilterOp(read);
filter.setPlan(ip);
-
+
PhysicalPlan op = new PhysicalPlan();
op.add(filter);
op.add(read);
op.connect(read, filter);
-
+
DataBag outbag = BagFactory.getInstance().newDefaultBag();
Result res;
Tuple t = tf.newTuple();
@@ -307,13 +313,4 @@ public class TestFilter extends junit.fr
assertEquals(1, (int)i2);
}
}
-
- public static void main(String[] args) {
- TestFilter tf = new TestFilter();
- try {
- tf.testAndFilter();
- } catch (Exception e) {
- System.out.println("Caught exception: " + e.getMessage());
- }
- }
-}
+}
\ No newline at end of file
Modified: pig/trunk/test/org/apache/pig/test/TestFilterUDF.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestFilterUDF.java?rev=1407167&r1=1407166&r2=1407167&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestFilterUDF.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestFilterUDF.java Thu Nov 8 17:06:46 2012
@@ -1,14 +1,12 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
- *
+ * 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.
@@ -17,8 +15,9 @@
*/
package org.apache.pig.test;
-
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileOutputStream;
@@ -27,47 +26,42 @@ import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Iterator;
-import junit.framework.TestCase;
-
import org.apache.pig.EvalFunc;
import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
import org.apache.pig.backend.executionengine.ExecException;
import org.apache.pig.data.Tuple;
import org.apache.pig.data.TupleFactory;
-import org.apache.pig.impl.io.FileLocalizer;
import org.apache.pig.test.utils.FILTERFROMFILE;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
public class TestFilterUDF {
private PigServer pigServer;
private static MiniCluster cluster = MiniCluster.buildCluster();
private File tmpFile;
-
+
TupleFactory tf = TupleFactory.getInstance();
- public TestFilterUDF() throws ExecException, IOException{
+ public TestFilterUDF() throws ExecException, IOException {
int LOOP_SIZE = 20;
tmpFile = File.createTempFile("test", "txt");
PrintStream ps = new PrintStream(new FileOutputStream(tmpFile));
- for(int i = 1; i <= LOOP_SIZE; i++) {
+ for (int i = 1; i <= LOOP_SIZE; i++) {
ps.println(i);
}
ps.close();
}
-
+
@Before
public void setUp() throws Exception {
pigServer = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
int LOOP_SIZE = 20;
tmpFile = File.createTempFile("test", "txt");
PrintStream ps = new PrintStream(new FileOutputStream(tmpFile));
- for(int i = 1; i <= LOOP_SIZE; i++) {
+ for (int i = 1; i <= LOOP_SIZE; i++) {
ps.println(i);
}
ps.close();
@@ -77,29 +71,29 @@ public class TestFilterUDF {
public void tearDown() throws Exception {
tmpFile.delete();
}
-
+
@AfterClass
public static void oneTimeTearDown() throws Exception {
cluster.shutDown();
}
-
- private File createFile(String[] data) throws Exception{
+
+ private File createFile(String[] data) throws Exception {
File f = File.createTempFile("tmp", "");
PrintWriter pw = new PrintWriter(f);
- for (int i=0; i<data.length; i++){
+ for (int i = 0; i < data.length; i++) {
pw.println(data[i]);
}
pw.close();
return f;
}
-
- static public class MyFilterFunction extends EvalFunc<Boolean>{
+
+ static public class MyFilterFunction extends EvalFunc<Boolean> {
@Override
public Boolean exec(Tuple input) throws IOException {
try {
int col = (Integer)input.get(0);
- if(col>10)
+ if (col > 10)
return true;
} catch (ExecException e) {
// TODO Auto-generated catch block
@@ -107,42 +101,42 @@ public class TestFilterUDF {
}
return false;
}
-
+
}
-
+
@Test
- public void testFilterUDF() throws Exception{
-
- pigServer.registerQuery("A = LOAD '"
- + Util.generateURI(tmpFile.toString(), pigServer.getPigContext())
+ public void testFilterUDF() throws Exception {
+
+ pigServer.registerQuery("A = LOAD '"
+ + Util.generateURI(tmpFile.toString(), pigServer.getPigContext())
+ "' as (x:int);");
pigServer.registerQuery("B = filter A by " + MyFilterFunction.class.getName() + "($0);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- if(!iter.hasNext()) fail("No Output received");
+ assertTrue("No Output received", iter.hasNext());
int cnt = 0;
- while(iter.hasNext()){
+ while (iter.hasNext()) {
Tuple t = iter.next();
- assertEquals(true,(Integer)t.get(0)>10);
+ assertEquals(true, (Integer)t.get(0) > 10);
++cnt;
}
assertEquals(10, cnt);
}
@Test
- public void testFilterUDFusingDefine() throws Exception{
- File inputFile= createFile(
- new String[]{
- "www.paulisageek.com\t4",
- "www.yahoo.com\t12344",
- "google.com\t1",
- "us2.amazon.com\t4141"
- }
+ public void testFilterUDFusingDefine() throws Exception {
+ File inputFile = createFile(
+ new String[] {
+ "www.paulisageek.com\t4",
+ "www.yahoo.com\t12344",
+ "google.com\t1",
+ "us2.amazon.com\t4141"
+ }
);
File filterFile = createFile(
- new String[]{
- "12344"
- }
+ new String[] {
+ "12344"
+ }
);
pigServer.registerQuery("define FILTER_CRITERION "
@@ -161,27 +155,27 @@ public class TestFilterUDF {
expectedTuple.append(new Integer("12344"));
Iterator<Tuple> iter = pigServer.openIterator("b");
- while(iter.hasNext()){
+ while (iter.hasNext()) {
Tuple t = iter.next();
assertTrue(t.equals(expectedTuple));
}
}
@Test
- public void testFilterUDFusingDefine2() throws Exception{
- File inputFile= createFile(
- new String[]{
- "www.paulisageek.com\t4",
- "www.yahoo.com\t12344",
- "google.com\t1",
- "us2.amazon.com\t4141"
- }
+ public void testFilterUDFusingDefine2() throws Exception {
+ File inputFile = createFile(
+ new String[] {
+ "www.paulisageek.com\t4",
+ "www.yahoo.com\t12344",
+ "google.com\t1",
+ "us2.amazon.com\t4141"
+ }
);
File filterFile = createFile(
- new String[]{
- "12344"
- }
+ new String[] {
+ "12344"
+ }
);
pigServer.registerQuery("define FILTER_CRITERION "
@@ -200,7 +194,7 @@ public class TestFilterUDF {
expectedTuple.append(new Integer("12344"));
Iterator<Tuple> iter = pigServer.openIterator("b");
- while(iter.hasNext()){
+ while (iter.hasNext()) {
Tuple t = iter.next();
assertTrue(t.equals(expectedTuple));
}
Modified: pig/trunk/test/org/apache/pig/test/TestFinish.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestFinish.java?rev=1407167&r1=1407166&r2=1407167&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestFinish.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestFinish.java Thu Nov 8 17:06:46 2012
@@ -1,14 +1,12 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
- *
+ * 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.
@@ -17,6 +15,7 @@
*/
package org.apache.pig.test;
+import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileOutputStream;
@@ -24,8 +23,6 @@ import java.io.IOException;
import java.io.PrintStream;
import java.util.Iterator;
-import junit.framework.TestCase;
-
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.pig.EvalFunc;
@@ -41,30 +38,28 @@ import org.apache.pig.impl.io.FileLocali
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.*;
public class TestFinish {
-
private PigServer pigServer;
TupleFactory mTf = TupleFactory.getInstance();
BagFactory mBf = BagFactory.getInstance();
File f1;
-
+
static MiniCluster cluster = MiniCluster.buildCluster();
-
- static public class MyEvalFunction extends EvalFunc<Tuple>{
-
+
+ static public class MyEvalFunction extends EvalFunc<Tuple> {
String execType;
String expectedFileName;
+
/**
- *
+ *
*/
public MyEvalFunction(String execType, String expectedFileName) {
this.execType = execType;
this.expectedFileName = expectedFileName;
}
-
+
@Override
public Tuple exec(Tuple input) throws IOException {
return input;
@@ -80,7 +75,7 @@ public class TestFinish {
}
}
}
-
+
@Before
public void setUp() throws Exception {
// re initialize FileLocalizer so that each test runs correctly without
@@ -88,22 +83,22 @@ public class TestFinish {
// tests are in mapred and some in local mode
FileLocalizer.setInitialized(false);
}
-
+
@AfterClass
public static void oneTimeTearDown() throws Exception {
cluster.shutDown();
}
-
- private String setUp(ExecType execType) throws Exception{
+
+ private String setUp(ExecType execType) throws Exception {
String inputFileName;
- if(execType == ExecType.LOCAL) {
+ if (execType == ExecType.LOCAL) {
pigServer = new PigServer(ExecType.LOCAL);
f1 = File.createTempFile("test", "txt");
f1.deleteOnExit();
inputFileName = f1.getAbsolutePath();
PrintStream ps = new PrintStream(new FileOutputStream(f1));
- for(int i = 0; i < 3; i++) {
- ps.println('a'+i + ":1");
+ for (int i = 0; i < 3; i++) {
+ ps.println('a' + i + ":1");
}
ps.close();
} else {
@@ -113,17 +108,17 @@ public class TestFinish {
inputFileName = Util.removeColon(f1.getAbsolutePath());
String input[] = new String[3];
- for(int i = 0; i < 3; i++) {
- input[i] = ('a'+i + ":1");
+ for (int i = 0; i < 3; i++) {
+ input[i] = ('a' + i + ":1");
}
Util.createInputFile(cluster, inputFileName, input);
}
return inputFileName;
}
-
+
private void checkAndCleanup(ExecType execType, String expectedFileName,
String inputFileName) throws IOException {
- if(execType == ExecType.MAPREDUCE) {
+ if (execType == ExecType.MAPREDUCE) {
FileSystem fs = FileSystem.get(ConfigurationUtil.toConfiguration(
cluster.getProperties()));
assertTrue(fs.exists(new Path(expectedFileName)));
@@ -138,64 +133,72 @@ public class TestFinish {
toString());
}
}
-
+
@Test
- public void testFinishInMapMR() throws Exception{
+ public void testFinishInMapMR() throws Exception {
String inputFileName = setUp(ExecType.MAPREDUCE);
// this file will be created on the cluster if finish() is called
String expectedFileName = "testFinishInMapMR-finish.txt";
- pigServer.registerQuery("define MYUDF " + MyEvalFunction.class.getName() + "('MAPREDUCE','" + expectedFileName + "');");
- pigServer.registerQuery("a = load '" + Util.encodeEscape(inputFileName) + "' using " + PigStorage.class.getName() + "(':');");
+ pigServer.registerQuery("define MYUDF " + MyEvalFunction.class.getName() + "('MAPREDUCE','"
+ + expectedFileName + "');");
+ pigServer.registerQuery("a = load '" + inputFileName + "' using "
+ + PigStorage.class.getName() + "(':');");
pigServer.registerQuery("b = foreach a generate MYUDF" + "(*);");
Iterator<Tuple> iter = pigServer.openIterator("b");
- while(iter.hasNext()){
+ while (iter.hasNext()) {
iter.next();
}
-
+
checkAndCleanup(ExecType.MAPREDUCE, expectedFileName, inputFileName);
-
+
}
-
+
@Test
- public void testFinishInReduceMR() throws Exception{
+ public void testFinishInReduceMR() throws Exception {
String inputFileName = setUp(ExecType.MAPREDUCE);
// this file will be created on the cluster if finish() is called
String expectedFileName = "testFinishInReduceMR-finish.txt";
- pigServer.registerQuery("define MYUDF " + MyEvalFunction.class.getName() + "('MAPREDUCE','" + expectedFileName + "');");
- pigServer.registerQuery("a = load '" + Util.encodeEscape(inputFileName) + "' using " + PigStorage.class.getName() + "(':');");
+ pigServer.registerQuery("define MYUDF " + MyEvalFunction.class.getName() + "('MAPREDUCE','"
+ + expectedFileName + "');");
+ pigServer.registerQuery("a = load '" + inputFileName + "' using "
+ + PigStorage.class.getName() + "(':');");
pigServer.registerQuery("a1 = group a by $1;");
pigServer.registerQuery("b = foreach a1 generate MYUDF" + "(*);");
Iterator<Tuple> iter = pigServer.openIterator("b");
- while(iter.hasNext()){
+ while (iter.hasNext()) {
iter.next();
}
-
+
checkAndCleanup(ExecType.MAPREDUCE, expectedFileName, inputFileName);
}
-
+
@Test
- public void testFinishInMapLoc() throws Exception{
+ public void testFinishInMapLoc() throws Exception {
String inputFileName = setUp(ExecType.LOCAL);
// this file will be created on the cluster if finish() is called
String expectedFileName = "testFinishInMapLoc-finish.txt";
- pigServer.registerQuery("define MYUDF " + MyEvalFunction.class.getName() + "('LOCAL','" + expectedFileName + "');");
- pigServer.registerQuery("a = load '" + Util.encodeEscape(inputFileName) + "' using " + PigStorage.class.getName() + "(':');");
+ pigServer.registerQuery("define MYUDF " + MyEvalFunction.class.getName() + "('LOCAL','"
+ + expectedFileName + "');");
+ pigServer.registerQuery("a = load '" + inputFileName + "' using "
+ + PigStorage.class.getName() + "(':');");
pigServer.registerQuery("b = foreach a generate MYUDF" + "(*);");
pigServer.openIterator("b");
checkAndCleanup(ExecType.LOCAL, expectedFileName, inputFileName);
}
-
+
@Test
- public void testFinishInReduceLoc() throws Exception{
+ public void testFinishInReduceLoc() throws Exception {
String inputFileName = setUp(ExecType.LOCAL);
// this file will be created on the cluster if finish() is called
String expectedFileName = "testFinishInReduceLoc-finish.txt";
- pigServer.registerQuery("define MYUDF " + MyEvalFunction.class.getName() + "('LOCAL','" + expectedFileName + "');");
- pigServer.registerQuery("a = load '" + Util.encodeEscape(inputFileName) + "' using " + PigStorage.class.getName() + "(':');");
+ pigServer.registerQuery("define MYUDF " + MyEvalFunction.class.getName() + "('LOCAL','"
+ + expectedFileName + "');");
+ pigServer.registerQuery("a = load '" + inputFileName + "' using "
+ + PigStorage.class.getName() + "(':');");
pigServer.registerQuery("a1 = group a by $1;");
pigServer.registerQuery("b = foreach a1 generate MYUDF" + "(*);");
pigServer.openIterator("b");
checkAndCleanup(ExecType.LOCAL, expectedFileName, inputFileName);
}
-
}
+
Modified: pig/trunk/test/org/apache/pig/test/TestForEach.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestForEach.java?rev=1407167&r1=1407166&r2=1407167&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestForEach.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestForEach.java Thu Nov 8 17:06:46 2012
@@ -1,14 +1,12 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
- *
+ * 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.
@@ -17,7 +15,8 @@
*/
package org.apache.pig.test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
@@ -25,21 +24,18 @@ import java.util.List;
import java.util.Random;
import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.POStatus;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.PhysicalOperator;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.Result;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POProject;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POForEach;
import org.apache.pig.data.DataBag;
import org.apache.pig.data.DataType;
-import org.apache.pig.data.DefaultBagFactory;
import org.apache.pig.data.DefaultTuple;
import org.apache.pig.data.Tuple;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.PhysicalOperator;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.POStatus;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.Result;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POForEach;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POLocalRearrange;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POProject;
import org.apache.pig.test.utils.GenPhyOp;
import org.apache.pig.test.utils.GenRandomData;
import org.apache.pig.test.utils.TestHelper;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -48,23 +44,21 @@ import org.junit.Test;
* Constructs a bag that projects the input
* bag onto the the column $0 and checks if
* the tuples generated by foreach are the same
- * as those in the projected bag
+ * as those in the projected bag
*
*/
-public class TestForEach extends junit.framework.TestCase {
-
+public class TestForEach {
POForEach fe;
Tuple t;
DataBag db;
DataBag projDB;
-
-
+
@Before
public void setUp() throws Exception {
Random r = new Random();
db = GenRandomData.genRandSmallTupDataBagWithNulls(r, 10, 100);
- projDB = TestHelper.projectBag(db,0);
- fe = GenPhyOp.topForEachOPWithPlan(0,db.iterator().next());
+ projDB = TestHelper.projectBag(db, 0);
+ fe = GenPhyOp.topForEachOPWithPlan(0, db.iterator().next());
POProject proj = GenPhyOp.exprProject();
proj.setColumn(0);
proj.setResultType(DataType.TUPLE);
@@ -77,21 +71,15 @@ public class TestForEach extends junit.f
fe.setInputs(inputs);
}
-
-
- @After
- public void tearDown() throws Exception {
- }
-
@Test
public void testGetNextTuple() throws ExecException, IOException {
- int size=0;
- for(Result res=fe.getNext(t);res.returnStatus!=POStatus.STATUS_EOP;res=fe.getNext(t)){
+ int size = 0;
+ for (Result res = fe.getNext(t); res.returnStatus != POStatus.STATUS_EOP; res = fe
+ .getNext(t)) {
Tuple t = (Tuple)res.result;
- assertEquals(true, TestHelper.bagContains(projDB, t));
+ assertTrue(TestHelper.bagContains(projDB, t));
++size;
}
- assertEquals(true, size==db.size());
+ assertEquals(size, db.size());
}
-
}
Modified: pig/trunk/test/org/apache/pig/test/TestGTOrEqual.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestGTOrEqual.java?rev=1407167&r1=1407166&r2=1407167&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestGTOrEqual.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestGTOrEqual.java Thu Nov 8 17:06:46 2012
@@ -1,14 +1,12 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
- *
+ * 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.
@@ -17,38 +15,22 @@
*/
package org.apache.pig.test;
-import java.util.Map;
-import java.util.Random;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
-import org.joda.time.DateTime;
-
-import org.apache.pig.backend.executionengine.ExecException;
-import org.apache.pig.data.DataBag;
-import org.apache.pig.data.DataByteArray;
-import org.apache.pig.data.DataType;
-import org.apache.pig.data.Tuple;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.POStatus;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.Result;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.ConstantExpression;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.GTOrEqualToExpr;
+import org.apache.pig.data.DataByteArray;
+import org.apache.pig.data.DataType;
import org.apache.pig.test.utils.GenPhyOp;
-import org.apache.pig.test.utils.GenRandomData;
-import org.junit.After;
-import org.junit.Before;
+import org.joda.time.DateTime;
import org.junit.Test;
-import static org.junit.Assert.*;
-
-public class TestGTOrEqual extends junit.framework.TestCase {
-
- @Before
- public void setUp() throws Exception {
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
+public class TestGTOrEqual {
@Test
public void testIntegerGt() throws Exception {
ConstantExpression lt = GenPhyOp.exprConst();
@@ -96,10 +78,10 @@ public class TestGTOrEqual extends junit
@Test
public void testIntegerAndNullValues() throws Exception {
-
- checkNullValues( DataType.INTEGER, new Integer(1) );
+
+ checkNullValues(DataType.INTEGER, new Integer(1));
}
-
+
@Test
public void testLongGt() throws Exception {
ConstantExpression lt = GenPhyOp.exprConst();
@@ -115,7 +97,6 @@ public class TestGTOrEqual extends junit
assertTrue((Boolean)r.result);
}
-
@Test
public void testLongLt() throws Exception {
ConstantExpression lt = GenPhyOp.exprConst();
@@ -148,8 +129,8 @@ public class TestGTOrEqual extends junit
@Test
public void testLongAndNullValues() throws Exception {
-
- checkNullValues( DataType.LONG, new Long(1L) );
+
+ checkNullValues(DataType.LONG, new Long(1L));
}
@Test
@@ -199,11 +180,10 @@ public class TestGTOrEqual extends junit
@Test
public void testFloatAndNullValues() throws Exception {
-
- checkNullValues( DataType.FLOAT, new Float(1.0f) );
+
+ checkNullValues(DataType.FLOAT, new Float(1.0f));
}
-
@Test
public void testDoubleGt() throws Exception {
ConstantExpression lt = GenPhyOp.exprConst();
@@ -251,8 +231,8 @@ public class TestGTOrEqual extends junit
@Test
public void testDoubleAndNullValues() throws Exception {
-
- checkNullValues( DataType.DOUBLE, new Double(1.0) );
+
+ checkNullValues(DataType.DOUBLE, new Double(1.0));
}
@Test
@@ -302,8 +282,8 @@ public class TestGTOrEqual extends junit
@Test
public void testDateTimeAndNullValues() throws Exception {
-
- checkNullValues( DataType.DATETIME, new DateTime(1L) );
+
+ checkNullValues(DataType.DATETIME, new DateTime(1L));
}
@Test
@@ -353,8 +333,8 @@ public class TestGTOrEqual extends junit
@Test
public void testStringAndNullValues() throws Exception {
-
- checkNullValues( DataType.CHARARRAY, new String("b") );
+
+ checkNullValues(DataType.CHARARRAY, new String("b"));
}
@Test
@@ -404,13 +384,10 @@ public class TestGTOrEqual extends junit
@Test
public void testDataByteArrayAndNullValues() throws Exception {
-
- checkNullValues( DataType.BYTEARRAY, new DataByteArray("b") );
+ checkNullValues(DataType.BYTEARRAY, new DataByteArray("b"));
}
-
- public <U> void checkNullValues( byte operandType, U value ) throws Exception {
-
+ public <U> void checkNullValues(byte operandType, U value) throws Exception {
ConstantExpression lt = GenPhyOp.exprConst();
ConstantExpression rt = GenPhyOp.exprConst();
GTOrEqualToExpr g = GenPhyOp.compGTOrEqualToExpr();
@@ -418,44 +395,34 @@ public class TestGTOrEqual extends junit
// test with null in lhs
g.setOperandType(operandType);
lt.setValue(null);
- rt.setValue( value );
+ rt.setValue(value);
g.setLhs(lt);
g.setRhs(rt);
-
+
Result r = g.getNext(new Boolean(true));
assertEquals(POStatus.STATUS_NULL, r.returnStatus);
- assertEquals(null, (Boolean)r.result);
-
+ assertNull(r.result);
+
// test with null in rhs
g.setOperandType(operandType);
- lt.setValue( value );
+ lt.setValue(value);
rt.setValue(null);
g.setLhs(lt);
g.setRhs(rt);
-
+
r = g.getNext(new Boolean(true));
assertEquals(POStatus.STATUS_NULL, r.returnStatus);
- assertEquals(null, (Boolean)r.result);
-
-
+ assertNull(r.result);
+
// test with null in lhs and rhs
g.setOperandType(operandType);
lt.setValue(null);
rt.setValue(null);
g.setLhs(lt);
g.setRhs(rt);
-
+
r = g.getNext(new Boolean(true));
assertEquals(POStatus.STATUS_NULL, r.returnStatus);
- assertEquals(null, (Boolean)r.result);
-
-
+ assertNull(r.result);
}
-
-
-
-
-
-
-
}