Author: olga Date: Wed May 7 13:00:22 2008 New Revision: 654239 URL: http://svn.apache.org/viewvc?rev=654239&view=rev Log: PIG-231: validation for ship, cache, and skippath
Modified: incubator/pig/trunk/CHANGES.txt incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt incubator/pig/trunk/src/org/apache/pig/impl/streaming/StreamingCommand.java incubator/pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java Modified: incubator/pig/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/incubator/pig/trunk/CHANGES.txt?rev=654239&r1=654238&r2=654239&view=diff ============================================================================== --- incubator/pig/trunk/CHANGES.txt (original) +++ incubator/pig/trunk/CHANGES.txt Wed May 7 13:00:22 2008 @@ -281,3 +281,5 @@ PIG-219: Change unit tests to run both local and map reduce modes (kali via gates). PIG-202: Fix Order by so that user provided comparator func is used for quantile determination (kali via gates). + + PIG-231: validation for ship, cache, and skippath 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=654239&r1=654238&r2=654239&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 Wed May 7 13:00:22 2008 @@ -250,7 +250,8 @@ // via "set stream.skippath <paths>" option. private static final String PERL = "perl"; private static final String PYTHON = "python"; - private void checkAutoShipSpecs(StreamingCommand command, String[] argv) { + private void checkAutoShipSpecs(StreamingCommand command, String[] argv) + throws ParseException { // Candidate for auto-ship String arg0 = argv[0]; @@ -269,7 +270,8 @@ } } - private void checkAndShip(StreamingCommand command, String arg) { + private void checkAndShip(StreamingCommand command, String arg) + throws ParseException { // Don't auto-ship if it is an absolute path... if (arg.startsWith("/")) { return; @@ -278,7 +280,11 @@ // $ which arg String argPath = which(arg); if (argPath != null && !inSkipPaths(argPath)) { - command.addPathToShip(argPath); + try { + command.addPathToShip(argPath); + } catch(IOException e) { + throw new ParseException(e.getMessage()); + } } } @@ -1422,7 +1428,7 @@ t = <EXECCOMMAND> { String[] argv = splitArgs(unquote(t.image)); - command = new StreamingCommand(argv); + command = new StreamingCommand(pigContext, argv); checkAutoShipSpecs(command, argv); return command; } @@ -1447,7 +1453,7 @@ cmd = <EXECCOMMAND> { StreamingCommand command = - new StreamingCommand(splitArgs(unquote(cmd.image))); + new StreamingCommand(pigContext, splitArgs(unquote(cmd.image))); String[] paths; StreamingCommand.HandleSpec[] handleSpecs; } @@ -1458,7 +1464,11 @@ command.setShipFiles(false); } else { for (String path : paths) { - command.addPathToShip(path); + try { + command.addPathToShip(path); + } catch(IOException e) { + throw new ParseException(e.getMessage()); + } } } } @@ -1466,7 +1476,11 @@ <CACHE> "(" paths = PathList() ")" { for (String path : paths) { - command.addPathToCache(path); + try { + command.addPathToCache(path); + } catch(IOException e) { + throw new ParseException(e.getMessage()); + } } } | Modified: incubator/pig/trunk/src/org/apache/pig/impl/streaming/StreamingCommand.java URL: http://svn.apache.org/viewvc/incubator/pig/trunk/src/org/apache/pig/impl/streaming/StreamingCommand.java?rev=654239&r1=654238&r2=654239&view=diff ============================================================================== --- incubator/pig/trunk/src/org/apache/pig/impl/streaming/StreamingCommand.java (original) +++ incubator/pig/trunk/src/org/apache/pig/impl/streaming/StreamingCommand.java Wed May 7 13:00:22 2008 @@ -1,5 +1,7 @@ package org.apache.pig.impl.streaming; +import java.io.File; +import java.io.IOException; import java.io.Serializable; import java.util.LinkedList; import java.util.List; @@ -7,6 +9,8 @@ import java.util.TreeMap; import org.apache.pig.builtin.PigStorage; +import org.apache.pig.impl.PigContext; +import org.apache.pig.impl.io.FileLocalizer; /** @@ -55,13 +59,16 @@ boolean shipFiles = true; + private PigContext pigContext; + /** * Create a new <code>StreamingCommand</code> with the given command. * * @param command streaming command to be executed * @param argv parsed arguments of the <code>command</code> */ - public StreamingCommand(String[] argv) { + public StreamingCommand(PigContext pigContext, String[] argv) { + this.pigContext = pigContext; this.argv = argv; // Assume that argv[0] is the executable @@ -131,7 +138,13 @@ * * @param path path of the file to be shipped to the cluster */ - public void addPathToShip(String path) { + public void addPathToShip(String path) throws IOException { + // Validate + File file = new File(path); + if (!file.exists()) { + throw new IOException("Invalid ship specification: " + path); + } + shipSpec.add(path); } @@ -141,7 +154,12 @@ * * @param path path of the file to be cached on the execute nodes */ - public void addPathToCache(String path) { + public void addPathToCache(String path) throws IOException { + // Validate + if (!FileLocalizer.fileExists(path, pigContext)) { + throw new IOException("Invalid cache specification: " + path); + } + cacheSpec.add(path); } Modified: incubator/pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java URL: http://svn.apache.org/viewvc/incubator/pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java?rev=654239&r1=654238&r2=654239&view=diff ============================================================================== --- incubator/pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java (original) +++ incubator/pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java Wed May 7 13:00:22 2008 @@ -1,6 +1,7 @@ package org.apache.pig.tools.grunt; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; @@ -161,6 +162,12 @@ mPigServer.setJobName(value); } else if (key.equals("stream.skippath")) { + // Validate + File file = new File(value); + if (!file.exists() || file.isDirectory()) { + throw new IOException("Invalid value for stream.skippath:" + + value); + } mPigServer.addPathToSkip(value); } else