You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by ol...@apache.org on 2008/09/16 03:23:27 UTC

svn commit: r695706 - in /incubator/pig/branches/types: src/org/apache/pig/impl/PigContext.java src/org/apache/pig/impl/logicalLayer/LOLoad.java src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt test/org/apache/pig/test/TestPigSplit.java

Author: olga
Date: Mon Sep 15 18:23:26 2008
New Revision: 695706

URL: http://svn.apache.org/viewvc?rev=695706&view=rev
Log:
PIG-178-183 merge from trunk

Modified:
    incubator/pig/branches/types/src/org/apache/pig/impl/PigContext.java
    incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOLoad.java
    incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt
    incubator/pig/branches/types/test/org/apache/pig/test/TestPigSplit.java

Modified: incubator/pig/branches/types/src/org/apache/pig/impl/PigContext.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/PigContext.java?rev=695706&r1=695705&r2=695706&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/impl/PigContext.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/impl/PigContext.java Mon Sep 15 18:23:26 2008
@@ -367,15 +367,21 @@
     }
     
     
-
     public static Class resolveClassName(String name) throws IOException{
+
         for(String prefix: packageImportList) {
             Class c;
-        try {
+            try {
                 c = Class.forName(prefix+name,true, LogicalPlanBuilder.classloader);
                 return c;
-            } catch (ClassNotFoundException e) {
-            } catch (LinkageError e) {}
+            } 
+            catch (ClassNotFoundException e) {
+                // do nothing
+            } 
+            catch (UnsupportedClassVersionError e) {
+                throw WrappedIOException.wrap(e) ;
+            }
+            
         }
 
         // create ClassNotFoundException exception and attach to IOException

Modified: incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOLoad.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOLoad.java?rev=695706&r1=695705&r2=695706&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOLoad.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOLoad.java Mon Sep 15 18:23:26 2008
@@ -26,6 +26,7 @@
 import org.apache.pig.impl.io.FileSpec;
 import org.apache.pig.impl.plan.OperatorKey;
 import org.apache.pig.impl.plan.VisitorException;
+import org.apache.pig.impl.util.WrappedIOException;
 import org.apache.pig.impl.logicalLayer.schema.Schema;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -64,14 +65,10 @@
                   PigContext.instantiateFuncFromSpec(inputFileSpec.getFuncSpec()); 
         }catch (ClassCastException cce) {
             log.error(inputFileSpec.getFuncSpec() + " should implement the LoadFunc interface.");
-            IOException ioe = new IOException(cce.getMessage()); 
-            ioe.setStackTrace(cce.getStackTrace());
-            throw ioe;
+            throw WrappedIOException.wrap(cce);
         }
          catch (Exception e){ 
-            IOException ioe = new IOException(e.getMessage()); 
-            ioe.setStackTrace(e.getStackTrace());
-            throw ioe; 
+             throw WrappedIOException.wrap(e);
         }
     }
 

Modified: incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt?rev=695706&r1=695705&r2=695706&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt (original)
+++ incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt Mon Sep 15 18:23:26 2008
@@ -999,7 +999,17 @@
 			log.debug("LoadClause: funcSpec = " + funcSpec);
 		}
 
-		lo = new LOLoad(lp, new OperatorKey(scope, getNextId()), new FileSpec(massageFilename(filename, pigContext), funcSpec), null, splittable);
+        try {
+		    lo = new LOLoad(lp, new OperatorKey(scope, getNextId()), new FileSpec(massageFilename(filename, pigContext), funcSpec), null, splittable);
+        } catch (IOException ioe) {
+            // The autogenerated parser code only catches RuntimeException and
+            // ParseException as special Exceptions. All others are caught as
+            // Throwable and then re-thrown by casting to ERROR - this can result
+            // in ClassCastException if it is due to the IOException here - so
+            // wrap the IOException in an "Error" object and throw the Error here
+            Error e = new Error(ioe);
+            throw e;
+        }
 		lp.add(lo);
 		log.debug("Added operator " + lo.getClass().getName() + " to the logical plan");	
 		

Modified: incubator/pig/branches/types/test/org/apache/pig/test/TestPigSplit.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/test/org/apache/pig/test/TestPigSplit.java?rev=695706&r1=695705&r2=695706&view=diff
==============================================================================
--- incubator/pig/branches/types/test/org/apache/pig/test/TestPigSplit.java (original)
+++ incubator/pig/branches/types/test/org/apache/pig/test/TestPigSplit.java Mon Sep 15 18:23:26 2008
@@ -18,34 +18,68 @@
 
 package org.apache.pig.test;
 
-import java.io.BufferedWriter;
 import java.io.File;
-import java.io.IOException;
-import java.io.FileWriter;
 import java.io.PrintWriter;
 import java.util.Iterator;
 
-import org.junit.Before;
-import org.junit.Test;
-
-import org.apache.pig.ExecType;
-import org.apache.pig.PigServer;
 import org.apache.pig.data.Tuple;
-import org.apache.pig.backend.executionengine.ExecException;
+import org.junit.Test;
 
-import junit.framework.TestCase;
+public class TestPigSplit extends PigExecTestCase {
+		
+	@Test
+	public void notestLongEvalSpec() throws Exception{
+		File f = File.createTempFile("tmp", "");
+		
+		PrintWriter pw = new PrintWriter(f);
+		pw.println("0\ta");
+		pw.close();
+		
+		pigServer.registerQuery("a = load 'file:" + Util.encodeEscape(f.toString()) + "';");
+		for (int i=0; i< 500; i++){
+			pigServer.registerQuery("a = filter a by $0 == '1';");
+		}
+		Iterator<Tuple> iter = pigServer.openIterator("a");
+		while (iter.hasNext()){
+			throw new Exception();
+		}
+		f.delete();
+	}
+	
+    @Test
+    public void testSchemaWithSplit() throws Exception {
+        File f = File.createTempFile("tmp", "");
 
-public class TestPigSplit extends TestCase {
-    PigServer pig;
-    MiniCluster cluster = MiniCluster.buildCluster();
-    
-    @Override
-    @Before
-    protected void setUp() throws Exception {
-        super.setUp();
+        PrintWriter pw = new PrintWriter(f);
+        pw.println("2");
+        pw.println("12");
+        pw.println("42");
+        pw.close();
+        pigServer.registerQuery("a = load 'file:" + Util.encodeEscape(f.toString()) + "' as (value:chararray);");
+        pigServer.registerQuery("split a into b if value < '20', c if value > '10';");
+        pigServer.registerQuery("b1 = order b by value;");
+        pigServer.registerQuery("c1 = order c by value;");
+
+        // order in lexicographic, so 12 comes before 2
+        Iterator<Tuple> iter = pigServer.openIterator("b1");
+        assertTrue("b1 has an element", iter.hasNext());
+        assertEquals("first item in b1", iter.next().get(0), "12");
+        assertTrue("b1 has an element", iter.hasNext());
+        assertEquals("second item in b1", iter.next().get(0), "2");
+        assertFalse("b1 is over", iter.hasNext());
+
+        iter = pigServer.openIterator("c1");
+        assertTrue("c1 has an element", iter.hasNext());
+        assertEquals("first item in c1", iter.next().get(0), "12");
+        assertTrue("c1 has an element", iter.hasNext());
+        assertEquals("second item in c1", iter.next().get(0), "2");
+        assertTrue("c1 has an element", iter.hasNext());
+        assertEquals("third item in c1", iter.next().get(0), "42");
+        assertFalse("c1 is over", iter.hasNext());
 
-        pig = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
+        f.delete();
     }
+
     @Test
     public void testLongEvalSpec() throws Exception{
         File f = File.createTempFile("tmp", "");
@@ -56,14 +90,13 @@
         }
         pw.close();
         
-        pig.registerQuery("a = load 'file:" + f + "';");
-        pig.registerQuery("a = filter a by $0 == '1';");
+        pigServer.registerQuery("a = load 'file:" + f + "';");
+        pigServer.registerQuery("a = filter a by $0 == '1';");
 
-        Iterator<Tuple> iter = pig.openIterator("a");
+        Iterator<Tuple> iter = pigServer.openIterator("a");
         while (iter.hasNext()){
             throw new Exception();
         }
         f.delete();
     }
-    
 }