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/05/12 20:00:29 UTC

svn commit: r655582 - in /incubator/pig/trunk: CHANGES.txt src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt

Author: olga
Date: Mon May 12 11:00:29 2008
New Revision: 655582

URL: http://svn.apache.org/viewvc?rev=655582&view=rev
Log:
PIG-237: validation of output dir

Modified:
    incubator/pig/trunk/CHANGES.txt
    incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt

Modified: incubator/pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/pig/trunk/CHANGES.txt?rev=655582&r1=655581&r2=655582&view=diff
==============================================================================
--- incubator/pig/trunk/CHANGES.txt (original)
+++ incubator/pig/trunk/CHANGES.txt Mon May 12 11:00:29 2008
@@ -291,3 +291,5 @@
     (acmurthy via olgan)
 
     PIG-232: let valid cache specifications through (acmurthy via olgan)
+
+    PIG-237: validation of the output directory (pi_song via olgan)

Modified: incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt
URL: http://svn.apache.org/viewvc/incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt?rev=655582&r1=655581&r2=655582&view=diff
==============================================================================
--- incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt (original)
+++ incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt Mon May 12 11:00:29 2008
@@ -46,6 +46,7 @@
 import org.apache.pig.impl.logicalLayer.LogicalPlan;
 import org.apache.pig.impl.streaming.StreamingCommand;
 import org.apache.pig.impl.streaming.StreamingCommand.HandleSpec;
+import org.apache.pig.backend.datastorage.* ;
 
 public class QueryParser {
 	private PigContext pigContext;
@@ -121,8 +122,22 @@
 	static int undollar(String s) {
 		return Integer.parseInt(s.substring(1, s.length()));	
 	}
-	
-	
+
+	/**************This is already a part of type branch. Don't merge it back ***********/
+	private boolean checkFileExists(String filename) throws IOException {
+        if (pigContext.getExecType() == ExecType.LOCAL) {
+            ElementDescriptor elem = pigContext.getLfs().asElement(filename) ;
+            return elem.exists() ;
+        }
+        else if (pigContext.getExecType() == ExecType.MAPREDUCE) {
+            // This does actual file check + glob check
+            return FileLocalizer.fileExists(filename, pigContext) ;
+        }
+        else { // if ExecType is something else)
+            throw new RuntimeException("Undefined state in " + this.getClass()) ;
+        }
+    }
+    /************************************************************************************/
 	
 	String massageFilename(String filename, PigContext pigContext)
 	throws IOException, ParseException {
@@ -1534,6 +1549,13 @@
         lo = new LOStore(opTable, scope, getNextId(), readFrom.getRoot(),
                          new FileSpec(jobOutputFile, functionSpec),
                          false);
+
+        /**************This is already a part of type branch. Don't merge it back ***********/
+        if (checkFileExists(jobOutputFile)) {
+            throw new ParseException(jobOutputFile + " already exists. Cannot overwrite.") ;
+        }
+        /************************************************************************************/
+        
         pigContext.setJobOutputFile(jobOutputFile);
         
         return lo;