PIG-5184: set command to view value of a variable (daijy via rohini)
git-svn-id: https://svn.apache.org/repos/asf/pig/trunk@1796704 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CHANGES.txt b/CHANGES.txt
index 186b363..fbb70ba 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -36,6 +36,8 @@
IMPROVEMENTS
+PIG-5184: set command to view value of a variable (daijy via rohini)
+
PIG-4059: Pig On Spark
PIG-5188: Review pig-index.xml (szita)
diff --git a/src/org/apache/pig/PigServer.java b/src/org/apache/pig/PigServer.java
index fe09d2f..ac8f818 100644
--- a/src/org/apache/pig/PigServer.java
+++ b/src/org/apache/pig/PigServer.java
@@ -43,6 +43,7 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
@@ -1983,4 +1984,21 @@
public String getLastRel() {
return currDAG.getLastRel();
}
+
+ public boolean isDebugOn() {
+ if (Logger.getLogger("org.apache.pig").getLevel() == Level.DEBUG) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public String getJobName() {
+ return jobName;
+ }
+
+ public String getJobPriority() {
+ return jobPriority;
+ }
+
}
diff --git a/src/org/apache/pig/impl/PigContext.java b/src/org/apache/pig/impl/PigContext.java
index d142eba..caf384b 100644
--- a/src/org/apache/pig/impl/PigContext.java
+++ b/src/org/apache/pig/impl/PigContext.java
@@ -902,6 +902,11 @@
{
defaultLogLevel = l;
}
+
+ public int getDefaultParallel() {
+ return defaultParallel;
+ }
+
public static ClassLoader getClassLoader() {
return classloader;
}
diff --git a/src/org/apache/pig/tools/grunt/GruntParser.java b/src/org/apache/pig/tools/grunt/GruntParser.java
index a60fb4e..eca6d2d 100644
--- a/src/org/apache/pig/tools/grunt/GruntParser.java
+++ b/src/org/apache/pig/tools/grunt/GruntParser.java
@@ -44,6 +44,7 @@
import jline.console.ConsoleReader;
import org.apache.commons.io.output.NullOutputStream;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.fs.FileSystem;
@@ -575,41 +576,69 @@
value = parameterSubstitutionInGrunt(value);
if (key.equals("debug"))
{
- if (value.equals("on"))
- mPigServer.debugOn();
- else if (value.equals("off"))
- mPigServer.debugOff();
- else
- throw new ParseException("Invalid value " + value + " provided for " + key);
+ if (value != null) {
+ if (value.equals("on"))
+ mPigServer.debugOn();
+ else if (value.equals("off"))
+ mPigServer.debugOff();
+ else
+ throw new ParseException("Invalid value " + value + " provided for " + key);
+ } else {
+ System.out.println(key + "=" + mPigServer.isDebugOn());
+ }
}
else if (key.equals("job.name"))
{
- mPigServer.setJobName(value);
+ if (value != null) {
+ mPigServer.setJobName(value);
+ } else {
+ System.out.println(key + "=" + mPigServer.getJobName());
+ }
}
else if (key.equals("job.priority"))
{
- mPigServer.setJobPriority(value);
+ if (value != null) {
+ mPigServer.setJobPriority(value);
+ } else {
+ System.out.println(key + "=" + mPigServer.getJobPriority());
+ }
}
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);
+ if (value != null) {
+ // Validate
+ File file = new File(value);
+ if (!file.exists() || file.isDirectory()) {
+ throw new IOException("Invalid value for stream.skippath:" +
+ value);
+ }
+ mPigServer.addPathToSkip(value);
+ } else {
+ System.out.println(key + "=" + StringUtils.join(mPigServer.getPigContext().getPathsToSkip(), ","));
}
- mPigServer.addPathToSkip(value);
}
else if (key.equals("default_parallel")) {
- // Validate
- try {
- mPigServer.setDefaultParallel(Integer.parseInt(value));
- } catch (NumberFormatException e) {
- throw new ParseException("Invalid value for default_parallel");
+ if (value != null) {
+ // Validate
+ try {
+ mPigServer.setDefaultParallel(Integer.parseInt(value));
+ } catch (NumberFormatException e) {
+ throw new ParseException("Invalid value for default_parallel");
+ }
+ } else {
+ System.out.println(key + "=" + mPigServer.getPigContext().getDefaultParallel());
}
}
else
{
- mPigServer.getPigContext().getExecutionEngine().setProperty(key, value);
+ if (value != null) {
+ mPigServer.getPigContext().getExecutionEngine().setProperty(key, value);
+ } else {
+ if (mPigServer.getPigContext().getProperties().containsKey(key)) {
+ System.out.println(key + "=" + mPigServer.getPigContext().getProperties().getProperty(key));
+ } else {
+ System.out.println(key + " is not defined");
+ }
+ }
}
}
diff --git a/src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj b/src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj
index d07a883..b8fe18a 100644
--- a/src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj
+++ b/src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj
@@ -132,6 +132,13 @@
else
return s;
}
+ static boolean eolOrSemicolon(int kind) {
+ if (kind == EOL || kind == SEMICOLON) {
+ return true;
+ } else {
+ return false;
+ }
+ }
}
PARSER_END(PigScriptParser)
@@ -626,8 +633,8 @@
<SET>
(
t1 = GetKey()
- t2 = GetValue()
- {processSet(t1.image, unquote(t2.image));}
+ t2 = GetValueOrNull()
+ {processSet(t1.image, eolOrSemicolon(t2.kind)?null:unquote(t2.image));}
|
{processSet();}
)
@@ -828,6 +835,22 @@
{return t;}
}
+Token GetValueOrNull() :
+{
+ Token t;
+}
+{
+ (
+ t = GetValue()
+ |
+ t = <EOL>
+ |
+ t = <SEMICOLON>
+ )
+
+ {return t;}
+}
+
Token GetValue() :
{
Token t;
diff --git a/test/org/apache/pig/test/TestGrunt.java b/test/org/apache/pig/test/TestGrunt.java
index 5ed629a..bf4b5e2 100644
--- a/test/org/apache/pig/test/TestGrunt.java
+++ b/test/org/apache/pig/test/TestGrunt.java
@@ -24,6 +24,7 @@
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
@@ -32,6 +33,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.ArrayList;
@@ -1517,6 +1519,14 @@
new Grunt(new BufferedReader(reader), pc).exec();
assertEquals("my.arbitrary.value", pc.getProperties().getProperty("my.arbitrary.key"));
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(baos));
+ strCmd = "set my.arbitrary.key\n";
+ reader = new InputStreamReader(new ByteArrayInputStream(strCmd.getBytes()));
+ new Grunt(new BufferedReader(reader), pc).exec();
+
+ assertEquals(baos.toString(), "my.arbitrary.key=my.arbitrary.value\n");
}
@Test