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 [7/10] - in /pig/trunk: ./ test/org/apache/pig/test/
test/org/apache/pig/test/pigunit/
Modified: pig/trunk/test/org/apache/pig/test/TestPigContext.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestPigContext.java?rev=1407167&r1=1407166&r2=1407167&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestPigContext.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestPigContext.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.
@@ -18,35 +16,18 @@
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;
import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.net.URI;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
-import java.util.Locale;
import java.util.Properties;
import java.util.Random;
-import javax.tools.Diagnostic;
-import javax.tools.DiagnosticCollector;
-import javax.tools.JavaCompiler;
-import javax.tools.JavaFileManager;
-import javax.tools.JavaFileObject;
-import javax.tools.SimpleJavaFileObject;
-import javax.tools.ToolProvider;
-import javax.tools.JavaFileObject.Kind;
-
-import com.google.common.collect.Lists;
-
-import junit.framework.TestCase;
-
import org.apache.hadoop.mapred.FileAlreadyExistsException;
import org.apache.log4j.Logger;
import org.apache.pig.ExecType;
@@ -60,8 +41,6 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
public class TestPigContext {
private static final Logger LOG = Logger.getLogger(TestPigContext.class);
@@ -72,113 +51,116 @@ public class TestPigContext {
private File input;
private PigContext pigContext;
static MiniCluster cluster = null;
-
- @BeforeClass
- public static void oneTimeSetup(){
+
+ @BeforeClass
+ public static void oneTimeSetup() {
cluster = MiniCluster.buildCluster();
}
-
+
@Before
public void setUp() throws Exception {
pigContext = new PigContext(ExecType.LOCAL, getProperties());
input = File.createTempFile("PigContextTest-", ".txt");
}
-
+
/**
- * Passing an already configured pigContext in PigServer constructor.
+ * Passing an already configured pigContext in PigServer constructor.
*/
@Test
public void testSetProperties_way_num01() throws Exception {
PigServer pigServer = new PigServer(pigContext);
registerAndStore(pigServer);
-
+
check_asserts(pigServer);
}
/**
- * Setting properties through PigServer constructor directly.
+ * Setting properties through PigServer constructor directly.
*/
@Test
public void testSetProperties_way_num02() throws Exception {
PigServer pigServer = new PigServer(ExecType.LOCAL, getProperties());
registerAndStore(pigServer);
-
+
check_asserts(pigServer);
}
/**
- * using connect() method.
+ * using connect() method.
*/
@Test
public void testSetProperties_way_num03() throws Exception {
pigContext.connect();
PigServer pigServer = new PigServer(pigContext);
registerAndStore(pigServer);
-
+
check_asserts(pigServer);
}
-
+
@Test
public void testHadoopExceptionCreation() throws Exception {
- Object object = PigContext.instantiateFuncFromSpec("org.apache.hadoop.mapred.FileAlreadyExistsException");
- assertTrue(object instanceof FileAlreadyExistsException);
+ Object object = PigContext
+ .instantiateFuncFromSpec("org.apache.hadoop.mapred.FileAlreadyExistsException");
+ assertTrue(object instanceof FileAlreadyExistsException);
}
-
+
@Test
// See PIG-832
public void testImportList() throws Exception {
-
+
String FILE_SEPARATOR = System.getProperty("file.separator");
File tmpDir = File.createTempFile("test", "");
tmpDir.delete();
tmpDir.mkdir();
-
- File udf1Dir = new File(tmpDir.getAbsolutePath()+FILE_SEPARATOR+"com"+FILE_SEPARATOR+"xxx"+FILE_SEPARATOR+"udf1");
+
+ File udf1Dir = new File(tmpDir.getAbsolutePath() + FILE_SEPARATOR + "com" + FILE_SEPARATOR
+ + "xxx" + FILE_SEPARATOR + "udf1");
udf1Dir.mkdirs();
- File udf2Dir = new File(tmpDir.getAbsolutePath()+FILE_SEPARATOR+"com"+FILE_SEPARATOR+"xxx"+FILE_SEPARATOR+"udf2");
+ File udf2Dir = new File(tmpDir.getAbsolutePath() + FILE_SEPARATOR + "com" + FILE_SEPARATOR
+ + "xxx" + FILE_SEPARATOR + "udf2");
udf2Dir.mkdirs();
-
- String udf1Src = new String("package com.xxx.udf1;\n"+
- "import java.io.IOException;\n"+
- "import org.apache.pig.EvalFunc;\n"+
- "import org.apache.pig.data.Tuple;\n"+
- "public class TestUDF1 extends EvalFunc<Integer>{\n"+
- "public Integer exec(Tuple input) throws IOException {\n"+
- "return 1;}\n"+
+
+ String udf1Src = new String("package com.xxx.udf1;\n" +
+ "import java.io.IOException;\n" +
+ "import org.apache.pig.EvalFunc;\n" +
+ "import org.apache.pig.data.Tuple;\n" +
+ "public class TestUDF1 extends EvalFunc<Integer>{\n" +
+ "public Integer exec(Tuple input) throws IOException {\n" +
+ "return 1;}\n" +
"}");
-
- String udf2Src = new String("package com.xxx.udf2;\n"+
+
+ String udf2Src = new String("package com.xxx.udf2;\n" +
"import org.apache.pig.builtin.PigStorage;\n" +
"public class TestUDF2 extends PigStorage { }\n");
-
+
// compile
JavaCompilerHelper javaCompilerHelper = new JavaCompilerHelper();
javaCompilerHelper.compile(tmpDir.getAbsolutePath(),
new JavaCompilerHelper.JavaSourceFromString("com.xxx.udf1.TestUDF1", udf1Src),
new JavaCompilerHelper.JavaSourceFromString("com.xxx.udf2.TestUDF2", udf2Src));
-
+
// generate jar file
String jarName = "TestUDFJar.jar";
String jarFile = tmpDir.getAbsolutePath() + FILE_SEPARATOR + jarName;
- int status = Util.executeJavaCommand("jar -cf " + jarFile +
- " -C " + tmpDir.getAbsolutePath() + " " + "com");
- assertTrue(status==0);
+ int status = Util.executeJavaCommand("jar -cf " + jarFile +
+ " -C " + tmpDir.getAbsolutePath() + " " + "com");
+ assertEquals(0, status);
Properties properties = cluster.getProperties();
PigContext localPigContext = new PigContext(ExecType.MAPREDUCE, properties);
-
- //register jar using properties
+
+ // register jar using properties
localPigContext.getProperties().setProperty("pig.additional.jars", jarFile);
PigServer pigServer = new PigServer(localPigContext);
PigContext.initializeImportList("com.xxx.udf1:com.xxx.udf2.");
ArrayList<String> importList = PigContext.getPackageImportList();
- assertTrue(importList.size()==5);
- assertTrue(importList.get(0).equals("com.xxx.udf1."));
- assertTrue(importList.get(1).equals("com.xxx.udf2."));
- assertTrue(importList.get(2).equals(""));
- assertTrue(importList.get(3).equals("org.apache.pig.builtin."));
- assertTrue(importList.get(4).equals("org.apache.pig.impl.builtin."));
-
+ assertEquals(5, importList.size());
+ assertEquals("com.xxx.udf1.", importList.get(0));
+ assertEquals("com.xxx.udf2.", importList.get(1));
+ assertEquals("", importList.get(2));
+ assertEquals("org.apache.pig.builtin.", importList.get(3));
+ assertEquals("org.apache.pig.impl.builtin.", importList.get(4));
+
Object udf = PigContext.instantiateFuncFromSpec("TestUDF1");
assertTrue(udf.getClass().toString().endsWith("com.xxx.udf1.TestUDF1"));
@@ -197,14 +179,15 @@ public class TestPigContext {
Util.createInputFile(cluster, clusterTmpPath, localInput);
FileLocalizer.deleteTempFiles();
- pigServer.registerQuery("A = LOAD '" + Util.encodeEscape(clusterTmpPath)+ "' using TestUDF2() AS (num:chararray);");
+ pigServer.registerQuery("A = LOAD '" + Util.encodeEscape(tmpFile.getCanonicalPath())
+ + "' using TestUDF2() AS (num:chararray);");
pigServer.registerQuery("B = foreach A generate TestUDF1(num);");
Iterator<Tuple> iter = pigServer.openIterator("B");
- if(!iter.hasNext()) fail("No output found");
- while(iter.hasNext()){
+ assertTrue("No Output received", iter.hasNext());
+ while (iter.hasNext()) {
Tuple t = iter.next();
assertTrue(t.get(0) instanceof Integer);
- assertTrue((Integer)t.get(0) == 1);
+ assertEquals(Integer.valueOf(1), (Integer)t.get(0));
}
Util.deleteFile(cluster, clusterTmpPath);
Util.deleteDirectory(tmpDir);
@@ -223,7 +206,7 @@ public class TestPigContext {
pc.addScriptFile("path-1824", "test/path-1824");
assertEquals("test/path-1824", pc.getScriptFiles().get("path-1824").toString());
assertEquals("script files should not be populated", n, pc.scriptFiles.size());
-
+
// last add wins when using an alias
pc.addScriptFile("path-1824", "test/some/other/path-1824");
assertEquals("test/some/other/path-1824", pc.getScriptFiles().get("path-1824").toString());
@@ -238,13 +221,12 @@ public class TestPigContext {
public void tearDown() throws Exception {
input.delete();
}
-
+
@AfterClass
public static void oneTimeTearDown() throws Exception {
cluster.shutDown();
}
-
-
+
private static Properties getProperties() {
Properties props = new Properties();
props.put("mapred.job.tracker", JOB_TRACKER);
@@ -255,7 +237,8 @@ public class TestPigContext {
private List<String> getCommands() {
List<String> commands = new ArrayList<String>();
- commands.add("my_input = LOAD '" + Util.encodeEscape(input.getAbsolutePath()) + "' USING PigStorage();");
+ commands.add("my_input = LOAD '" + Util.encodeEscape(input.getAbsolutePath())
+ + "' USING PigStorage();");
commands.add("words = FOREACH my_input GENERATE FLATTEN(TOKENIZE($0));");
commands.add("grouped = GROUP words BY $0;");
commands.add("counts = FOREACH grouped GENERATE group, COUNT(words);");
@@ -274,8 +257,11 @@ public class TestPigContext {
}
private void check_asserts(PigServer pigServer) {
- assertEquals(JOB_TRACKER, pigServer.getPigContext().getProperties().getProperty("mapred.job.tracker"));
- assertEquals(FS_NAME, pigServer.getPigContext().getProperties().getProperty("fs.default.name"));
- assertEquals(TMP_DIR_PROP, pigServer.getPigContext().getProperties().getProperty("hadoop.tmp.dir"));
+ assertEquals(JOB_TRACKER,
+ pigServer.getPigContext().getProperties().getProperty("mapred.job.tracker"));
+ assertEquals(FS_NAME,
+ pigServer.getPigContext().getProperties().getProperty("fs.default.name"));
+ assertEquals(TMP_DIR_PROP,
+ pigServer.getPigContext().getProperties().getProperty("hadoop.tmp.dir"));
}
}
Modified: pig/trunk/test/org/apache/pig/test/TestPigScriptParser.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestPigScriptParser.java?rev=1407167&r1=1407166&r2=1407167&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestPigScriptParser.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestPigScriptParser.java Thu Nov 8 17:06:46 2012
@@ -123,13 +123,13 @@ public class TestPigScriptParser {
Iterator<Tuple> it = ps.openIterator("B");
int[] expectedResults = new int[] {2,0,1,0,0};
int i = 0;
- while(it.hasNext()) {
+ while (it.hasNext()) {
Tuple t = it.next();
assertEquals(expectedResults[i++], t.get(0));
}
}
- @Test
+ @Test
public void testSplitWithNotEvalCondition() throws Exception {
String defineQ = "define minelogs org.apache.pig.test.RegexGroupCount('www\\\\.xyz\\\\.com/sports');";
String defineL = "a = load 'nosuchfile' " +
@@ -150,17 +150,17 @@ public class TestPigScriptParser {
ps.registerQuery(queryA);
try {
ps.registerQuery(queryB);
- }catch (FrontendException e) {
+ } catch (FrontendException e) {
assertTrue(e.getMessage().contains("Undefined alias:"));
throw e;
}
}
private void checkParsedConstContent(PigServer pigServer,
- PigContext pigContext,
- String query,
- String expectedContent)
- throws Exception {
+ PigContext pigContext,
+ String query,
+ String expectedContent)
+ throws Exception {
pigContext.connect();
LogicalPlan lp = Util.buildLp(pigServer, query + "store B into 'output';");
// Digging down the tree
@@ -190,5 +190,5 @@ public class TestPigScriptParser {
ps.close();
return inputFile.getPath();
}
-
}
+
Modified: pig/trunk/test/org/apache/pig/test/TestPlanGeneration.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestPlanGeneration.java?rev=1407167&r1=1407166&r2=1407167&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestPlanGeneration.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestPlanGeneration.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,15 +15,16 @@
*/
package org.apache.pig.test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
import java.io.IOException;
import java.util.Properties;
-import junit.framework.Assert;
-
import org.apache.hadoop.mapreduce.Job;
import org.apache.pig.ExecType;
import org.apache.pig.Expression;
-import org.apache.pig.LoadFunc;
import org.apache.pig.LoadMetadata;
import org.apache.pig.ResourceSchema;
import org.apache.pig.ResourceStatistics;
@@ -39,7 +38,6 @@ import org.apache.pig.backend.hadoop.exe
import org.apache.pig.builtin.PigStorage;
import org.apache.pig.data.DataType;
import org.apache.pig.impl.PigContext;
-import org.apache.pig.impl.logicalLayer.FrontendException;
import org.apache.pig.impl.logicalLayer.schema.Schema;
import org.apache.pig.impl.util.Utils;
import org.apache.pig.newplan.Operator;
@@ -54,165 +52,165 @@ import org.apache.pig.newplan.logical.re
import org.apache.pig.newplan.logical.relational.LogicalSchema;
import org.apache.pig.newplan.logical.relational.LogicalSchema.LogicalFieldSchema;
import org.apache.pig.parser.ParserException;
-import org.apache.pig.test.TestPartitionFilterPushDown.TestLoader;
import org.junit.BeforeClass;
import org.junit.Test;
-public class TestPlanGeneration extends junit.framework.TestCase {
-
- PigContext pc;
-
- @Override
+public class TestPlanGeneration {
+
+ static PigContext pc;
+
@BeforeClass
- public void setUp() throws ExecException {
+ public static void setUp() throws ExecException {
pc = new PigContext(ExecType.LOCAL, new Properties());
pc.connect();
}
-
+
@Test
- public void testGenerateStar() throws Exception {
+ public void testGenerateStar() throws Exception {
String query = "a = load 'x';" +
- "b = foreach a generate *;" +
- "store b into '111';";
-
+ "b = foreach a generate *;" +
+ "store b into '111';";
+
LogicalPlan lp = Util.parseAndPreprocess(query, pc);
Util.optimizeNewLP(lp);
LOStore loStore = (LOStore)lp.getSinks().get(0);
LOForEach loForEach = (LOForEach)lp.getPredecessors(loStore).get(0);
- assert(loForEach.getSchema()==null);
+ assertNull(loForEach.getSchema());
}
-
+
@Test
- public void testEmptyBagDereference() throws Exception {
+ public void testEmptyBagDereference() throws Exception {
String query = "A = load 'x' as ( u:bag{} );" +
- "B = foreach A generate u.$100;" +
- "store B into '111';";
-
+ "B = foreach A generate u.$100;" +
+ "store B into '111';";
+
LogicalPlan lp = Util.parseAndPreprocess(query, pc);
Util.optimizeNewLP(lp);
LOStore loStore = (LOStore)lp.getSinks().get(0);
LOForEach loForEach = (LOForEach)lp.getPredecessors(loStore).get(0);
LogicalSchema schema = loForEach.getSchema();
- Assert.assertTrue(schema.size()==1);
+ assertEquals(1, schema.size());
LogicalFieldSchema bagFieldSchema = schema.getField(0);
- Assert.assertTrue(bagFieldSchema.type==DataType.BAG);
- LogicalFieldSchema tupleFieldSchema = bagFieldSchema.schema.getField(0);
- Assert.assertTrue(tupleFieldSchema.schema.size()==1);
- Assert.assertTrue(tupleFieldSchema.schema.getField(0).type==DataType.BYTEARRAY);
+ assertEquals(DataType.BAG, bagFieldSchema.type);
+ LogicalFieldSchema tupleFieldSchema = bagFieldSchema.schema.getField(0);
+ assertEquals(1, tupleFieldSchema.schema.size());
+ assertEquals(DataType.BYTEARRAY, tupleFieldSchema.schema.getField(0).type);
}
-
+
@Test
- public void testEmptyTupleDereference() throws Exception {
+ public void testEmptyTupleDereference() throws Exception {
String query = "A = load 'x' as ( u:tuple() );" +
- "B = foreach A generate u.$100;" +
- "store B into '111';";
-
+ "B = foreach A generate u.$100;" +
+ "store B into '111';";
+
LogicalPlan lp = Util.parseAndPreprocess(query, pc);
Util.optimizeNewLP(lp);
LOStore loStore = (LOStore)lp.getSinks().get(0);
LOForEach loForEach = (LOForEach)lp.getPredecessors(loStore).get(0);
LogicalSchema schema = loForEach.getSchema();
- Assert.assertTrue(schema.size()==1);
- Assert.assertTrue(schema.getField(0).type==DataType.BYTEARRAY);
+ assertEquals(1, schema.size());
+ assertEquals(DataType.BYTEARRAY, schema.getField(0).type);
}
@Test
- public void testEmptyBagInnerPlan() throws Exception {
+ public void testEmptyBagInnerPlan() throws Exception {
String query = "A = load 'x' as ( u:bag{} );" +
- "B = foreach A { B1 = filter u by $1==0; generate B1;};" +
- "store B into '111';";
-
+ "B = foreach A { B1 = filter u by $1==0; generate B1;};" +
+ "store B into '111';";
+
LogicalPlan lp = Util.parseAndPreprocess(query, pc);
Util.optimizeNewLP(lp);
LOStore loStore = (LOStore)lp.getSinks().get(0);
LOForEach loForEach = (LOForEach)lp.getPredecessors(loStore).get(0);
LogicalSchema schema = loForEach.getSchema();
- Assert.assertTrue(schema.size()==1);
+ assertEquals(1, schema.size());
LogicalFieldSchema bagFieldSchema = schema.getField(0);
- Assert.assertTrue(bagFieldSchema.type==DataType.BAG);
- LogicalFieldSchema tupleFieldSchema = bagFieldSchema.schema.getField(0);
- Assert.assertTrue(tupleFieldSchema.schema==null);
+ assertEquals(DataType.BAG, bagFieldSchema.type);
+ LogicalFieldSchema tupleFieldSchema = bagFieldSchema.schema.getField(0);
+ assertNull(tupleFieldSchema.schema);
}
-
+
@Test
- public void testOrderByNullFieldSchema() throws Exception {
+ public void testOrderByNullFieldSchema() throws Exception {
String query = "A = load 'x';" +
- "B = order A by *;" +
- "store B into '111';";
-
+ "B = order A by *;" +
+ "store B into '111';";
+
LogicalPlan lp = Util.parseAndPreprocess(query, pc);
Util.optimizeNewLP(lp);
LOStore loStore = (LOStore)lp.getSinks().get(0);
LOSort loSort = (LOSort)lp.getPredecessors(loStore).get(0);
Operator sortPlanLeaf = loSort.getSortColPlans().get(0).getSources().get(0);
LogicalFieldSchema sortPlanFS = ((LogicalExpression)sortPlanLeaf).getFieldSchema();
- Assert.assertTrue(sortPlanFS==null);
-
+ assertNull(sortPlanFS);
+
PhysicalPlan pp = Util.buildPhysicalPlanFromNewLP(lp, pc);
POStore poStore = (POStore)pp.getLeaves().get(0);
POSort poSort = (POSort)pp.getPredecessors(poStore).get(0);
POProject poProject = (POProject)poSort.getSortPlans().get(0).getLeaves().get(0);
- Assert.assertTrue(poProject.getResultType()==DataType.TUPLE);
+ assertEquals(DataType.TUPLE, poProject.getResultType());
}
-
+
@Test
- public void testGroupByNullFieldSchema() throws Exception {
+ public void testGroupByNullFieldSchema() throws Exception {
String query = "A = load 'x';" +
- "B = group A by *;" +
- "store B into '111';";
-
+ "B = group A by *;" +
+ "store B into '111';";
+
LogicalPlan lp = Util.parseAndPreprocess(query, pc);
Util.optimizeNewLP(lp);
LOStore loStore = (LOStore)lp.getSinks().get(0);
LOCogroup loCoGroup = (LOCogroup)lp.getPredecessors(loStore).get(0);
LogicalFieldSchema groupFieldSchema = loCoGroup.getSchema().getField(0);
- Assert.assertTrue(groupFieldSchema.type==DataType.TUPLE);
- Assert.assertTrue(groupFieldSchema.schema==null);
+ assertEquals(DataType.TUPLE, groupFieldSchema.type);
+ assertNull(groupFieldSchema.schema);
}
-
+
@Test
- public void testStoreAlias() throws Exception {
+ public void testStoreAlias() throws Exception {
String query = "A = load 'data' as (a0, a1);" +
- "B = filter A by a0 > 1;" +
- "store B into 'output';";
-
+ "B = filter A by a0 > 1;" +
+ "store B into 'output';";
+
LogicalPlan lp = Util.parse(query, pc);
Util.optimizeNewLP(lp);
LOStore loStore = (LOStore)lp.getSinks().get(0);
- assert(loStore.getAlias().equals("B"));
-
+ assertEquals("B", loStore.getAlias());
+
PhysicalPlan pp = Util.buildPhysicalPlanFromNewLP(lp, pc);
POStore poStore = (POStore)pp.getLeaves().get(0);
- assert(poStore.getAlias().equals("B"));
-
+ assertEquals("B", poStore.getAlias());
+
MROperPlan mrp = Util.buildMRPlanWithOptimizer(pp, pc);
MapReduceOper mrOper = mrp.getLeaves().get(0);
poStore = (POStore)mrOper.mapPlan.getLeaves().get(0);
- assert(poStore.getAlias().equals("B"));
+ assertEquals("B", poStore.getAlias());
}
-
+
// See PIG-2119
@Test
- public void testDanglingNestedNode() throws Exception {
+ public void testDanglingNestedNode() throws Exception {
String query = "a = load 'b.txt' AS (id:chararray, num:int); " +
- "b = group a by id;" +
- "c = foreach b {" +
- " d = order a by num DESC;" +
- " n = COUNT(a);" +
- " e = limit d 1;" +
- " generate n;" +
- "};";
-
+ "b = group a by id;" +
+ "c = foreach b {" +
+ " d = order a by num DESC;" +
+ " n = COUNT(a);" +
+ " e = limit d 1;" +
+ " generate n;" +
+ "};";
+
LogicalPlan lp = Util.parse(query, pc);
Util.optimizeNewLP(lp);
}
-
+
public static class SchemaLoader extends PigStorage implements LoadMetadata {
Schema schema;
+
public SchemaLoader(String schemaString) throws ParserException {
schema = Utils.getSchemaFromString(schemaString);
}
+
@Override
public ResourceSchema getSchema(String location, Job job)
throws IOException {
@@ -236,37 +234,38 @@ public class TestPlanGeneration extends
throws IOException {
}
}
-
+
@Test
public void testLoaderWithSchema() throws Exception {
- String query = "a = load 'foo' using " + SchemaLoader.class.getName() + "('name,age,gpa');\n"
+ String query = "a = load 'foo' using " + SchemaLoader.class.getName()
+ + "('name,age,gpa');\n"
+ "b = filter a by age==20;"
+ "store b into 'output';";
LogicalPlan lp = Util.parse(query, pc);
Util.optimizeNewLP(lp);
-
+
LOLoad loLoad = (LOLoad)lp.getSources().get(0);
LOFilter loFilter = (LOFilter)lp.getSuccessors(loLoad).get(0);
LOStore loStore = (LOStore)lp.getSuccessors(loFilter).get(0);
-
- Assert.assertTrue(lp.getSuccessors(loStore)==null);
+
+ assertNull(lp.getSuccessors(loStore));
}
-
+
public static class PartitionedLoader extends PigStorage implements LoadMetadata {
Schema schema;
String[] partCols;
static Expression partFilter = null;
-
- public PartitionedLoader(String schemaString, String commaSepPartitionCols)
- throws ParserException {
+
+ public PartitionedLoader(String schemaString, String commaSepPartitionCols)
+ throws ParserException {
schema = Utils.getSchemaFromString(schemaString);
partCols = commaSepPartitionCols.split(",");
}
@Override
public ResourceSchema getSchema(String location, Job job)
- throws IOException {
+ throws IOException {
return new ResourceSchema(schema);
}
@@ -278,8 +277,8 @@ public class TestPlanGeneration extends
@Override
public void setPartitionFilter(Expression partitionFilter)
- throws IOException {
- partFilter = partitionFilter;
+ throws IOException {
+ partFilter = partitionFilter;
}
@Override
@@ -287,27 +286,27 @@ public class TestPlanGeneration extends
throws IOException {
return partCols;
}
-
+
public Expression getPartFilter() {
return partFilter;
}
}
-
+
@Test
// See PIG-2339
public void testPartitionFilterOptimizer() throws Exception {
- String query = "a = load 'foo' using " + PartitionedLoader.class.getName() +
+ String query = "a = load 'foo' using " + PartitionedLoader.class.getName() +
"('name:chararray, dt:chararray', 'dt');\n" +
- "b = filter a by dt=='2011';\n" +
- "store b into 'output';";
-
+ "b = filter a by dt=='2011';\n" +
+ "store b into 'output';";
+
LogicalPlan lp = Util.parse(query, pc);
Util.optimizeNewLP(lp);
-
+
LOLoad loLoad = (LOLoad)lp.getSources().get(0);
LOStore loStore = (LOStore)lp.getSuccessors(loLoad).get(0);
- Assert.assertTrue(((PartitionedLoader)loLoad.getLoadFunc()).getPartFilter()!=null);
- Assert.assertTrue(loStore.getAlias().equals("b"));
+ assertNotNull(((PartitionedLoader)loLoad.getLoadFunc()).getPartFilter());
+ assertEquals("b", loStore.getAlias());
}
}
Modified: pig/trunk/test/org/apache/pig/test/TestPoissonSampleLoader.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestPoissonSampleLoader.java?rev=1407167&r1=1407166&r2=1407167&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestPoissonSampleLoader.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestPoissonSampleLoader.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,8 @@
*/
package org.apache.pig.test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileWriter;
@@ -24,8 +24,6 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
-import junit.framework.TestCase;
-
import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
import org.apache.pig.backend.executionengine.ExecException;
@@ -34,31 +32,29 @@ 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 TestPoissonSampleLoader extends TestCase{
+public class TestPoissonSampleLoader {
private static final String INPUT_FILE1 = "SkewedJoinInput1.txt";
private PigServer pigServer;
private static MiniCluster cluster = MiniCluster.buildCluster();
- public TestPoissonSampleLoader() throws ExecException, IOException{
+ public TestPoissonSampleLoader() throws ExecException, IOException {
pigServer = new PigServer(ExecType.LOCAL);
- pigServer.getPigContext().getProperties().setProperty("pig.skewedjoin.reduce.maxtuple", "5");
- pigServer.getPigContext().getProperties().setProperty("pig.skewedjoin.reduce.memusage", "0.0001");
+ pigServer.getPigContext().getProperties()
+ .setProperty("pig.skewedjoin.reduce.maxtuple", "5");
+ pigServer.getPigContext().getProperties()
+ .setProperty("pig.skewedjoin.reduce.memusage", "0.0001");
pigServer.getPigContext().getProperties().setProperty("mapred.child.java.opts", "-Xmx512m");
pigServer.getPigContext().getProperties().setProperty("pig.mapsplits.count", "5");
}
-
@Before
public void setUp() throws Exception {
createFiles();
}
-
+
@AfterClass
public static void oneTimeTearDown() throws Exception {
cluster.shutDown();
@@ -68,13 +64,13 @@ public class TestPoissonSampleLoader ext
PrintWriter w = new PrintWriter(new FileWriter(INPUT_FILE1));
int k = 0;
- for(int j=0; j<100; j++) {
+ for (int j = 0; j < 100; j++) {
w.println("100:apple1:aaa" + k);
k++;
w.println("200:orange1:bbb" + k);
k++;
w.println("300:strawberry:ccc" + k);
- k++;
+ k++;
}
w.close();
@@ -82,7 +78,6 @@ public class TestPoissonSampleLoader ext
Util.copyFromLocalToCluster(cluster, INPUT_FILE1, INPUT_FILE1);
}
-
@After
public void tearDown() throws Exception {
new File(INPUT_FILE1).delete();
@@ -91,63 +86,43 @@ public class TestPoissonSampleLoader ext
}
private int testNumSamples(String memUsage, String sampleRate) throws IOException {
- pigServer.getPigContext().getProperties().setProperty("pig.skewedjoin.reduce.memusage", memUsage);
- pigServer.getPigContext().getProperties().setProperty("pig.sksampler.samplerate", sampleRate);
- pigServer.registerQuery("A = Load '"+INPUT_FILE1+"' Using PoissonSampleLoader('PigStorage()', '100');");
+ pigServer.getPigContext().getProperties()
+ .setProperty("pig.skewedjoin.reduce.memusage", memUsage);
+ pigServer.getPigContext().getProperties()
+ .setProperty("pig.sksampler.samplerate", sampleRate);
+ pigServer.registerQuery("A = Load '" + INPUT_FILE1
+ + "' Using PoissonSampleLoader('PigStorage()', '100');");
Iterator<Tuple> iter = pigServer.openIterator("A");
int count = 0;
- while(iter.hasNext()){
+ while (iter.hasNext()) {
count++;
iter.next();
}
return count;
}
-/*
-// This test has been removed because the results are platform dependent.
-// See: PIG-2926
- @Test
- public void testNumSamples() throws IOException {
- //PoissonSampleLoader.DEFAULT_SAMPLE_RATE is 17
- int count = testNumSamples("0.0001", "17");
- assertEquals(count, 12);
- count = testNumSamples("0.001", "17");
- assertEquals(count, 6);
-
- count = testNumSamples("0.001", "10");
- assertEquals(count, 4);
-
- count = testNumSamples("0.001", "100");
- assertEquals(count, 9);
-
- count = testNumSamples("0.005", "17");
- assertEquals(count, 2);
-
- count = testNumSamples("0.0001", "100");
- assertEquals(count, 42);
- }
-*/
/*
* Test use of LoadFunc with parameters as argument to PoissonSampleLoader
*/
@Test
public void testInstantiation() throws IOException {
- pigServer.registerQuery("A = Load '"+INPUT_FILE1+"' Using PoissonSampleLoader('PigStorage(\\\\\\':\\\\\\')', '100');");
+ pigServer.registerQuery("A = Load '" + INPUT_FILE1
+ + "' Using PoissonSampleLoader('PigStorage(\\\\\\':\\\\\\')', '100');");
Iterator<Tuple> iter = pigServer.openIterator("A");
assertTrue(iter.hasNext());
-
+
Tuple t = iter.next();
- //Check the tuple size. It has to be 3.
+ // Check the tuple size. It has to be 3.
assertEquals(3, t.size());
- while(iter.hasNext()){
+ while (iter.hasNext()) {
t = iter.next();
}
// Last tuple's size has to be 5
- // 3 datum (ex: 100:apple1:aaa)
- // + PoissonSampleLoader.NUMROWS_TUPLE_MARKER ??_pig_inTeRnal-spEcial_roW_num_tuple3kt579CFLehkblah
+ // 3 datum (ex: 100:apple1:aaa)
+ // + PoissonSampleLoader.NUMROWS_TUPLE_MARKER
+ // ??_pig_inTeRnal-spEcial_roW_num_tuple3kt579CFLehkblah
// + numRow 300
assertEquals(5, t.size());
}
-
}
\ No newline at end of file
Modified: pig/trunk/test/org/apache/pig/test/TestProject.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestProject.java?rev=1407167&r1=1407166&r2=1407167&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestProject.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestProject.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,34 +15,30 @@
*/
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;
import java.util.Iterator;
import java.util.Random;
-import java.util.ArrayList;
import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
import org.apache.pig.backend.executionengine.ExecException;
-import org.apache.pig.data.DataBag;
-import org.apache.pig.data.DataType;
-import org.apache.pig.data.TupleFactory;
-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.POProject;
+import org.apache.pig.data.DataBag;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.TupleFactory;
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.AfterClass;
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-public class TestProject extends junit.framework.TestCase {
+public class TestProject {
Random r;
Tuple t, tRandom, tRandomAndNull;
@@ -53,7 +47,6 @@ public class TestProject extends junit.
POProject proj;
- @Override
@Before
public void setUp() throws Exception {
r = new Random();
@@ -63,14 +56,9 @@ public class TestProject extends junit.
proj = GenPhyOp.exprProject();
}
- @Override
- @After
- public void tearDown() throws Exception {
- }
-
@Test
public void testGetNext() throws ExecException, IOException {
- t=tRandom;
+ t = tRandom;
proj.attachInput(t);
for (int j = 0; j < t.size(); j++) {
proj.attachInput(t);
@@ -82,29 +70,27 @@ public class TestProject extends junit.
}
}
-
-
@Test
public void testGetNextTuple() throws IOException, ExecException {
- t=tRandom;
+ t = tRandom;
proj.attachInput(t);
proj.setColumn(0);
proj.setOverloaded(true);
- DataBag inpBag = (DataBag) t.get(0);
+ DataBag inpBag = (DataBag)t.get(0);
int cntr = 0;
boolean contains = true;
while (true) {
res = proj.getNext(t);
if (res.returnStatus == POStatus.STATUS_EOP)
break;
- if (!TestHelper.bagContains(inpBag, (Tuple) res.result)) {
+ if (!TestHelper.bagContains(inpBag, (Tuple)res.result)) {
contains = false;
break;
}
++cntr;
}
- assertEquals((float) (inpBag).size(), (float) cntr, 0.01f);
- assertEquals(true, contains);
+ assertEquals((float)inpBag.size(), (float)cntr, 0.01f);
+ assertTrue(contains);
proj.attachInput(t);
proj.setColumn(8);
@@ -114,38 +100,32 @@ public class TestProject extends junit.
assertEquals(t.get(8), res.result);
}
-
-
-
@Test
public void testGetNextMultipleProjections() throws ExecException, IOException {
- t=tRandom;
+ t = tRandom;
ArrayList<Integer> cols = new ArrayList<Integer>();
proj.attachInput(t);
for (int j = 0; j < t.size() - 1; j++) {
proj.attachInput(t);
cols.add(j);
- cols.add(j+1);
+ cols.add(j + 1);
proj.setColumns(cols);
res = proj.getNext();
- TupleFactory tupleFactory = TupleFactory.getInstance();
- ArrayList<Object> objList = new ArrayList<Object>();
- objList.add(t.get(j));
- objList.add(t.get(j+1));
- Tuple expectedResult = tupleFactory.newTuple(objList);
+ TupleFactory tupleFactory = TupleFactory.getInstance();
+ ArrayList<Object> objList = new ArrayList<Object>();
+ objList.add(t.get(j));
+ objList.add(t.get(j + 1));
+ Tuple expectedResult = tupleFactory.newTuple(objList);
assertEquals(POStatus.STATUS_OK, res.returnStatus);
assertEquals(expectedResult, res.result);
cols.clear();
}
}
-
-
-
@Test
public void testGetNextTupleMultipleProjections() throws IOException, ExecException {
- t=tRandom;
+ t = tRandom;
proj.attachInput(t);
proj.setOverloaded(true);
int j = 0;
@@ -153,16 +133,16 @@ public class TestProject extends junit.
while (true) {
cols.add(j);
- cols.add(j+1);
+ cols.add(j + 1);
proj.setColumns(cols);
res = proj.getNext(t);
if (res.returnStatus == POStatus.STATUS_EOP)
break;
- TupleFactory tupleFactory = TupleFactory.getInstance();
- ArrayList<Object> objList = new ArrayList<Object>();
- objList.add(t.get(j));
- objList.add(t.get(j+1));
- Tuple expectedResult = tupleFactory.newTuple(objList);
+ TupleFactory tupleFactory = TupleFactory.getInstance();
+ ArrayList<Object> objList = new ArrayList<Object>();
+ objList.add(t.get(j));
+ objList.add(t.get(j + 1));
+ Tuple expectedResult = tupleFactory.newTuple(objList);
assertEquals(POStatus.STATUS_OK, res.returnStatus);
assertEquals(expectedResult, res.result);
++j;
@@ -176,10 +156,10 @@ public class TestProject extends junit.
assertEquals(POStatus.STATUS_OK, res.returnStatus);
assertEquals(t.get(8), res.result);
}
-
+
@Test
public void testGetNextWithNull() throws ExecException, IOException {
- t= tRandomAndNull;
+ t = tRandomAndNull;
proj.attachInput(t);
for (int j = 0; j < t.size(); j++) {
proj.attachInput(t);
@@ -191,28 +171,27 @@ public class TestProject extends junit.
}
}
-
- @Test
+ @Test
public void testGetNextTupleWithNull() throws IOException, ExecException {
- t= tRandomAndNull;
+ t = tRandomAndNull;
proj.attachInput(t);
proj.setColumn(0);
proj.setOverloaded(true);
- DataBag inpBag = (DataBag) t.get(0);
+ DataBag inpBag = (DataBag)t.get(0);
int cntr = 0;
boolean contains = true;
while (true) {
res = proj.getNext(t);
if (res.returnStatus == POStatus.STATUS_EOP)
break;
- if (!TestHelper.bagContains(inpBag, (Tuple) res.result)) {
+ if (!TestHelper.bagContains(inpBag, (Tuple)res.result)) {
contains = false;
break;
}
++cntr;
}
- assertEquals((float) (inpBag).size(), (float) cntr, 0.01f);
- assertEquals(true, contains);
+ assertEquals((float)inpBag.size(), (float)cntr, 0.01f);
+ assertTrue(contains);
proj.attachInput(t);
proj.setColumn(8);
@@ -222,38 +201,32 @@ public class TestProject extends junit.
assertEquals(t.get(8), res.result);
}
-
-
-
@Test
public void testGetNextMultipleProjectionsWithNull() throws ExecException, IOException {
- t= tRandomAndNull;
+ t = tRandomAndNull;
ArrayList<Integer> cols = new ArrayList<Integer>();
proj.attachInput(t);
for (int j = 0; j < t.size() - 1; j++) {
proj.attachInput(t);
cols.add(j);
- cols.add(j+1);
+ cols.add(j + 1);
proj.setColumns(cols);
res = proj.getNext();
- TupleFactory tupleFactory = TupleFactory.getInstance();
- ArrayList<Object> objList = new ArrayList<Object>();
- objList.add(t.get(j));
- objList.add(t.get(j+1));
- Tuple expectedResult = tupleFactory.newTuple(objList);
+ TupleFactory tupleFactory = TupleFactory.getInstance();
+ ArrayList<Object> objList = new ArrayList<Object>();
+ objList.add(t.get(j));
+ objList.add(t.get(j + 1));
+ Tuple expectedResult = tupleFactory.newTuple(objList);
assertEquals(POStatus.STATUS_OK, res.returnStatus);
assertEquals(expectedResult, res.result);
cols.clear();
}
}
-
-
-
@Test
public void testGetNextTupleMultipleProjectionsWithNull() throws IOException, ExecException {
- t= tRandomAndNull;
+ t = tRandomAndNull;
proj.attachInput(t);
proj.setOverloaded(true);
int j = 0;
@@ -261,16 +234,16 @@ public class TestProject extends junit.
while (true) {
cols.add(j);
- cols.add(j+1);
+ cols.add(j + 1);
proj.setColumns(cols);
res = proj.getNext(t);
if (res.returnStatus == POStatus.STATUS_EOP)
break;
- TupleFactory tupleFactory = TupleFactory.getInstance();
- ArrayList<Object> objList = new ArrayList<Object>();
- objList.add(t.get(j));
- objList.add(t.get(j+1));
- Tuple expectedResult = tupleFactory.newTuple(objList);
+ TupleFactory tupleFactory = TupleFactory.getInstance();
+ ArrayList<Object> objList = new ArrayList<Object>();
+ objList.add(t.get(j));
+ objList.add(t.get(j + 1));
+ Tuple expectedResult = tupleFactory.newTuple(objList);
assertEquals(POStatus.STATUS_OK, res.returnStatus);
assertEquals(expectedResult, res.result);
++j;
@@ -284,29 +257,29 @@ public class TestProject extends junit.
assertEquals(POStatus.STATUS_OK, res.returnStatus);
assertEquals(t.get(8), res.result);
}
-
+
@Test
public void testMissingCols1() throws Exception {
String inputFileName = "TestProject-testMissingCols1-input.txt";
String input[] = { "hello\tworld", "good\tbye" };
Util.createLocalInputFile(inputFileName, input);
- String query = "a = load '" + inputFileName + "' as (s1:chararray, s2:chararray, extra:chararray);" +
- "b = foreach a generate s1, s2, extra;";
-
+ String query = "a = load '" + inputFileName
+ + "' as (s1:chararray, s2:chararray, extra:chararray);" +
+ "b = foreach a generate s1, s2, extra;";
+
PigServer ps = new PigServer(ExecType.LOCAL);
Util.registerMultiLineQuery(ps, query);
Iterator<Tuple> it = ps.openIterator("b");
Tuple[] expectedResults = new Tuple[] {
- (Tuple) Util.getPigConstant("('hello', 'world', null)"),
- (Tuple) Util.getPigConstant("('good', 'bye', null)")
+ (Tuple)Util.getPigConstant("('hello', 'world', null)"),
+ (Tuple)Util.getPigConstant("('good', 'bye', null)")
};
int i = 0;
- while(it.hasNext()) {
+ while (it.hasNext()) {
assertEquals(expectedResults[i++], it.next());
}
}
-
-
+
@Test
public void testMissingCols2() throws Exception {
String inputFileName = "TestProject-testMissingCols2-input.txt";
@@ -315,22 +288,22 @@ public class TestProject extends junit.
// in the script, PigStorage will return a null for the tuple field
// since it does not comply with the schema
String query = "a = load '" + inputFileName + "' as (i:int, " +
- "t:tuple(s1:chararray, s2:chararray, s3:chararray));" +
+ "t:tuple(s1:chararray, s2:chararray, s3:chararray));" +
"b = foreach a generate t.(s2,s3);";
-
+
PigServer ps = new PigServer(ExecType.LOCAL);
Util.registerMultiLineQuery(ps, query);
Iterator<Tuple> it = ps.openIterator("b");
Tuple[] expectedResults = new Tuple[] {
- (Tuple) Util.getPigConstant("((null, null))"),
- (Tuple) Util.getPigConstant("((null, null))")
+ (Tuple)Util.getPigConstant("((null, null))"),
+ (Tuple)Util.getPigConstant("((null, null))")
};
int i = 0;
- while(it.hasNext()) {
+ while (it.hasNext()) {
assertEquals(expectedResults[i++], it.next());
}
}
-
+
@Test
public void testMissingCols3() throws Exception {
String inputFileName = "TestProject-testMissingCols3-input.txt";
@@ -339,24 +312,25 @@ public class TestProject extends junit.
String query = "a = load '" + inputFileName + "';" +
"b = group a all;" +
"c = foreach b generate flatten(a.($1, $2)),a.$2;";
-
+
PigServer ps = new PigServer(ExecType.LOCAL);
Util.registerMultiLineQuery(ps, query);
Iterator<Tuple> it = ps.openIterator("c");
Tuple[] expectedResults = new Tuple[] {
- (Tuple) Util.getPigConstant("('world', null, {(null),(null)})"),
- (Tuple) Util.getPigConstant("('bye', null, {(null),(null)})")
+ (Tuple)Util.getPigConstant("('world', null, {(null),(null)})"),
+ (Tuple)Util.getPigConstant("('bye', null, {(null),(null)})")
};
boolean contains0 = false;
boolean contains1 = false;
- while(it.hasNext()) {
+ while (it.hasNext()) {
String actualResult = it.next().toString();
if (actualResult.equals(expectedResults[0].toString()))
contains0 = true;
if (actualResult.equals(expectedResults[1].toString()))
contains1 = true;
}
- assertTrue(contains0&&contains1);
+ assertTrue(contains0);
+ assertTrue(contains1);
}
@Test
@@ -368,21 +342,20 @@ public class TestProject extends junit.
// second record since it does not comply with the schema and in the
// third record since the field is absent
String query = "a = load '" + inputFileName + "' as (i:int, " +
- "t:tuple(s1:chararray, s2:chararray));" +
+ "t:tuple(s1:chararray, s2:chararray));" +
"b = foreach a generate t.s1, t.s2;";
-
+
PigServer ps = new PigServer(ExecType.LOCAL);
Util.registerMultiLineQuery(ps, query);
Iterator<Tuple> it = ps.openIterator("b");
Tuple[] expectedResults = new Tuple[] {
- (Tuple) Util.getPigConstant("('hello', 'world')"),
- (Tuple) Util.getPigConstant("(null, null)"),
- (Tuple) Util.getPigConstant("(null, null)")
+ (Tuple)Util.getPigConstant("('hello', 'world')"),
+ (Tuple)Util.getPigConstant("(null, null)"),
+ (Tuple)Util.getPigConstant("(null, null)")
};
int i = 0;
- while(it.hasNext()) {
+ while (it.hasNext()) {
assertEquals(expectedResults[i++], it.next());
}
}
-
-}
+}
\ No newline at end of file
Modified: pig/trunk/test/org/apache/pig/test/TestRegexp.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestRegexp.java?rev=1407167&r1=1407166&r2=1407167&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestRegexp.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestRegexp.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,24 +15,25 @@
*/
package org.apache.pig.test;
+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 java.util.Map;
import java.util.Random;
-import junit.framework.TestCase;
-
import org.apache.pig.backend.executionengine.ExecException;
-import org.apache.pig.data.DataType;
-import org.apache.pig.impl.plan.OperatorKey;
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.BinaryComparisonOperator;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.ConstantExpression;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.*;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.PORegexp;
+import org.apache.pig.data.DataType;
+import org.apache.pig.impl.plan.OperatorKey;
import org.junit.Before;
import org.junit.Test;
-
-public class TestRegexp extends TestCase{
+public class TestRegexp {
Random r = new Random();
ConstantExpression lt, rt;
@@ -42,9 +41,9 @@ public class TestRegexp extends TestCase
@Before
public void setUp() throws Exception {
- lt = new ConstantExpression(new OperatorKey("",r.nextLong()));
+ lt = new ConstantExpression(new OperatorKey("", r.nextLong()));
lt.setResultType(DataType.CHARARRAY);
- rt = new ConstantExpression(new OperatorKey("",r.nextLong()));
+ rt = new ConstantExpression(new OperatorKey("", r.nextLong()));
rt.setResultType(DataType.CHARARRAY);
op = new PORegexp(new OperatorKey("", r.nextLong()));
op.setLhs(lt);
@@ -53,36 +52,35 @@ public class TestRegexp extends TestCase
}
@Test
- public void testMatches() throws ExecException{
+ public void testMatches() throws ExecException {
lt.setValue(new String(
- "The quick sly fox jumped over the lazy brown dog"));
+ "The quick sly fox jumped over the lazy brown dog"));
rt.setValue(".*s.y.*");
Result res = op.getNext(new Boolean(true));
assertEquals(POStatus.STATUS_OK, res.returnStatus);
assertTrue((Boolean)res.result);
-
+
// test with null in lhs
lt.setValue(null);
rt.setValue(".*s.y.*");
res = op.getNext(new Boolean(true));
- assertEquals(null, (Boolean)res.result);
-
+ assertNull(res.result);
+
// test with null in rhs
lt.setValue(new String(
- "The quick sly fox jumped over the lazy brown dog"));
+ "The quick sly fox jumped over the lazy brown dog"));
rt.setValue(null);
res = op.getNext(new Boolean(true));
- assertEquals(null, (Boolean)res.result);
+ assertNull(res.result);
}
@Test
- public void testDoesntMatch() throws ExecException{
+ public void testDoesntMatch() throws ExecException {
lt.setValue(new String(
- "The quick sly fox jumped over the lazy brown dog"));
+ "The quick sly fox jumped over the lazy brown dog"));
rt.setValue(new String("zzz"));
Result res = op.getNext(new Boolean(true));
assertEquals(POStatus.STATUS_OK, res.returnStatus);
assertFalse((Boolean)res.result);
}
}
-
Modified: pig/trunk/test/org/apache/pig/test/TestSecondarySort.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestSecondarySort.java?rev=1407167&r1=1407166&r2=1407167&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestSecondarySort.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestSecondarySort.java Thu Nov 8 17:06:46 2012
@@ -17,7 +17,9 @@
*/
package org.apache.pig.test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileOutputStream;
@@ -26,8 +28,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Random;
-import junit.framework.TestCase;
-
import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
import org.apache.pig.backend.executionengine.ExecException;
@@ -42,8 +42,6 @@ import org.apache.pig.impl.logicalLayer.
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
public class TestSecondarySort {
static MiniCluster cluster = MiniCluster.buildCluster();
@@ -55,7 +53,7 @@ public class TestSecondarySort {
try {
pc.connect();
} catch (ExecException e) {
- e.printStackTrace();
+ throw new RuntimeException(e);
}
}
@@ -103,9 +101,9 @@ public class TestSecondarySort {
SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
so.visit();
- assertTrue(so.getNumMRUseSecondaryKey() == 1);
- assertTrue(so.getNumSortRemoved() == 0);
- assertTrue(so.getDistinctChanged() == 1);
+ assertEquals(1, so.getNumMRUseSecondaryKey());
+ assertEquals(0, so.getNumSortRemoved());
+ assertEquals(1, so.getDistinctChanged());
}
@Test
@@ -122,9 +120,9 @@ public class TestSecondarySort {
SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
so.visit();
- assertTrue(so.getNumMRUseSecondaryKey() == 0);
- assertTrue(so.getNumSortRemoved() == 0);
- assertTrue(so.getDistinctChanged() == 1);
+ assertEquals(0, so.getNumMRUseSecondaryKey());
+ assertEquals(0, so.getNumSortRemoved());
+ assertEquals(1, so.getDistinctChanged());
}
@Test
@@ -141,9 +139,9 @@ public class TestSecondarySort {
SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
so.visit();
- assertTrue(so.getNumMRUseSecondaryKey() == 1);
- assertTrue(so.getNumSortRemoved() == 0);
- assertTrue(so.getDistinctChanged() == 2);
+ assertEquals(1, so.getNumMRUseSecondaryKey());
+ assertEquals(0, so.getNumSortRemoved());
+ assertEquals(2, so.getDistinctChanged());
}
@Test
@@ -179,9 +177,9 @@ public class TestSecondarySort {
SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
so.visit();
- assertTrue(so.getNumMRUseSecondaryKey() == 1);
- assertTrue(so.getNumSortRemoved() == 0);
- assertTrue(so.getDistinctChanged() == 1);
+ assertEquals(1, so.getNumMRUseSecondaryKey());
+ assertEquals(0, so.getNumSortRemoved());
+ assertEquals(1, so.getDistinctChanged());
}
@Test
@@ -198,9 +196,9 @@ public class TestSecondarySort {
SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
so.visit();
- assertTrue(so.getNumMRUseSecondaryKey() == 1);
- assertTrue(so.getNumSortRemoved() == 0);
- assertTrue(so.getDistinctChanged() == 1);
+ assertEquals(1, so.getNumMRUseSecondaryKey());
+ assertEquals(0, so.getNumSortRemoved());
+ assertEquals(1, so.getDistinctChanged());
}
@Test
@@ -217,9 +215,9 @@ public class TestSecondarySort {
SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
so.visit();
- assertTrue(so.getNumMRUseSecondaryKey() == 1);
- assertTrue(so.getNumSortRemoved() == 0);
- assertTrue(so.getDistinctChanged() == 1);
+ assertEquals(1, so.getNumMRUseSecondaryKey());
+ assertEquals(0, so.getNumSortRemoved());
+ assertEquals(1, so.getDistinctChanged());
}
@Test
@@ -236,9 +234,9 @@ public class TestSecondarySort {
SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
so.visit();
- assertTrue(so.getNumMRUseSecondaryKey() == 1);
- assertTrue(so.getNumSortRemoved() == 0);
- assertTrue(so.getDistinctChanged() == 1);
+ assertEquals(1, so.getNumMRUseSecondaryKey());
+ assertEquals(0, so.getNumSortRemoved());
+ assertEquals(1, so.getDistinctChanged());
}
@Test
@@ -255,9 +253,9 @@ public class TestSecondarySort {
SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
so.visit();
- assertTrue(so.getNumMRUseSecondaryKey() == 1);
- assertTrue(so.getNumSortRemoved() == 1);
- assertTrue(so.getDistinctChanged() == 0);
+ assertEquals(1, so.getNumMRUseSecondaryKey());
+ assertEquals(1, so.getNumSortRemoved());
+ assertEquals(0, so.getDistinctChanged());
}
@Test
@@ -274,9 +272,9 @@ public class TestSecondarySort {
SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
so.visit();
- assertTrue(so.getNumMRUseSecondaryKey() == 0);
- assertTrue(so.getNumSortRemoved() == 1);
- assertTrue(so.getDistinctChanged() == 0);
+ assertEquals(0, so.getNumMRUseSecondaryKey());
+ assertEquals(1, so.getNumSortRemoved());
+ assertEquals(0, so.getDistinctChanged());
}
@Test
@@ -293,9 +291,9 @@ public class TestSecondarySort {
SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
so.visit();
- assertTrue(so.getNumMRUseSecondaryKey() == 1);
- assertTrue(so.getNumSortRemoved() == 2);
- assertTrue(so.getDistinctChanged() == 0);
+ assertEquals(1, so.getNumMRUseSecondaryKey());
+ assertEquals(2, so.getNumSortRemoved());
+ assertEquals(0, so.getDistinctChanged());
}
@Test
@@ -312,9 +310,9 @@ public class TestSecondarySort {
SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
so.visit();
- assertTrue(so.getNumMRUseSecondaryKey() == 1);
- assertTrue(so.getNumSortRemoved() == 1);
- assertTrue(so.getDistinctChanged() == 0);
+ assertEquals(1, so.getNumMRUseSecondaryKey());
+ assertEquals(1, so.getNumSortRemoved());
+ assertEquals(0, so.getDistinctChanged());
}
@Test
@@ -330,9 +328,9 @@ public class TestSecondarySort {
SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
so.visit();
- assertTrue(so.getNumMRUseSecondaryKey() == 1);
- assertTrue(so.getNumSortRemoved() == 1);
- assertTrue(so.getDistinctChanged() == 0);
+ assertEquals(1, so.getNumMRUseSecondaryKey());
+ assertEquals(1, so.getNumSortRemoved());
+ assertEquals(0, so.getDistinctChanged());
}
@Test
@@ -349,9 +347,9 @@ public class TestSecondarySort {
SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
so.visit();
- assertTrue(so.getNumMRUseSecondaryKey() == 1);
- assertTrue(so.getNumSortRemoved() == 1);
- assertTrue(so.getDistinctChanged() == 0);
+ assertEquals(1, so.getNumMRUseSecondaryKey());
+ assertEquals(1, so.getNumSortRemoved());
+ assertEquals(0, so.getDistinctChanged());
}
@Test
@@ -368,9 +366,9 @@ public class TestSecondarySort {
SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
so.visit();
- assertTrue(so.getNumMRUseSecondaryKey() == 1);
- assertTrue(so.getNumSortRemoved() == 1);
- assertTrue(so.getDistinctChanged() == 0);
+ assertEquals(1, so.getNumMRUseSecondaryKey());
+ assertEquals(1, so.getNumSortRemoved());
+ assertEquals(0, so.getDistinctChanged());
}
// See PIG-1193
@@ -388,9 +386,9 @@ public class TestSecondarySort {
SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
so.visit();
- assertTrue(so.getNumMRUseSecondaryKey() == 1);
- assertTrue(so.getNumSortRemoved() == 2);
- assertTrue(so.getDistinctChanged() == 0);
+ assertEquals(1, so.getNumMRUseSecondaryKey());
+ assertEquals(2, so.getNumSortRemoved());
+ assertEquals(0, so.getDistinctChanged());
}
@Test
@@ -423,9 +421,9 @@ public class TestSecondarySort {
.registerQuery("D = foreach C { E = limit A 10; F = E.a1; G = DISTINCT F; generate group, COUNT(G);};");
Iterator<Tuple> iter = pigServer.openIterator("D");
assertTrue(iter.hasNext());
- assertTrue(iter.next().toString().equals("(2,1)"));
+ assertEquals("(2,1)", iter.next().toString());
assertTrue(iter.hasNext());
- assertTrue(iter.next().toString().equals("(1,2)"));
+ assertEquals("(1,2)", iter.next().toString());
assertFalse(iter.hasNext());
Util.deleteFile(cluster, file1ClusterPath);
Util.deleteFile(cluster, file2ClusterPath);
@@ -451,9 +449,9 @@ public class TestSecondarySort {
pigServer.registerQuery("C = foreach B { D = distinct A; generate group, D;};");
Iterator<Tuple> iter = pigServer.openIterator("C");
assertTrue(iter.hasNext());
- assertTrue(iter.next().toString().equals("(2,{(2,3,4)})"));
+ assertEquals("(2,{(2,3,4)})", iter.next().toString());
assertTrue(iter.hasNext());
- assertTrue(iter.next().toString().equals("(1,{(1,2,3),(1,2,4),(1,3,4)})"));
+ assertEquals("(1,{(1,2,3),(1,2,4),(1,3,4)})", iter.next().toString());
assertFalse(iter.hasNext());
Util.deleteFile(cluster, clusterPath);
}
@@ -469,7 +467,7 @@ public class TestSecondarySort {
ps1.println("1\t2\t4");
ps1.println("2\t3\t4");
ps1.close();
-
+
String expected[] = {
"(2,{(2,3,4)})",
"(1,{(1,2,3),(1,2,4),(1,2,4),(1,2,4),(1,3,4)})"
@@ -499,7 +497,7 @@ public class TestSecondarySort {
ps1.println("1\t8\t4");
ps1.println("2\t3\t4");
ps1.close();
-
+
String expected[] = {
"(2,{(2,3,4)})",
"(1,{(1,8,4),(1,4,4),(1,3,4),(1,2,3),(1,2,4)})"
@@ -554,7 +552,7 @@ public class TestSecondarySort {
Util.deleteFile(cluster, tmpFile1.getCanonicalPath());
Util.deleteFile(cluster, tmpFile2.getCanonicalPath());
}
-
+
@Test
public void testNestedSortMultiQueryEndToEnd1() throws Exception {
pigServer.setBatchOn();
@@ -571,13 +569,13 @@ public class TestSecondarySort {
List<ExecJob> jobs = pigServer.executeBatch();
for (ExecJob job : jobs) {
- assertTrue(job.getStatus() == ExecJob.JOB_STATUS.COMPLETED);
+ assertEquals(ExecJob.JOB_STATUS.COMPLETED, job.getStatus());
}
FileLocalizer.delete("/tmp/output1", pigServer.getPigContext());
FileLocalizer.delete("/tmp/output2", pigServer.getPigContext());
Util.deleteFile(cluster, "testNestedSortMultiQueryEndToEnd1-input.txt");
}
-
+
// See PIG-1978
@Test
public void testForEachTwoInput() throws Exception {
@@ -590,7 +588,7 @@ public class TestSecondarySort {
ps1.println("1\t2\t4");
ps1.println("2\t3\t4");
ps1.close();
-
+
String expected[] = {
"((1,2),{(2,3),(2,4),(2,4),(2,4)})",
"((1,3),{(3,4)})",
@@ -604,9 +602,10 @@ public class TestSecondarySort {
pigServer.registerQuery("C = foreach B { C1 = A.(a1,a2); generate group, C1;};");
Iterator<Tuple> iter = pigServer.openIterator("C");
Schema s = pigServer.dumpSchema("C");
-
+
Util.checkQueryOutputsAfterSortRecursive(iter, expected, org.apache.pig.newplan.logical.Util.translateSchema(s));
-
+
Util.deleteFile(cluster, tmpFile1.getCanonicalPath());
}
-}
\ No newline at end of file
+}
+