You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by da...@apache.org on 2014/05/30 21:07:29 UTC
svn commit: r1598702 [20/23] - in /pig/trunk: ./ ivy/
shims/src/hadoop23/org/apache/pig/backend/hadoop23/
shims/test/hadoop20/org/apache/pig/test/
shims/test/hadoop23/org/apache/pig/test/ src/META-INF/services/
src/org/apache/pig/ src/org/apache/pig/ba...
Modified: pig/trunk/test/org/apache/pig/test/TestPigServer.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestPigServer.java?rev=1598702&r1=1598701&r2=1598702&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestPigServer.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestPigServer.java Fri May 30 19:07:23 2014
@@ -56,6 +56,7 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.mapreduce.Job;
import org.apache.pig.ExecType;
+import org.apache.pig.PigConfiguration;
import org.apache.pig.PigServer;
import org.apache.pig.ResourceSchema;
import org.apache.pig.backend.executionengine.ExecException;
@@ -75,6 +76,7 @@ import org.apache.pig.tools.grunt.GruntP
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@@ -83,15 +85,14 @@ import org.w3c.dom.NodeList;
import com.google.common.io.Files;
public class TestPigServer {
- private PigServer pig = null;
- static MiniCluster cluster = MiniCluster.buildCluster();
+ private static Properties properties;
+ private static MiniGenericCluster cluster;
+
private File tempDir;
@Before
public void setUp() throws Exception{
- FileLocalizer.setInitialized(false);
- pig = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
-
+ Util.resetStateForExecModeSwitch();
tempDir = Files.createTempDir();
tempDir.deleteOnExit();
registerNewResource(tempDir.getAbsolutePath());
@@ -99,10 +100,15 @@ public class TestPigServer {
@After
public void tearDown() throws Exception{
- pig = null;
tempDir.delete();
}
+ @BeforeClass
+ public static void oneTimeSetup() {
+ cluster = MiniGenericCluster.buildCluster();
+ properties = cluster.getProperties();
+ }
+
@AfterClass
public static void oneTimeTearDown() throws Exception {
cluster.shutDown();
@@ -150,8 +156,7 @@ public class TestPigServer {
URL urlToAdd = new File(file).toURI().toURL();
URLClassLoader sysLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Method addMethod = URLClassLoader.class.
- getDeclaredMethod("addURL",
- new Class[]{URL.class});
+ getDeclaredMethod("addURL", new Class[]{URL.class});
addMethod.setAccessible(true);
addMethod.invoke(sysLoader, new Object[]{urlToAdd});
}
@@ -166,6 +171,7 @@ public class TestPigServer {
String jarName = "BadFileNameTestJarNotPresent.jar";
// jar name is not present to start with
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
verifyStringContained(pig.getPigContext().extraJars, jarName, false);
boolean raisedException = false;
try {
@@ -192,9 +198,10 @@ public class TestPigServer {
createFakeJarFile(jarLocation, jarName);
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
verifyStringContained(pig.getPigContext().extraJars, jarName, false);
- pig.registerJar(jarLocation + jarName);
+ pig.registerJar(jarLocation + jarName);
verifyStringContained(pig.getPigContext().extraJars, jarName, true);
// clean-up
@@ -221,12 +228,13 @@ public class TestPigServer {
createFakeJarFile(jarLocation1, jarName);
createFakeJarFile(jarLocation2, jarName);
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
verifyStringContained(pig.getPigContext().extraJars, jarName, false);
registerNewResource(jarLocation1);
registerNewResource(jarLocation2);
- pig.registerJar(jarName);
+ pig.registerJar(jarName);
verifyStringContained(pig.getPigContext().extraJars, jarName, true);
// clean-up
@@ -288,6 +296,7 @@ public class TestPigServer {
// load the specific resource
boolean exceptionRaised = false;
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
try {
pig.registerJar("sub_dir/TestRegisterJar.class");
}
@@ -314,7 +323,8 @@ public class TestPigServer {
createFakeJarFile(jarLocation, jar1Name);
createFakeJarFile(jarLocation, jar2Name);
- pig.registerJar(jarLocation + "TestRegisterJarGlobbing*.jar");
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
+ pig.registerJar(jarLocation + "TestRegisterJarGlobbing*.jar");
verifyStringContained(pig.getPigContext().extraJars, jar1Name, true);
verifyStringContained(pig.getPigContext().extraJars, jar2Name, true);
@@ -335,7 +345,8 @@ public class TestPigServer {
createFakeJarFile(jarLocation, jar2Name);
String currentDir = System.getProperty("user.dir");
- pig.registerJar(new File(currentDir, dir) + FILE_SEPARATOR + "TestRegisterJarGlobbing*.jar");
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
+ pig.registerJar(new File(currentDir, dir) + FILE_SEPARATOR + "TestRegisterJarGlobbing*.jar");
verifyStringContained(pig.getPigContext().extraJars, jar1Name, true);
verifyStringContained(pig.getPigContext().extraJars, jar2Name, true);
@@ -360,7 +371,8 @@ public class TestPigServer {
// depend on configuration
String absPath = fs.getFileStatus(new Path(jarLocation)).getPath().toString();
- pig.registerJar(absPath + FILE_SEPARATOR + "TestRegister{Remote}Jar*.jar");
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
+ pig.registerJar(absPath + FILE_SEPARATOR + "TestRegister{Remote}Jar*.jar");
verifyStringContained(pig.getPigContext().extraJars, jar1Name, true);
verifyStringContained(pig.getPigContext().extraJars, jar2Name, true);
@@ -370,6 +382,7 @@ public class TestPigServer {
}
public void testDescribeLoad() throws Throwable {
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
pig.registerQuery("a = load 'a' as (field1: int, field2: float, field3: chararray );") ;
Schema dumpedSchema = pig.dumpSchema("a") ;
Schema expectedSchema = Utils.getSchemaFromString("field1: int,field2: float,field3: chararray");
@@ -378,6 +391,7 @@ public class TestPigServer {
@Test
public void testDescribeFilter() throws Throwable {
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
pig.registerQuery("a = load 'a' as (field1: int, field2: float, field3: chararray );") ;
pig.registerQuery("b = filter a by field1 > 10;") ;
Schema dumpedSchema = pig.dumpSchema("b") ;
@@ -387,6 +401,7 @@ public class TestPigServer {
@Test
public void testDescribeDistinct() throws Throwable {
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
pig.registerQuery("a = load 'a' as (field1: int, field2: float, field3: chararray );") ;
pig.registerQuery("b = distinct a ;") ;
Schema dumpedSchema = pig.dumpSchema("b") ;
@@ -396,6 +411,7 @@ public class TestPigServer {
@Test
public void testDescribeSort() throws Throwable {
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
pig.registerQuery("a = load 'a' as (field1: int, field2: float, field3: chararray );") ;
pig.registerQuery("b = order a by * desc;") ;
Schema dumpedSchema = pig.dumpSchema("b") ;
@@ -405,6 +421,7 @@ public class TestPigServer {
@Test
public void testDescribeLimit() throws Throwable {
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
pig.registerQuery("a = load 'a' as (field1: int, field2: float, field3: chararray );") ;
pig.registerQuery("b = limit a 10;") ;
Schema dumpedSchema = pig.dumpSchema("b") ;
@@ -414,6 +431,7 @@ public class TestPigServer {
@Test
public void testDescribeForeach() throws Throwable {
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
pig.registerQuery("a = load 'a' as (field1: int, field2: float, field3: chararray );") ;
pig.registerQuery("b = foreach a generate field1 + 10;") ;
Schema dumpedSchema = pig.dumpSchema("b") ;
@@ -423,7 +441,7 @@ public class TestPigServer {
@Test
public void testDescribeForeachFail() throws Throwable {
-
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
pig.registerQuery("a = load 'a' as (field1: int, field2: float, field3: chararray );") ;
pig.registerQuery("b = foreach a generate field1 + 10;") ;
try {
@@ -436,6 +454,7 @@ public class TestPigServer {
@Test
public void testDescribeForeachNoSchema() throws Throwable {
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
pig.registerQuery("a = load 'a' ;") ;
pig.registerQuery("b = foreach a generate *;") ;
Schema dumpedSchema = pig.dumpSchema("b") ;
@@ -444,6 +463,7 @@ public class TestPigServer {
@Test
public void testDescribeCogroup() throws Throwable {
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
pig.registerQuery("a = load 'a' as (field1: int, field2: float, field3: chararray );") ;
pig.registerQuery("b = load 'b' as (field4, field5: double, field6: chararray );") ;
pig.registerQuery("c = cogroup a by field1, b by field4;") ;
@@ -454,6 +474,7 @@ public class TestPigServer {
@Test
public void testDescribeCross() throws Throwable {
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
pig.registerQuery("a = load 'a' as (field1: int, field2: float, field3: chararray );") ;
pig.registerQuery("b = load 'b' as (field4, field5: double, field6: chararray );") ;
pig.registerQuery("c = cross a, b;") ;
@@ -464,6 +485,7 @@ public class TestPigServer {
@Test
public void testDescribeJoin() throws Throwable {
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
pig.registerQuery("a = load 'a' as (field1: int, field2: float, field3: chararray );") ;
pig.registerQuery("b = load 'b' as (field4, field5: double, field6: chararray );") ;
pig.registerQuery("c = join a by field1, b by field4;") ;
@@ -474,6 +496,7 @@ public class TestPigServer {
@Test
public void testDescribeUnion() throws Throwable {
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
pig.registerQuery("a = load 'a' as (field1: int, field2: float, field3: chararray );") ;
pig.registerQuery("b = load 'b' as (field4, field5: double, field6: chararray );") ;
pig.registerQuery("c = union a, b;") ;
@@ -484,6 +507,7 @@ public class TestPigServer {
@Test
public void testDescribeTuple2Elem() throws Throwable {
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
pig.registerQuery("a = load 'a' as (field1: int, field2: int, field3: int );") ;
pig.registerQuery("b = foreach a generate field1, (field2, field3);") ;
Schema dumpedSchema = pig.dumpSchema("b") ;
@@ -493,6 +517,7 @@ public class TestPigServer {
@Test
public void testDescribeComplex() throws Throwable {
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
pig.registerQuery("a = load 'a' as (site: chararray, count: int, itemCounts: bag { itemCountsTuple: tuple (type: chararray, typeCount: int, f: float, m: map[]) } ) ;") ;
pig.registerQuery("b = foreach a generate site, count, FLATTEN(itemCounts);") ;
Schema dumpedSchema = pig.dumpSchema("b") ;
@@ -504,6 +529,7 @@ public class TestPigServer {
}
private void registerScalarScript(boolean useScalar, String expectedSchemaStr) throws IOException {
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
pig.registerQuery("A = load 'adata' AS (a: int, b: int);");
//scalar
pig.registerQuery("C = FOREACH A GENERATE *;");
@@ -533,6 +559,12 @@ public class TestPigServer {
@Test
public void testExplainXmlComplex() throws Throwable {
+ // TODO: Explain XML output is not supported in non-MR mode. Remove the
+ // following condition once it's implemented in Tez.
+ if (cluster.getExecType() != ExecType.MAPREDUCE) {
+ return;
+ }
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
pig.registerQuery("a = load 'a' as (site: chararray, count: int, itemCounts: bag { itemCountsTuple: tuple (type: chararray, typeCount: int, f: float, m: map[]) } ) ;") ;
pig.registerQuery("b = foreach a generate site, count, FLATTEN(itemCounts);") ;
pig.registerQuery("c = group b by site;");
@@ -614,6 +646,7 @@ public class TestPigServer {
String absPath = fs.getFileStatus(new Path(scriptName)).getPath().toString();
Util.createInputFile(cluster, "testRegisterRemoteScript_input", new String[]{"1", "2"});
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
pig.registerCode(absPath, "jython", "pig");
pig.registerQuery("a = load 'testRegisterRemoteScript_input';");
pig.registerQuery("b = foreach a generate pig.helloworld($0);");
@@ -631,26 +664,6 @@ public class TestPigServer {
assertFalse(iter.hasNext());
}
-
- // PIG-3469
- @Test
- public void testNonExistingSecondDirectoryInSkewJoin() throws Exception {
- String script =
- "exists = LOAD 'test/org/apache/pig/test/data/InputFiles/jsTst1.txt' AS (x:chararray, a:long);" +
- "missing = LOAD '/non/existing/directory' AS (a:long);" +
- "missing = FOREACH ( GROUP missing BY a ) GENERATE $0 AS a, COUNT_STAR($1);" +
- "joined = JOIN exists BY a, missing BY a USING 'skewed';" +
- "STORE joined INTO '/tmp/test_out.tsv';";
-
- PigServer pig = new PigServer(ExecType.LOCAL);
- // Execution of the script should fail, but without throwing any exceptions (such as NPE)
- try {
- pig.registerScript(new ByteArrayInputStream(script.getBytes("UTF-8")));
- } catch(Exception ex) {
- fail("Unexpected exception: " + ex);
- }
- }
-
@Test
public void testParamSubstitution() throws Exception{
// using params map
@@ -822,6 +835,7 @@ public class TestPigServer {
@Test
public void testDescribeForEachFlatten() throws Throwable {
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
pig.registerQuery("a = load 'a';") ;
pig.registerQuery("b = group a by $0;") ;
pig.registerQuery("c = foreach b generate flatten(a);") ;
@@ -831,7 +845,8 @@ public class TestPigServer {
@Test // PIG-2059
public void test1() throws Throwable {
- pig.setValidateEachStatement(true);
+ PigServer pig = new PigServer(cluster.getExecType(), properties);
+ pig.setValidateEachStatement(true);
pig.registerQuery("A = load 'x' as (u, v);") ;
try {
pig.registerQuery("B = foreach A generate $2;") ;
@@ -844,40 +859,40 @@ public class TestPigServer {
}
@Test
- public void testDefaultPigProperties() throws Throwable {
- //Test with PigServer
- PigServer pigServer = new PigServer(ExecType.MAPREDUCE);
- Properties properties = pigServer.getPigContext().getProperties();
+ public void testDefaultPigProperties() throws Throwable {
+ //Test with PigServer
+ PigServer pigServer = new PigServer(cluster.getExecType());
+ Properties properties = pigServer.getPigContext().getProperties();
assertEquals("999", properties.getProperty("pig.exec.reducers.max"));
assertEquals("true", properties.getProperty("aggregate.warning"));
- assertEquals("true", properties.getProperty("opt.multiquery"));
+ assertEquals("true", properties.getProperty(PigConfiguration.OPT_MULTIQUERY));
assertEquals("false", properties.getProperty("stop.on.failure"));
- //Test with properties file
- File propertyFile = new File(tempDir, "pig.properties");
+ //Test with properties file
+ File propertyFile = new File(tempDir, "pig.properties");
- properties = PropertiesUtil.loadDefaultProperties();
+ properties = PropertiesUtil.loadDefaultProperties();
- assertEquals("999", properties.getProperty("pig.exec.reducers.max"));
+ assertEquals("999", properties.getProperty("pig.exec.reducers.max"));
assertEquals("true", properties.getProperty("aggregate.warning"));
- assertEquals("true", properties.getProperty("opt.multiquery"));
+ assertEquals("true", properties.getProperty(PigConfiguration.OPT_MULTIQUERY));
assertEquals("false", properties.getProperty("stop.on.failure"));
- PrintWriter out = new PrintWriter(new FileWriter(propertyFile));
- out.println("aggregate.warning=false");
- out.println("opt.multiquery=false");
- out.println("stop.on.failure=true");
-
- out.close();
-
- properties = PropertiesUtil.loadDefaultProperties();
- assertEquals("false", properties.getProperty("aggregate.warning"));
- assertEquals("false", properties.getProperty("opt.multiquery"));
- assertEquals("true", properties.getProperty("stop.on.failure"));
+ PrintWriter out = new PrintWriter(new FileWriter(propertyFile));
+ out.println("aggregate.warning=false");
+ out.println("opt.multiquery=false");
+ out.println("stop.on.failure=true");
+
+ out.close();
+
+ properties = PropertiesUtil.loadDefaultProperties();
+ assertEquals("false", properties.getProperty("aggregate.warning"));
+ assertEquals("false", properties.getProperty(PigConfiguration.OPT_MULTIQUERY));
+ assertEquals("true", properties.getProperty("stop.on.failure"));
- propertyFile.delete();
- }
+ propertyFile.delete();
+ }
@Test
public void testSecondarySort() throws Exception {
Modified: pig/trunk/test/org/apache/pig/test/TestPigServerWithMacros.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestPigServerWithMacros.java?rev=1598702&r1=1598701&r2=1598702&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestPigServerWithMacros.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestPigServerWithMacros.java Fri May 30 19:07:23 2014
@@ -39,10 +39,16 @@ import org.apache.pig.PigServer;
import org.apache.pig.builtin.mock.Storage;
import org.apache.pig.data.Tuple;
import org.junit.AfterClass;
+import org.junit.Before;
import org.junit.Test;
public class TestPigServerWithMacros {
- private static MiniCluster cluster = MiniCluster.buildCluster();
+ private static MiniGenericCluster cluster = MiniGenericCluster.buildCluster();
+
+ @Before
+ public void setup() throws Exception {
+ Util.resetStateForExecModeSwitch();
+ }
@AfterClass
public static void tearDown() throws Exception {
@@ -51,7 +57,7 @@ public class TestPigServerWithMacros {
@Test
public void testRegisterRemoteMacro() throws Throwable {
- PigServer pig = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
+ PigServer pig = new PigServer(cluster.getExecType(), cluster.getProperties());
String macroName = "util.pig";
File macroFile = File.createTempFile("tmp", "");
@@ -94,42 +100,42 @@ public class TestPigServerWithMacros {
pig.shutdown();
}
-
+
@Test
public void testRegisterResourceMacro() throws Throwable {
PigServer pig = new PigServer(ExecType.LOCAL);
String macrosFile = "test/pig/macros.pig";
File macrosJarFile = File.createTempFile("macros", ".jar");
-
+
System.out.println("Creating macros jar " + macrosJarFile);
-
+
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
-
+
JarOutputStream jarStream = new JarOutputStream(new FileOutputStream(macrosJarFile), manifest);
-
+
JarEntry jarEntry = new JarEntry(macrosFile);
jarEntry.setTime(System.currentTimeMillis());
- jarStream.putNextEntry(jarEntry);
-
+ jarStream.putNextEntry(jarEntry);
+
PrintWriter pw = new PrintWriter(jarStream);
pw.println("DEFINE row_count_in_jar(X) RETURNS Z { Y = group $X all; $Z = foreach Y generate COUNT($X); };");
- pw.close();
-
+ pw.close();
+
jarStream.close();
-
+
Storage.Data data = resetData(pig);
data.set("some_path", "(l:int)", tuple(tuple("1")), tuple(tuple("2")), tuple(tuple("3")), tuple(tuple("10")), tuple(tuple("11")));
-
+
System.out.println("Registering macros jar " + macrosJarFile);
pig.registerJar(macrosJarFile.toString());
-
+
pig.registerQuery("import '" + macrosFile + "';");
pig.registerQuery("a = load 'some_path' USING mock.Storage();");
pig.registerQuery("b = row_count_in_jar(a);");
Iterator<Tuple> iter = pig.openIterator("b");
-
+
assertTrue(((Long)iter.next().get(0))==5);
pig.shutdown();
Modified: pig/trunk/test/org/apache/pig/test/TestPigStorage.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestPigStorage.java?rev=1598702&r1=1598701&r2=1598702&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestPigStorage.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestPigStorage.java Fri May 30 19:07:23 2014
@@ -18,24 +18,24 @@
package org.apache.pig.test;
-import static org.apache.pig.ExecType.MAPREDUCE;
import static org.apache.pig.builtin.mock.Storage.tuple;
-import static org.junit.Assert.*;
+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 static org.junit.Assert.fail;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import org.apache.commons.io.FileUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.Job;
import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
@@ -59,25 +59,22 @@ import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
public class TestPigStorage {
-
- protected final Log log = LogFactory.getLog(getClass());
-
- private static MiniCluster cluster = MiniCluster.buildCluster();
- static PigServer pig;
- static final String datadir = "build/test/tmpdata/";
-
- PigContext pigContext = new PigContext(ExecType.LOCAL, new Properties());
- Map<String, String> fileNameMap = new HashMap<String, String>();
+ private static PigServer pig;
+ private static PigContext pigContext;
+ private static Properties properties;
+ private static MiniGenericCluster cluster;
+ private static final String datadir = "build/test/tmpdata/";
@Before
public void setup() throws IOException {
// some tests are in map-reduce mode and some in local - so before
- // each test, we will de-initialize FileLocalizer so that temp files
+ // each test, we will re-initialize FileLocalizer so that temp files
// are created correctly depending on the ExecType in the test.
- FileLocalizer.setInitialized(false);
+ Util.resetStateForExecModeSwitch();
// If needed, a test can change that. Most tests are local so we save a bit
// of typing here.
@@ -99,6 +96,13 @@ public class TestPigStorage {
pig.shutdown();
}
+ @BeforeClass
+ public static void oneTimeSetup() {
+ cluster = MiniGenericCluster.buildCluster();
+ properties = cluster.getProperties();
+ pigContext = new PigContext(ExecType.LOCAL, new Properties());
+ }
+
@AfterClass
public static void shutdown() {
cluster.shutDown();
@@ -120,11 +124,12 @@ public class TestPigStorage {
// This tests PigStorage loader with records exactly
// on the boundary of the file blocks.
Properties props = new Properties();
- for (Entry<Object, Object> entry : cluster.getProperties().entrySet()) {
+ for (Entry<Object, Object> entry : properties.entrySet()) {
props.put(entry.getKey(), entry.getValue());
}
props.setProperty("mapred.max.split.size", "20");
- PigServer pigServer = new PigServer(MAPREDUCE, props);
+ Util.resetStateForExecModeSwitch();
+ PigServer pigServer = new PigServer(cluster.getExecType(), props);
String[] inputs = {
"abcdefgh1", "abcdefgh2", "abcdefgh3",
"abcdefgh4", "abcdefgh5", "abcdefgh6",
@@ -191,7 +196,7 @@ public class TestPigStorage {
inputFileName,
new String[] {"1\t2\t3", "4", "5\t6\t7"});
String script = "a = load '" + inputFileName + "' as (i:int, j:int, k:int);" +
- "b = foreach a generate j, k;";
+ "b = foreach a generate j, k;";
Util.registerMultiLineQuery(pig, script);
Iterator<Tuple> it = pig.openIterator("b");
assertEquals(Util.createTuple(new Integer[] { 2, 3}), it.next());
@@ -261,17 +266,17 @@ public class TestPigStorage {
"as (f1:chararray, f2:int);";
pig.registerQuery(query);
pig.store("a", datadir + "aout", "PigStorage('\\t', '-schema')");
-
+
// aout now has a schema.
-
+
// Verify that loaded data has the correct data type after the prune
pig.registerQuery("b = LOAD '" + datadir + "aout' using PigStorage('\\t'); c = FOREACH b GENERATE f2;");
-
+
Iterator<Tuple> it = pig.openIterator("c");
Assert.assertTrue("results were produced", it.hasNext());
-
+
Tuple t = it.next();
-
+
Assert.assertTrue("data is correct type", t.get(0) instanceof Integer);
}
@@ -355,7 +360,7 @@ public class TestPigStorage {
@Test
public void testSchemaDataNotMatchWITHCast() throws Exception {
pig.registerQuery("A = LOAD '" + datadir + "originput' using PigStorage(',') as (x:chararray);");
-
+
List<Tuple> expectedResults = Util.getTuplesFromConstantTupleStrings(
new String[] {
"('A')",
@@ -376,7 +381,7 @@ public class TestPigStorage {
@Test
public void testSchemaDataNotMatchNOCast() throws Exception {
pig.registerQuery("A = LOAD '" + datadir + "originput' using PigStorage(',') as (x:bytearray);");
-
+
List<Tuple> expectedResults = Util.getTuplesFromConstantTupleStrings(
new String[] {
"('A')",
@@ -397,7 +402,7 @@ public class TestPigStorage {
@Test
public void testSchemaDataNotMatchAsEXTRACoumns() throws Exception {
pig.registerQuery("A = LOAD '" + datadir + "originput' using PigStorage(',') as (x,y,z);");
-
+
List<Tuple> expectedResults = Util.getTuplesFromConstantTupleStrings(
new String[] {
"('A',1,NULL)",
@@ -521,6 +526,7 @@ public class TestPigStorage {
new ObjectMapper().writeValue(new File(schemaFilename), testSchema);
}
+ @SuppressWarnings("deprecation")
@Test
public void testPigStorageSchemaSearch() throws Exception {
String globtestdir = "build/test/tmpglobbingdata/";
@@ -537,40 +543,41 @@ public class TestPigStorage {
pig.mkdirs(globtestdir+"b");
} catch (IOException e) {};
+ Configuration conf = ConfigurationUtil.toConfiguration(pigContext.getProperties());
// if schema file is not found, schema is null
- ResourceSchema schema = pigStorage.getSchema(globtestdir, new Job(ConfigurationUtil.toConfiguration(pigContext.getProperties())));
+ ResourceSchema schema = pigStorage.getSchema(globtestdir, new Job(conf));
Assert.assertTrue(schema==null);
// if .pig_schema is in the input directory
putSchemaFile(globtestdir+"a/a0/.pig_schema", testSchema);
- schema = pigStorage.getSchema(globtestdir+"a/a0", new Job(ConfigurationUtil.toConfiguration(pigContext.getProperties())));
+ schema = pigStorage.getSchema(globtestdir+"a/a0", new Job(conf));
Assert.assertTrue(ResourceSchema.equals(schema, testSchema));
new File(globtestdir+"a/a0/.pig_schema").delete();
// .pig_schema in one of globStatus returned directory
putSchemaFile(globtestdir+"a/.pig_schema", testSchema);
- schema = pigStorage.getSchema(globtestdir+"*", new Job(ConfigurationUtil.toConfiguration(pigContext.getProperties())));
+ schema = pigStorage.getSchema(globtestdir+"*", new Job(conf));
Assert.assertTrue(ResourceSchema.equals(schema, testSchema));
new File(globtestdir+"a/.pig_schema").delete();
putSchemaFile(globtestdir+"b/.pig_schema", testSchema);
- schema = pigStorage.getSchema(globtestdir+"*", new Job(ConfigurationUtil.toConfiguration(pigContext.getProperties())));
+ schema = pigStorage.getSchema(globtestdir+"*", new Job(conf));
Assert.assertTrue(ResourceSchema.equals(schema, testSchema));
new File(globtestdir+"b/.pig_schema").delete();
// if .pig_schema is deep in the globbing, it will not get used
putSchemaFile(globtestdir+"a/a0/.pig_schema", testSchema);
- schema = pigStorage.getSchema(globtestdir+"*", new Job(ConfigurationUtil.toConfiguration(pigContext.getProperties())));
+ schema = pigStorage.getSchema(globtestdir+"*", new Job(conf));
Assert.assertTrue(schema==null);
putSchemaFile(globtestdir+"a/.pig_schema", testSchema);
- schema = pigStorage.getSchema(globtestdir+"*", new Job(ConfigurationUtil.toConfiguration(pigContext.getProperties())));
+ schema = pigStorage.getSchema(globtestdir+"*", new Job(conf));
Assert.assertTrue(ResourceSchema.equals(schema, testSchema));
new File(globtestdir+"a/a0/.pig_schema").delete();
new File(globtestdir+"a/.pig_schema").delete();
pigStorage = new PigStorage("\t", "-schema");
putSchemaFile(globtestdir+"a/.pig_schema", testSchema);
- schema = pigStorage.getSchema(globtestdir+"{a,b}", new Job(ConfigurationUtil.toConfiguration(pigContext.getProperties())));
+ schema = pigStorage.getSchema(globtestdir+"{a,b}", new Job(conf));
Assert.assertTrue(ResourceSchema.equals(schema, testSchema));
}
@@ -677,7 +684,7 @@ public class TestPigStorage {
assertTrue(it.hasNext());
assertEquals(tuple(1,null,null), it.next());
assertFalse(it.hasNext());
-
+
// Now, test with prune
pig.registerQuery("a = load '"+Util.encodeEscape(inputDir.getAbsolutePath())+"'; b = foreach a generate y, z;");
it = pig.openIterator("b");
@@ -726,5 +733,5 @@ public class TestPigStorage {
pig.store("a", datadir + "aout", "PigStorage(',')");
pig.store("a", datadir + "aout", "PigStorage(',')");
}
-
+
}
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=1598702&r1=1598701&r2=1598702&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestPoissonSampleLoader.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestPoissonSampleLoader.java Fri May 30 19:07:23 2014
@@ -29,7 +29,6 @@ import org.apache.pig.PigServer;
import org.apache.pig.backend.executionengine.ExecException;
import org.apache.pig.data.Tuple;
import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
@@ -37,7 +36,6 @@ 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 {
pigServer = new PigServer(ExecType.LOCAL);
@@ -55,11 +53,6 @@ public class TestPoissonSampleLoader {
createFiles();
}
- @AfterClass
- public static void oneTimeTearDown() throws Exception {
- cluster.shutDown();
- }
-
private void createFiles() throws IOException {
PrintWriter w = new PrintWriter(new FileWriter(INPUT_FILE1));
@@ -75,30 +68,11 @@ public class TestPoissonSampleLoader {
w.close();
- Util.copyFromLocalToCluster(cluster, INPUT_FILE1, INPUT_FILE1);
}
@After
public void tearDown() throws Exception {
new File(INPUT_FILE1).delete();
-
- Util.deleteFile(cluster, INPUT_FILE1);
- }
-
- 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');");
- Iterator<Tuple> iter = pigServer.openIterator("A");
- int count = 0;
- while (iter.hasNext()) {
- count++;
- iter.next();
- }
- return count;
}
/*
Modified: pig/trunk/test/org/apache/pig/test/TestRegisteredJarVisibility.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestRegisteredJarVisibility.java?rev=1598702&r1=1598701&r2=1598702&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestRegisteredJarVisibility.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestRegisteredJarVisibility.java Fri May 30 19:07:23 2014
@@ -44,6 +44,7 @@ import org.apache.pig.PigServer;
import org.apache.pig.impl.util.JarManager;
import org.junit.AfterClass;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -62,7 +63,7 @@ public class TestRegisteredJarVisibility
// Actual data is not important. Reusing an existing input file.
private static final File INPUT_FILE = new File("test/data/pigunit/top_queries_input_data.txt");
- private static MiniCluster cluster;
+ private static MiniGenericCluster cluster;
private static File jarFile;
@BeforeClass()
@@ -95,7 +96,7 @@ public class TestRegisteredJarVisibility
jar(filesToJar);
- cluster = MiniCluster.buildCluster();
+ cluster = MiniGenericCluster.buildCluster();
Util.copyFromLocalToCluster(cluster, INPUT_FILE.getPath(), INPUT_FILE.getName());
}
@@ -104,6 +105,11 @@ public class TestRegisteredJarVisibility
cluster.shutDown();
}
+ @Before
+ public void setup() {
+ Util.resetStateForExecModeSwitch();
+ }
+
@Test()
public void testRegisteredJarVisibilitySchemaNotOnClasspath() {
boolean exceptionThrown = false;
@@ -114,10 +120,10 @@ public class TestRegisteredJarVisibility
}
Assert.assertTrue(exceptionThrown);
}
-
+
@Test
public void testRegisterJarVisibilityMR() throws IOException {
- PigServer pigServer = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
+ PigServer pigServer = new PigServer(cluster.getExecType(), cluster.getProperties());
testRegisteredJarVisibility(pigServer, INPUT_FILE.getName());
}
@@ -126,7 +132,7 @@ public class TestRegisteredJarVisibility
PigServer pigServer = new PigServer(ExecType.LOCAL, new Properties());
testRegisteredJarVisibility(pigServer, INPUT_FILE.getAbsolutePath());
}
-
+
public void testRegisteredJarVisibility(PigServer pigServer, String inputPath) throws IOException {
String query = "register " + jarFile.getAbsolutePath() + ";\n"
+ "a = load '" + inputPath
Modified: pig/trunk/test/org/apache/pig/test/TestSample.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestSample.java?rev=1598702&r1=1598701&r2=1598702&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestSample.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestSample.java Fri May 30 19:07:23 2014
@@ -23,7 +23,6 @@ import java.io.File;
import java.io.IOException;
import java.util.Iterator;
-import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
import org.apache.pig.data.Tuple;
import org.apache.pig.impl.logicalLayer.FrontendException;
@@ -38,13 +37,13 @@ public class TestSample {
private String tmpfilepath;
private int DATALEN = 1024;
- static MiniCluster cluster = MiniCluster.buildCluster();
-
+ static MiniGenericCluster cluster = MiniGenericCluster.buildCluster();
+
@Before
public void setUp()
throws Exception
{
- pig = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
+ pig = new PigServer(cluster.getExecType(), cluster.getProperties());
tmpFile = File.createTempFile( this.getClass().getName(), ".txt");
tmpFile.delete(); // we don't want the file, just the temp path
@@ -65,7 +64,7 @@ public class TestSample {
{
Util.deleteFile(cluster, tmpfilepath);
}
-
+
@AfterClass
public static void oneTimeTearDown() throws Exception {
cluster.shutDown();
@@ -109,7 +108,7 @@ public class TestSample {
{
verify("myid = sample (load '"+ Util.encodeEscape(tmpfilepath) + "') 0.5;", DATALEN/3, DATALEN*2/3);
}
-
+
@Test
public void testSample_VariableNone() throws Exception {
verify("a = LOAD '" + Util.encodeEscape(tmpfilepath) + "'; " +
@@ -117,7 +116,7 @@ public class TestSample {
"c = FOREACH b GENERATE COUNT(a) AS count;" +
"myid = SAMPLE a (c.count - c.count);", 0, 0);
}
-
+
@Test
public void testSample_VariableAll() throws Exception {
verify("a = LOAD '" + Util.encodeEscape(tmpfilepath) + "'; " +
@@ -125,7 +124,7 @@ public class TestSample {
"c = FOREACH b GENERATE COUNT(a) AS count;" +
"myid = SAMPLE a 1.0 * (c.count / c.count) PARALLEL 2;", DATALEN, DATALEN); // test for PIG-2156
}
-
+
@Test
public void testSample_VariableSome() throws Exception {
verify("a = LOAD '" + Util.encodeEscape(tmpfilepath) + "'; " +
@@ -133,11 +132,11 @@ public class TestSample {
"c = FOREACH b GENERATE COUNT(a) AS count;" +
"myid = SAMPLE a (c.count / (2.0 * c.count) );", DATALEN/3, DATALEN*2/3);
}
-
+
@Test(expected=FrontendException.class)
public void testSampleScalarException() throws IOException {
- String query =
- "a = load '" + Util.encodeEscape(tmpfilepath) + "';" +
+ String query =
+ "a = load '" + Util.encodeEscape(tmpfilepath) + "';" +
"b = sample a $0;" // reference to non scalar context is not allowed
;
Modified: pig/trunk/test/org/apache/pig/test/TestSchema.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestSchema.java?rev=1598702&r1=1598701&r2=1598702&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestSchema.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestSchema.java Fri May 30 19:07:23 2014
@@ -29,7 +29,6 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
import org.apache.pig.ResourceSchema;
import org.apache.pig.data.DataType;
@@ -613,6 +612,7 @@ public class TestSchema {
assertFalse(Schema.equals(bagSchema1, bagSchema2, false, false));
}
+ @Test
public void testCharArray2Numeric(){
byte[] numbericTypes=new byte[]{DataType.DOUBLE,DataType.FLOAT,DataType.LONG,DataType.INTEGER};
Schema.FieldSchema inputFieldSchema=new Schema.FieldSchema("",DataType.CHARARRAY);
@@ -622,9 +622,10 @@ public class TestSchema {
}
}
+ @Test
public void testSchemaSerialization() throws IOException {
- MiniCluster cluster = MiniCluster.buildCluster();
- PigServer pigServer = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
+ MiniGenericCluster cluster = MiniGenericCluster.buildCluster();
+ PigServer pigServer = new PigServer(cluster.getExecType(), cluster.getProperties());
String inputFileName = "testSchemaSerialization-input.txt";
String[] inputData = new String[] { "foo\t1", "hello\t2" };
Util.createInputFile(cluster, inputFileName, inputData);
Modified: pig/trunk/test/org/apache/pig/test/TestScriptLanguageJavaScript.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestScriptLanguageJavaScript.java?rev=1598702&r1=1598701&r2=1598702&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestScriptLanguageJavaScript.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestScriptLanguageJavaScript.java Fri May 30 19:07:23 2014
@@ -26,7 +26,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
import org.apache.pig.scripting.ScriptEngine;
import org.apache.pig.tools.pigstats.PigStats;
@@ -38,7 +37,7 @@ import org.junit.Test;
public class TestScriptLanguageJavaScript {
- static MiniCluster cluster = MiniCluster.buildCluster();
+ static MiniGenericCluster cluster = MiniGenericCluster.buildCluster();
private PigServer pigServer;
@BeforeClass
@@ -53,8 +52,7 @@ public class TestScriptLanguageJavaScrip
@Before
public void setUp() throws Exception {
- pigServer = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
-// pigServer = new PigServer(ExecType.LOCAL);
+ pigServer = new PigServer(cluster.getExecType(), cluster.getProperties());
}
@After
Modified: pig/trunk/test/org/apache/pig/test/TestScriptUDF.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestScriptUDF.java?rev=1598702&r1=1598701&r2=1598702&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestScriptUDF.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestScriptUDF.java Fri May 30 19:07:23 2014
@@ -20,35 +20,33 @@ package org.apache.pig.test;
import java.io.File;
import java.util.Iterator;
-import junit.framework.Assert;
-
import org.apache.hadoop.util.Shell;
-import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
import org.apache.pig.data.BagFactory;
import org.apache.pig.data.Tuple;
import org.apache.pig.data.TupleFactory;
import org.junit.AfterClass;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class TestScriptUDF{
- static MiniCluster cluster = MiniCluster.buildCluster();
+ static MiniGenericCluster cluster = MiniGenericCluster.buildCluster();
private PigServer pigServer;
TupleFactory mTf = TupleFactory.getInstance();
BagFactory mBf = BagFactory.getInstance();
-
+
@Before
public void setUp() throws Exception{
- pigServer = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
+ pigServer = new PigServer(cluster.getExecType(), cluster.getProperties());
}
-
+
@AfterClass
public static void oneTimeTearDown() throws Exception {
cluster.shutDown();
}
-
+
// See PIG-928
@Test
public void testJavascriptExampleScript() throws Exception{
@@ -132,7 +130,7 @@ public class TestScriptUDF{
t = iter.next();
Assert.assertTrue(t.toString().equals("(9)"));
-
+
Assert.assertFalse(iter.hasNext());
}
@@ -143,7 +141,7 @@ public class TestScriptUDF{
* to use a jython install, the Lib dir must be in the jython search path
* via env variable JYTHON_HOME=jy_home or JYTHONPATH=jy_home/Lib:... or
* jython-standalone.jar should be in the classpath
- *
+ *
* Left in for now as we don't have paths to include other scripts in a
* script in the e2e harness.
*
@@ -156,7 +154,7 @@ public class TestScriptUDF{
@Test
public void testPythonNestedImportClassPath() throws Exception {
- // Use different names for the script as PythonInterpreter is static in JythonScriptEngine
+ // Use different names for the script as PythonInterpreter is static in JythonScriptEngine
testPythonNestedImport("build/classes", "scriptC.py", "scriptD.py");
}
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=1598702&r1=1598701&r2=1598702&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestSecondarySort.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestSecondarySort.java Fri May 30 19:07:23 2014
@@ -27,45 +27,52 @@ import java.io.PrintStream;
import java.util.Iterator;
import java.util.List;
-import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
import org.apache.pig.backend.executionengine.ExecException;
import org.apache.pig.backend.executionengine.ExecJob;
-import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.SecondaryKeyOptimizer;
-import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.plans.MROperPlan;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhysicalPlan;
+import org.apache.pig.backend.hadoop.executionengine.optimizer.SecondaryKeyOptimizer;
import org.apache.pig.data.Tuple;
import org.apache.pig.impl.PigContext;
import org.apache.pig.impl.io.FileLocalizer;
import org.apache.pig.impl.logicalLayer.schema.Schema;
+import org.apache.pig.impl.plan.VisitorException;
import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
-public class TestSecondarySort {
- static MiniCluster cluster = MiniCluster.buildCluster();
- private PigServer pigServer;
-
- static PigContext pc;
- static {
- pc = new PigContext(ExecType.MAPREDUCE, MiniCluster.buildCluster().getProperties());
- try {
- pc.connect();
- } catch (ExecException e) {
- throw new RuntimeException(e);
- }
- }
+// ant sends abstract classes also to junit. skipNonTests attribute does not work with all ant versions
+@Ignore
+public abstract class TestSecondarySort {
+ protected static MiniGenericCluster cluster = null;
+ protected PigServer pigServer;
+ protected static PigContext pc;
@AfterClass
public static void oneTimeTearDown() throws Exception {
cluster.shutDown();
+ cluster = null;
}
@Before
public void setUp() throws Exception {
- pigServer = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
+ if (cluster == null) {
+ cluster = getCluster();
+ pc = new PigContext(cluster.getExecType(), cluster.getProperties());
+ try {
+ pc.connect();
+ } catch (ExecException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ pigServer = new PigServer(pc);
}
+ public abstract SecondaryKeyOptimizer visitSecondaryKeyOptimizer(
+ String query) throws Exception, VisitorException;
+
+ public abstract MiniGenericCluster getCluster();
+
@Test
public void testDistinctOptimization1() throws Exception {
// Distinct on one entire input
@@ -74,15 +81,11 @@ public class TestSecondarySort {
"C = foreach B { D = distinct A; generate group, D;};"+
"store C into 'output';");
- PhysicalPlan pp = Util.buildPp(pigServer, query);
- MROperPlan mrPlan = Util.buildMRPlan(pp, pc);
+ SecondaryKeyOptimizer so = visitSecondaryKeyOptimizer(query);
- SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
- so.visit();
-
- assertEquals(1, so.getNumMRUseSecondaryKey());
+ assertEquals(1, so.getNumUseSecondaryKey());
assertEquals(0, so.getNumSortRemoved());
- assertEquals(1, so.getDistinctChanged());
+ assertEquals(1, so.getNumDistinctChanged());
}
@Test
@@ -93,15 +96,11 @@ public class TestSecondarySort {
"C = foreach B { D = limit A 10; E = order D by $1; generate group, E;};" +
"store C into 'output';");
- PhysicalPlan pp = Util.buildPp(pigServer, query);
- MROperPlan mrPlan = Util.buildMRPlan(pp, pc);
-
- SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
- so.visit();
+ SecondaryKeyOptimizer so = visitSecondaryKeyOptimizer(query);
- assertEquals(1, so.getNumMRUseSecondaryKey());
+ assertEquals(1, so.getNumUseSecondaryKey());
assertEquals(1, so.getNumSortRemoved());
- assertEquals(0, so.getDistinctChanged());
+ assertEquals(0, so.getNumDistinctChanged());
}
@Test
@@ -112,15 +111,11 @@ public class TestSecondarySort {
"C = foreach B { D = limit A 10; E = order D by $0; generate group, E;};" +
"store C into 'output';");
- PhysicalPlan pp = Util.buildPp(pigServer, query);
- MROperPlan mrPlan = Util.buildMRPlan(pp, pc);
+ SecondaryKeyOptimizer so = visitSecondaryKeyOptimizer(query);
- SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
- so.visit();
-
- assertEquals(0, so.getNumMRUseSecondaryKey());
+ assertEquals(0, so.getNumUseSecondaryKey());
assertEquals(1, so.getNumSortRemoved());
- assertEquals(0, so.getDistinctChanged());
+ assertEquals(0, so.getNumDistinctChanged());
}
@Test
@@ -131,15 +126,11 @@ public class TestSecondarySort {
"C = foreach B { D = limit A 10; E = order D by $1; F = order E by $0; generate group, F;};"+
"store C into 'output';");
- PhysicalPlan pp = Util.buildPp(pigServer, query);
- MROperPlan mrPlan = Util.buildMRPlan(pp, pc);
-
- SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
- so.visit();
+ SecondaryKeyOptimizer so = visitSecondaryKeyOptimizer(query);
- assertEquals(1, so.getNumMRUseSecondaryKey());
+ assertEquals(1, so.getNumUseSecondaryKey());
assertEquals(2, so.getNumSortRemoved());
- assertEquals(0, so.getDistinctChanged());
+ assertEquals(0, so.getNumDistinctChanged());
}
@Test
@@ -150,15 +141,11 @@ public class TestSecondarySort {
"C = foreach B { D = limit A 10; E = order D by $0, $1, $2; generate group, E;};" +
"store C into 'output';");
- PhysicalPlan pp = Util.buildPp(pigServer, query);
- MROperPlan mrPlan = Util.buildMRPlan(pp, pc);
- SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
- so.visit();
-
- assertEquals(1, so.getNumMRUseSecondaryKey());
+ SecondaryKeyOptimizer so = visitSecondaryKeyOptimizer(query);
+ assertEquals(1, so.getNumUseSecondaryKey());
assertEquals(1, so.getNumSortRemoved());
- assertEquals(0, so.getDistinctChanged());
+ assertEquals(0, so.getNumDistinctChanged());
}
@Test
@@ -168,15 +155,11 @@ public class TestSecondarySort {
"B = group A by $0;" +
"C = foreach B { D = limit A 10; E = order D by $1; F = order E by $2; generate group, F;};" +
"store C into 'output';");
- PhysicalPlan pp = Util.buildPp(pigServer, query);
- MROperPlan mrPlan = Util.buildMRPlan(pp, pc);
-
- SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
- so.visit();
- assertEquals(1, so.getNumMRUseSecondaryKey());
+ SecondaryKeyOptimizer so = visitSecondaryKeyOptimizer(query);
+ assertEquals(1, so.getNumUseSecondaryKey());
assertEquals(1, so.getNumSortRemoved());
- assertEquals(0, so.getDistinctChanged());
+ assertEquals(0, so.getNumDistinctChanged());
}
@Test
@@ -187,15 +170,11 @@ public class TestSecondarySort {
"C = foreach B { D = order A by $0 desc; generate group, D;};" +
"store C into 'output';");
- PhysicalPlan pp = Util.buildPp(pigServer, query);
- MROperPlan mrPlan = Util.buildMRPlan(pp, pc);
- SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
- so.visit();
-
- assertEquals(1, so.getNumMRUseSecondaryKey());
+ SecondaryKeyOptimizer so = visitSecondaryKeyOptimizer(query);
+ assertEquals(1, so.getNumUseSecondaryKey());
assertEquals(1, so.getNumSortRemoved());
- assertEquals(0, so.getDistinctChanged());
+ assertEquals(0, so.getNumDistinctChanged());
}
@Test
@@ -206,15 +185,11 @@ public class TestSecondarySort {
"C = foreach B { D = order A by $0, $1 desc; generate group, D;};" +
"store C into 'output';");
- PhysicalPlan pp = Util.buildPp(pigServer, query);
- MROperPlan mrPlan = Util.buildMRPlan(pp, pc);
-
- SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
- so.visit();
- assertEquals(1, so.getNumMRUseSecondaryKey());
+ SecondaryKeyOptimizer so = visitSecondaryKeyOptimizer(query);
+ assertEquals(1, so.getNumUseSecondaryKey());
assertEquals(1, so.getNumSortRemoved());
- assertEquals(0, so.getDistinctChanged());
+ assertEquals(0, so.getNumDistinctChanged());
}
// See PIG-1193
@@ -226,15 +201,11 @@ public class TestSecondarySort {
"C = foreach B { D = order A by $0 desc; generate DIFF(D, D);};" +
"store C into 'output';");
- PhysicalPlan pp = Util.buildPp(pigServer, query);
- MROperPlan mrPlan = Util.buildMRPlan(pp, pc);
- SecondaryKeyOptimizer so = new SecondaryKeyOptimizer(mrPlan);
- so.visit();
-
- assertEquals(1, so.getNumMRUseSecondaryKey());
+ SecondaryKeyOptimizer so = visitSecondaryKeyOptimizer(query);
+ assertEquals(1, so.getNumUseSecondaryKey());
assertEquals(2, so.getNumSortRemoved());
- assertEquals(0, so.getDistinctChanged());
+ assertEquals(0, so.getNumDistinctChanged());
}
@Test
@@ -403,25 +374,78 @@ public class TestSecondarySort {
@Test
public void testNestedSortMultiQueryEndToEnd1() throws Exception {
- pigServer.setBatchOn();
- Util.copyFromLocalToCluster(cluster, "test/org/apache/pig/test/data/passwd",
- "testNestedSortMultiQueryEndToEnd1-input.txt");
- pigServer.registerQuery("a = load 'testNestedSortMultiQueryEndToEnd1-input.txt'"
- + " using PigStorage(':') as (uname:chararray, passwd:chararray, uid:int, gid:int);");
- pigServer.registerQuery("b = group a by uname parallel 2;");
- pigServer.registerQuery("c = group a by gid parallel 2;");
- pigServer.registerQuery("d = foreach b generate SUM(a.gid);");
- pigServer.registerQuery("e = foreach c { f = order a by uid; generate group, f; };");
- pigServer.registerQuery("store d into '/tmp/output1';");
- pigServer.registerQuery("store e into '/tmp/output2';");
-
- List<ExecJob> jobs = pigServer.executeBatch();
- for (ExecJob job : jobs) {
- assertEquals(ExecJob.JOB_STATUS.COMPLETED, job.getStatus());
+ try {
+ pigServer.setBatchOn();
+ Util.copyFromLocalToCluster(cluster, "test/org/apache/pig/test/data/passwd",
+ "testNestedSortMultiQueryEndToEnd1-input.txt");
+ pigServer.registerQuery("a = load 'testNestedSortMultiQueryEndToEnd1-input.txt'"
+ + " using PigStorage(':') as (uname:chararray, passwd:chararray, uid:int, gid:int);");
+ pigServer.registerQuery("b = group a by uname parallel 2;");
+ pigServer.registerQuery("c = group a by gid parallel 2;");
+ pigServer.registerQuery("d = foreach b generate SUM(a.gid);");
+ pigServer.registerQuery("e = foreach c { f = order a by uid; generate group, f; };");
+ pigServer.registerQuery("store d into '/tmp/output1';");
+ pigServer.registerQuery("store e into '/tmp/output2';");
+
+ List<ExecJob> jobs = pigServer.executeBatch();
+ for (ExecJob job : jobs) {
+ assertEquals(ExecJob.JOB_STATUS.COMPLETED, job.getStatus());
+ }
+ } finally {
+ FileLocalizer.delete("/tmp/output1", pigServer.getPigContext());
+ FileLocalizer.delete("/tmp/output2", pigServer.getPigContext());
+ Util.deleteFile(cluster, "testNestedSortMultiQueryEndToEnd1-input.txt");
}
- FileLocalizer.delete("/tmp/output1", pigServer.getPigContext());
- FileLocalizer.delete("/tmp/output2", pigServer.getPigContext());
- Util.deleteFile(cluster, "testNestedSortMultiQueryEndToEnd1-input.txt");
+ }
+
+ @Test
+ public void testNestedSortMultiQueryEndToEnd2() throws Exception {
+ File input = Util.createTempFileDelOnExit("test", "txt");
+ PrintStream ps1 = new PrintStream(new FileOutputStream(input));
+ ps1.println("2\t2\t4");
+ ps1.println("2\t3\t4");
+ ps1.println("1\t2\t3");
+ ps1.println("1\t3\t4");
+ ps1.println("1\t2\t4");
+ ps1.println("1\t2\t5");
+ ps1.close();
+ Util.copyFromLocalToCluster(cluster, input.getCanonicalPath(), "testNestedSortMultiQueryEndToEnd2-input.txt");
+
+ try {
+ pigServer.setBatchOn();
+ pigServer.registerQuery("a = load 'testNestedSortMultiQueryEndToEnd2-input.txt' as (a0, a1, a2);");
+ pigServer.registerQuery("b = group a by a0 parallel 2;");
+ pigServer.registerQuery("c = group a by a1 parallel 2;");
+ pigServer.registerQuery("d = foreach b generate group, SUM(a.a2);");
+ pigServer.registerQuery("e = foreach c { f = order a by a0,a2; generate group, f; };");
+ pigServer.registerQuery("store d into '/tmp/output1';");
+ pigServer.registerQuery("store e into '/tmp/output2';");
+
+ List<ExecJob> jobs = pigServer.executeBatch();
+ for (ExecJob job : jobs) {
+ assertTrue(job.getStatus() == ExecJob.JOB_STATUS.COMPLETED);
+ }
+ pigServer.registerQuery("D = load '/tmp/output1';");
+ pigServer.registerQuery("E = load '/tmp/output2';");
+ pigServer.executeBatch();
+
+ Iterator<Tuple> iter = pigServer.openIterator("D");
+ Schema s = pigServer.dumpSchema("D");
+ String[] expectedD = { "(1,16.0)", "(2,8.0)" };
+ Util.checkQueryOutputsAfterSortRecursive(iter, expectedD,
+ org.apache.pig.newplan.logical.Util.translateSchema(s));
+
+ iter = pigServer.openIterator("E");
+ s = pigServer.dumpSchema("E");
+ String[] expectedE = { "(2,{(1,2,3),(1,2,4),(1,2,5),(2,2,4)})", "(3,{(1,3,4),(2,3,4)})" };
+ Util.checkQueryOutputsAfterSortRecursive(iter, expectedE,
+ org.apache.pig.newplan.logical.Util.translateSchema(s));
+ } finally {
+ FileLocalizer.delete("/tmp/output1", pigServer.getPigContext());
+ FileLocalizer.delete("/tmp/output2", pigServer.getPigContext());
+ Util.deleteFile(cluster, "testNestedSortMultiQueryEndToEnd2-input.txt");
+ }
+
}
// See PIG-1978
@@ -455,7 +479,7 @@ public class TestSecondarySort {
Util.deleteFile(cluster, clusterFilePath);
}
-
+
@Test
// Once custom partitioner is used, we cannot use secondary key optimizer, see PIG-3827
public void testCustomPartitionerWithSort() throws Exception {
@@ -481,9 +505,9 @@ public class TestSecondarySort {
} catch (Exception e) {
captureException = true;
}
-
+
assertTrue(captureException);
-
+
Util.deleteFile(cluster, clusterPath);
}
}
Added: pig/trunk/test/org/apache/pig/test/TestSecondarySortMR.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestSecondarySortMR.java?rev=1598702&view=auto
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestSecondarySortMR.java (added)
+++ pig/trunk/test/org/apache/pig/test/TestSecondarySortMR.java Fri May 30 19:07:23 2014
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pig.test;
+
+import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.SecondaryKeyOptimizerMR;
+import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.plans.MROperPlan;
+import org.apache.pig.backend.hadoop.executionengine.optimizer.SecondaryKeyOptimizer;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhysicalPlan;
+import org.apache.pig.impl.plan.VisitorException;
+
+public class TestSecondarySortMR extends TestSecondarySort {
+
+ public TestSecondarySortMR() {
+ super();
+ }
+
+ @Override
+ public MiniGenericCluster getCluster() {
+ return MiniGenericCluster.buildCluster(MiniGenericCluster.EXECTYPE_MR);
+ }
+
+ @Override
+ public SecondaryKeyOptimizer visitSecondaryKeyOptimizer(String query)
+ throws Exception, VisitorException {
+ PhysicalPlan pp = Util.buildPp(pigServer, query);
+ MROperPlan mrPlan = Util.buildMRPlan(pp, pc);
+
+ SecondaryKeyOptimizerMR so = new SecondaryKeyOptimizerMR(mrPlan);
+ so.visit();
+ return so;
+ }
+
+}
+
Modified: pig/trunk/test/org/apache/pig/test/TestSkewedJoin.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestSkewedJoin.java?rev=1598702&r1=1598701&r2=1598702&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestSkewedJoin.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestSkewedJoin.java Fri May 30 19:07:23 2014
@@ -23,15 +23,26 @@ import static org.junit.Assert.assertTru
import static org.junit.Assert.fail;
import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.Map;
+import java.util.Properties;
-import org.apache.pig.ExecType;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapreduce.lib.input.InvalidInputException;
+import org.apache.log4j.FileAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.apache.log4j.SimpleLayout;
import org.apache.pig.PigServer;
import org.apache.pig.data.BagFactory;
import org.apache.pig.data.DataBag;
@@ -40,10 +51,11 @@ import org.apache.pig.data.Tuple;
import org.apache.pig.data.TupleFactory;
import org.apache.pig.impl.builtin.PartitionSkewedKeys;
import org.apache.pig.impl.logicalLayer.FrontendException;
+import org.apache.pig.newplan.logical.rules.ColumnPruneVisitor;
import org.apache.pig.test.utils.TestHelper;
-import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
public class TestSkewedJoin {
@@ -54,29 +66,45 @@ public class TestSkewedJoin {
private static final String INPUT_FILE5 = "SkewedJoinInput5.txt";
private static final String INPUT_FILE6 = "SkewedJoinInput6.txt";
private static final String INPUT_FILE7 = "SkewedJoinInput7.txt";
+ private static final String INPUT_DIR = "build/test/data";
+ private static final String OUTPUT_DIR = "build/test/output";
- private PigServer pigServer;
- private static MiniCluster cluster = MiniCluster.buildCluster();
+ private static FileSystem fs;
+ private static PigServer pigServer;
+ private static Properties properties;
+ private static MiniGenericCluster cluster;
@Before
public void setUp() throws Exception {
- pigServer = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
- pigServer.getPigContext().getProperties().setProperty("pig.skewedjoin.reduce.maxtuple", "5");
- pigServer.getPigContext().getProperties().setProperty("pig.skewedjoin.reduce.memusage", "0.01");
+ Util.resetStateForExecModeSwitch();
+ pigServer = new PigServer(cluster.getExecType(), properties);
+ }
+
+ @BeforeClass
+ public static void oneTimeSetUp() throws Exception {
+ cluster = MiniGenericCluster.buildCluster();
+ properties = cluster.getProperties();
+ properties.setProperty("pig.skewedjoin.reduce.maxtuple", "5");
+ properties.setProperty("pig.skewedjoin.reduce.memusage", "0.01");
+ fs = cluster.getFileSystem();
createFiles();
}
@AfterClass
public static void oneTimeTearDown() throws Exception {
+ deleteFiles();
cluster.shutDown();
}
- private void createFiles() throws IOException {
- PrintWriter w = new PrintWriter(new FileWriter(INPUT_FILE1));
+ private static void createFiles() throws IOException {
+ new File(INPUT_DIR).mkdir();
+ new File(OUTPUT_DIR).mkdir();
+
+ PrintWriter w = new PrintWriter(new FileWriter(INPUT_DIR + "/" + INPUT_FILE1));
int k = 0;
for(int j=0; j<120; j++) {
- w.println("100\tapple1\taaa" + k);
+ w.println("100\tapple1\taaa" + k);
k++;
w.println("200\torange1\tbbb" + k);
k++;
@@ -86,7 +114,7 @@ public class TestSkewedJoin {
w.close();
- PrintWriter w2 = new PrintWriter(new FileWriter(INPUT_FILE2));
+ PrintWriter w2 = new PrintWriter(new FileWriter(INPUT_DIR + "/" + INPUT_FILE2));
w2.println("100\tapple1");
w2.println("100\tapple2");
w2.println("100\tapple2");
@@ -97,7 +125,7 @@ public class TestSkewedJoin {
w2.close();
- PrintWriter w3 = new PrintWriter(new FileWriter(INPUT_FILE3));
+ PrintWriter w3 = new PrintWriter(new FileWriter(INPUT_DIR + "/" + INPUT_FILE3));
w3.println("100\tapple1");
w3.println("100\tapple2");
w3.println("200\torange1");
@@ -108,14 +136,14 @@ public class TestSkewedJoin {
w3.close();
- PrintWriter w4 = new PrintWriter(new FileWriter(INPUT_FILE4));
+ PrintWriter w4 = new PrintWriter(new FileWriter(INPUT_DIR + "/" + INPUT_FILE4));
for(int i=0; i < 100; i++) {
w4.println("[a100#apple1,a100#apple2,a200#orange1,a200#orange2,a300#strawberry,a300#strawberry2,a400#pear]");
}
w4.close();
// Create a file with null keys
- PrintWriter w5 = new PrintWriter(new FileWriter(INPUT_FILE5));
+ PrintWriter w5 = new PrintWriter(new FileWriter(INPUT_DIR + "/" + INPUT_FILE5));
for(int i=0; i < 10; i++) {
w5.println("\tapple1");
}
@@ -127,7 +155,7 @@ public class TestSkewedJoin {
w5.println("100\t");
w5.close();
- PrintWriter w6 = new PrintWriter(new FileWriter(INPUT_FILE6));
+ PrintWriter w6 = new PrintWriter(new FileWriter(INPUT_DIR + "/" + INPUT_FILE6));
for(int i=0; i<300; i++) {
for(int j=0; j<5; j++) {
@@ -136,7 +164,7 @@ public class TestSkewedJoin {
}
w6.close();
- PrintWriter w7 = new PrintWriter(new FileWriter(INPUT_FILE7));
+ PrintWriter w7 = new PrintWriter(new FileWriter(INPUT_DIR + "/" + INPUT_FILE7));
for(int i=0; i<300; i = i+3) {
for(int j=0; j<2; j++) {
@@ -145,33 +173,18 @@ public class TestSkewedJoin {
}
w7.close();
- Util.copyFromLocalToCluster(cluster, INPUT_FILE1, INPUT_FILE1);
- Util.copyFromLocalToCluster(cluster, INPUT_FILE2, INPUT_FILE2);
- Util.copyFromLocalToCluster(cluster, INPUT_FILE3, INPUT_FILE3);
- Util.copyFromLocalToCluster(cluster, INPUT_FILE4, INPUT_FILE4);
- Util.copyFromLocalToCluster(cluster, INPUT_FILE5, INPUT_FILE5);
- Util.copyFromLocalToCluster(cluster, INPUT_FILE6, INPUT_FILE6);
- Util.copyFromLocalToCluster(cluster, INPUT_FILE7, INPUT_FILE7);
- }
-
- @After
- public void tearDown() throws Exception {
- new File(INPUT_FILE1).delete();
- new File(INPUT_FILE2).delete();
- new File(INPUT_FILE3).delete();
- new File(INPUT_FILE4).delete();
- new File(INPUT_FILE5).delete();
- new File(INPUT_FILE6).delete();
- new File(INPUT_FILE7).delete();
- Util.deleteDirectory(new File("skewedjoin"));
-
- Util.deleteFile(cluster, INPUT_FILE1);
- Util.deleteFile(cluster, INPUT_FILE2);
- Util.deleteFile(cluster, INPUT_FILE3);
- Util.deleteFile(cluster, INPUT_FILE4);
- Util.deleteFile(cluster, INPUT_FILE5);
- Util.deleteFile(cluster, INPUT_FILE6);
- Util.deleteFile(cluster, INPUT_FILE7);
+ Util.copyFromLocalToCluster(cluster, INPUT_DIR + "/" + INPUT_FILE1, INPUT_FILE1);
+ Util.copyFromLocalToCluster(cluster, INPUT_DIR + "/" + INPUT_FILE2, INPUT_FILE2);
+ Util.copyFromLocalToCluster(cluster, INPUT_DIR + "/" + INPUT_FILE3, INPUT_FILE3);
+ Util.copyFromLocalToCluster(cluster, INPUT_DIR + "/" + INPUT_FILE4, INPUT_FILE4);
+ Util.copyFromLocalToCluster(cluster, INPUT_DIR + "/" + INPUT_FILE5, INPUT_FILE5);
+ Util.copyFromLocalToCluster(cluster, INPUT_DIR + "/" + INPUT_FILE6, INPUT_FILE6);
+ Util.copyFromLocalToCluster(cluster, INPUT_DIR + "/" + INPUT_FILE7, INPUT_FILE7);
+ }
+
+ private static void deleteFiles() throws IOException {
+ Util.deleteDirectory(new File(INPUT_DIR));
+ Util.deleteDirectory(new File(OUTPUT_DIR));
}
@Test
@@ -205,8 +218,6 @@ public class TestSkewedJoin {
@Test
public void testSkewedJoinWithNoProperties() throws IOException{
- pigServer = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
-
pigServer.registerQuery("A = LOAD '" + INPUT_FILE1 + "' as (id, name, n);");
pigServer.registerQuery("B = LOAD '" + INPUT_FILE2 + "' as (id, name);");
DataBag dbfrj = BagFactory.getInstance().newDefaultBag();
@@ -271,36 +282,35 @@ public class TestSkewedJoin {
}
}
-
@Test
public void testSkewedJoinKeyPartition() throws IOException {
+ String outputDir = "testSkewedJoinKeyPartition";
try{
- Util.deleteFile(cluster, "skewedjoin");
+ Util.deleteFile(cluster, outputDir);
}catch(Exception e){
// it is ok if directory not exist
}
pigServer.registerQuery("A = LOAD '" + INPUT_FILE1 + "' as (id, name, n);");
pigServer.registerQuery("B = LOAD '" + INPUT_FILE2 + "' as (id, name);");
-
-
pigServer.registerQuery("E = join A by id, B by id using 'skewed' parallel 7;");
- pigServer.store("E", "skewedjoin");
+ pigServer.store("E", outputDir);
int[][] lineCount = new int[3][7];
- new File("skewedjoin").mkdir();
+ FileStatus[] outputFiles = fs.listStatus(new Path(outputDir), Util.getSuccessMarkerPathFilter());
// check how many times a key appear in each part- file
- for(int i=0; i<7; i++) {
- Util.copyFromClusterToLocal(cluster, "skewedjoin/part-r-0000"+i, "skewedjoin/part-r-0000"+i);
-
- BufferedReader reader = new BufferedReader(new FileReader("skewedjoin/part-r-0000"+i));
- String line = null;
- while((line = reader.readLine()) != null) {
- String[] cols = line.split("\t");
- int key = Integer.parseInt(cols[0])/100 -1;
- lineCount[key][i] ++;
- }
+ for (int i=0; i<7; i++) {
+ String filename = outputFiles[i].getPath().toString();
+ Util.copyFromClusterToLocal(cluster, filename, OUTPUT_DIR + "/" + i);
+ BufferedReader reader = new BufferedReader(new FileReader(OUTPUT_DIR + "/" + i));
+ String line = null;
+ while((line = reader.readLine()) != null) {
+ String[] cols = line.split("\t");
+ int key = Integer.parseInt(cols[0])/100 -1;
+ lineCount[key][i] ++;
+ }
+ reader.close();
}
int fc = 0;
@@ -529,4 +539,63 @@ public class TestSkewedJoin {
}
}
}
+
+ // PIG-3469
+ // This query should fail with nothing else but InvalidInputException
+ @Test
+ public void testNonExistingInputPathInSkewJoin() throws Exception {
+ String script =
+ "exists = LOAD '" + INPUT_FILE2 + "' AS (a:long, x:chararray);" +
+ "missing = LOAD '/non/existing/directory' AS (a:long);" +
+ "missing = FOREACH ( GROUP missing BY a ) GENERATE $0 AS a, COUNT_STAR($1);" +
+ "joined = JOIN exists BY a, missing BY a USING 'skewed';";
+
+ String logFile = Util.createTempFileDelOnExit("tmp", ".log").getAbsolutePath();
+ Logger logger = Logger.getLogger("org.apache.pig");
+ logger.setLevel(Level.INFO);
+ SimpleLayout layout = new SimpleLayout();
+ FileAppender appender = new FileAppender(layout, logFile.toString(), false, false, 0);
+ logger.addAppender(appender);
+
+ try {
+ pigServer.registerScript(new ByteArrayInputStream(script.getBytes("UTF-8")));
+ pigServer.openIterator("joined");
+ } catch (Exception e) {
+ boolean foundInvalidInputException = false;
+
+ // Search through chained exceptions for InvalidInputException. If
+ // input splits are calculated on the front-end, we will see this
+ // exception in the stack trace.
+ Throwable cause = e.getCause();
+ while (cause != null) {
+ if (cause instanceof InvalidInputException) {
+ foundInvalidInputException = true;
+ break;
+ }
+ cause = cause.getCause();
+ }
+
+ // InvalidInputException was not found in the stack trace. But it's
+ // possible that the exception was thrown in the back-end, and Pig
+ // couldn't retrieve it in the front-end. To be safe, search the log
+ // file before declaring a failure.
+ if (!foundInvalidInputException) {
+ FileInputStream fis = new FileInputStream(new File(logFile));
+ int bytes = fis.available();
+ byte[] buffer = new byte[bytes];
+ fis.read(buffer);
+ String str = new String(buffer, "UTF-8");
+ if (str.contains(InvalidInputException.class.getName())) {
+ foundInvalidInputException = true;
+ }
+ fis.close();
+ }
+
+ assertTrue("This exception was not caused by InvalidInputException: " + e,
+ foundInvalidInputException);
+ } finally {
+ LogManager.resetConfiguration();
+ }
+ }
+
}
Modified: pig/trunk/test/org/apache/pig/test/TestSplitStore.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestSplitStore.java?rev=1598702&r1=1598701&r2=1598702&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestSplitStore.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestSplitStore.java Fri May 30 19:07:23 2014
@@ -21,24 +21,26 @@ package org.apache.pig.test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
+import java.util.Properties;
-import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
import org.apache.pig.impl.PigContext;
import org.apache.pig.impl.io.FileLocalizer;
import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
public class TestSplitStore {
- private PigServer pig;
- private PigContext pigContext;
- private File tmpFile;
- private static MiniCluster cluster = MiniCluster.buildCluster();
+ private static File tmpFile;
+ private static PigServer pig;
+ private static PigContext pigContext;
+ private static Properties properties;
+ private static MiniGenericCluster cluster;
@Before
public void setUp() throws Exception {
- pig = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
+ pig = new PigServer(cluster.getExecType(), properties);
pigContext = pig.getPigContext();
int LOOP_SIZE = 20;
tmpFile = File.createTempFile("test", "txt");
@@ -50,6 +52,12 @@ public class TestSplitStore {
ps.close();
}
+ @BeforeClass
+ public static void oneTimeSetUp() throws Exception {
+ cluster = MiniGenericCluster.buildCluster();
+ properties = cluster.getProperties();
+ }
+
@AfterClass
public static void oneTimeTearDown() throws Exception {
cluster.shutDown();
Modified: pig/trunk/test/org/apache/pig/test/TestStore.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestStore.java?rev=1598702&r1=1598701&r2=1598702&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestStore.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestStore.java Fri May 30 19:07:23 2014
@@ -872,7 +872,7 @@ public class TestStore {
}
private void checkStorePath(String orig, String expected, boolean isTmp) throws Exception {
- pc.getProperties().setProperty("opt.multiquery",""+true);
+ pc.getProperties().setProperty(PigConfiguration.OPT_MULTIQUERY,""+true);
DataStorage dfs = pc.getDfs();
dfs.setActiveContainer(dfs.asContainer("/tmp"));
Modified: pig/trunk/test/org/apache/pig/test/TestStoreInstances.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestStoreInstances.java?rev=1598702&r1=1598701&r2=1598702&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestStoreInstances.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestStoreInstances.java Fri May 30 19:07:23 2014
@@ -18,7 +18,6 @@
package org.apache.pig.test;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
@@ -53,10 +52,10 @@ import org.junit.Test;
* Test to ensure that same instance of store func is used for multiple
* backend tasks. This enables sharing of information between putNext and
* output committer
- *
+ *
*/
public class TestStoreInstances {
- static MiniCluster cluster ;
+ static MiniGenericCluster cluster ;
private static final String INP_FILE_2NUMS = "TestStoreInstances";
@Before
@@ -71,7 +70,7 @@ public class TestStoreInstances {
@BeforeClass
public static void oneTimeSetup() throws IOException, Exception {
- cluster = MiniCluster.buildCluster();
+ cluster = MiniGenericCluster.buildCluster();
String[] input = {
"1\t5",
@@ -99,29 +98,30 @@ public class TestStoreInstances {
*/
@Test
public void testBackendStoreCommunication() throws IOException, ParserException {
- ExecType[] execTypes = { ExecType.MAPREDUCE, ExecType.LOCAL};
+ ExecType[] execTypes = { cluster.getExecType(), ExecType.LOCAL};
PigServer pig = null;
for(ExecType execType : execTypes){
+ Util.resetStateForExecModeSwitch();
System.err.println("Starting test mode " + execType);
- if(execType == ExecType.MAPREDUCE) {
- pig = new PigServer(ExecType.MAPREDUCE,
+ if (execType == cluster.getExecType()) {
+ pig = new PigServer(cluster.getExecType(),
cluster.getProperties());
- }else{
- pig = new PigServer(ExecType.LOCAL);
+ } else {
+ pig = new PigServer(execType);
}
final String outFile = "TestStoreInst1";
Util.deleteFile(pig.getPigContext(), outFile);
pig.setBatchOn();
String query =
" l1 = load '" + INP_FILE_2NUMS + "' as (i : int, j : int);" +
- " store l1 into '" + outFile + "' using " + CHECK_INSTANCE_STORE_FUNC +
+ " store l1 into '" + outFile + "' using " + CHECK_INSTANCE_STORE_FUNC +
";";
Util.registerMultiLineQuery(pig, query);
List<ExecJob> execJobs = pig.executeBatch();
assertEquals("num jobs", 1, execJobs.size());
assertEquals("status ", JOB_STATUS.COMPLETED, execJobs.get(0).getStatus());
}
-
+
}
@@ -160,7 +160,7 @@ public class TestStoreInstances {
throws IOException {
Configuration conf = job.getConfiguration();
conf.set("mapred.output.dir", location);
-
+
}
@@ -200,11 +200,11 @@ public class TestStoreInstances {
this.outRows = outRows;
}
-
+
@Override
public void commitTask(TaskAttemptContext arg0) {
System.err.println("OutputCommitterTestInstances commitTask called");
- assertTrue("Number of output rows > 0 ",outRows.size() > 0);
+ assertEquals("Number of output rows should be 3", 3, outRows.size());
}
@Override
Modified: pig/trunk/test/org/apache/pig/test/TestStoreOld.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestStoreOld.java?rev=1598702&r1=1598701&r2=1598702&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestStoreOld.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestStoreOld.java Fri May 30 19:07:23 2014
@@ -23,7 +23,6 @@ import java.io.File;
import java.io.PrintWriter;
import java.util.Iterator;
-import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
import org.apache.pig.data.DataType;
import org.apache.pig.data.Tuple;
@@ -34,7 +33,7 @@ import org.junit.Test;
public class TestStoreOld {
- static MiniCluster cluster = MiniCluster.buildCluster();
+ static MiniGenericCluster cluster = MiniGenericCluster.buildCluster();
private int LOOP_COUNT = 1024;
String fileName;
@@ -114,7 +113,7 @@ public class TestStoreOld {
pw.println(i + "\t" + i);
}
pw.close();
- pig = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
+ pig = new PigServer(cluster.getExecType(), cluster.getProperties());
fileName = "'" + FileLocalizer.hadoopify(f.toString(), pig.getPigContext()) + "'";
tmpFile1 = "'" + FileLocalizer.getTemporaryPath(pig.getPigContext()).toString() + "'";
tmpFile2 = "'" + FileLocalizer.getTemporaryPath(pig.getPigContext()).toString() + "'";