Author: gates
Date: Tue Mar 17 01:07:06 2009
New Revision: 755061

URL: http://svn.apache.org/viewvc?rev=755061&view=rev
Log:
PIG-704 Added ALIASES command that shows all currently defined ALIASES.  
Changed semantics of DEFINE to define last used alias if no argument is given 
(ericg via gates).

Modified:
    hadoop/pig/trunk/CHANGES.txt
    hadoop/pig/trunk/src/org/apache/pig/PigServer.java
    hadoop/pig/trunk/src/org/apache/pig/impl/PigContext.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt
    hadoop/pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java
    
hadoop/pig/trunk/src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj

Modified: hadoop/pig/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/CHANGES.txt?rev=755061&r1=755060&r2=755061&view=diff
==============================================================================
--- hadoop/pig/trunk/CHANGES.txt (original)
+++ hadoop/pig/trunk/CHANGES.txt Tue Mar 17 01:07:06 2009
@@ -33,6 +33,10 @@
 
     PIG-535: added rmf command
 
+       PIG-704 Added ALIASES command that shows all currently defined ALIASES.
+       Changed semantics of DEFINE to define last used alias if no argument is
+       given (ericg via gates).
+
 IMPROVEMENTS
 
     PIG-270: proper line number for parse errors (daijy via olgan)

Modified: hadoop/pig/trunk/src/org/apache/pig/PigServer.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/PigServer.java?rev=755061&r1=755060&r2=755061&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/PigServer.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/PigServer.java Tue Mar 17 01:07:06 2009
@@ -387,6 +387,10 @@
         }
     }
 
+    public void printAliases () throws FrontendException {
+        System.out.println("aliases: " + aliasOp.keySet());
+    }
+
     public Schema dumpSchema(String alias) throws IOException{
         try {
             LogicalPlan lp = getPlanFromAlias(alias, "describe");

Modified: hadoop/pig/trunk/src/org/apache/pig/impl/PigContext.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/impl/PigContext.java?rev=755061&r1=755060&r2=755061&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/impl/PigContext.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/impl/PigContext.java Tue Mar 17 
01:07:06 2009
@@ -116,6 +116,8 @@
 
     public boolean debug = true;
     
+    private String last_alias = null;
+
     // List of paths skipped for automatic shipping
     List<String> skippedShipPaths = new ArrayList<String>();
     
@@ -327,6 +329,14 @@
         return getProperties();
     }
 
+    public String getLastAlias() {
+      return this.last_alias;
+    }
+
+    public void setLastAlias(String value) {
+      this.last_alias = value;
+    }
+
     /**
      * Defines an alias for the given function spec. This
      * is useful for functions that require arguments to the 

Modified: 
hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt?rev=755061&r1=755060&r2=755061&view=diff
==============================================================================
--- 
hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt 
(original)
+++ 
hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt 
Tue Mar 17 01:07:06 2009
@@ -830,7 +830,11 @@
                        throw new ParseException(
                        "Currently PIG does not support assigning an existing 
relation (" + t1.image + ") to another alias (" + t2.image + ")");})
 |      LOOKAHEAD(2) 
-       (t1 = <IDENTIFIER> "=" root = Expr(lp) ";" {root.setAlias(t1.image); 
addAlias(t1.image, root);})
+       (t1 = <IDENTIFIER> "=" root = Expr(lp) ";" {
+         root.setAlias(t1.image);
+         addAlias(t1.image, root);
+         pigContext.setLastAlias(t1.image);
+       })
 |      (root = Expr(lp) ";")
 |      (<SPLIT> root = SplitClause(lp) ";")
        )

Modified: hadoop/pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java?rev=755061&r1=755060&r2=755061&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java Tue Mar 17 
01:07:06 2009
@@ -167,9 +167,17 @@
     }
     
     protected void processDescribe(String alias) throws IOException {
+        if(alias==null) {
+            alias = mPigServer.getPigContext().getLastAlias();
+        }
         mPigServer.dumpSchema(alias);
     }
 
+    protected void printAliases() throws IOException {
+        mPigServer.printAliases();
+    }
+
+
     protected void processExplain(String alias) throws IOException {
         mPigServer.explain(alias, System.out);
     }

Modified: 
hadoop/pig/trunk/src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj?rev=755061&r1=755060&r2=755061&view=diff
==============================================================================
--- 
hadoop/pig/trunk/src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj 
(original)
+++ 
hadoop/pig/trunk/src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj 
Tue Mar 17 01:07:06 2009
@@ -61,6 +61,8 @@
        
        abstract protected void quit();
        
+       abstract protected void printAliases() throws IOException;
+
        abstract protected void processDescribe(String alias) throws 
IOException;
 
        abstract protected void processExplain(String alias) throws IOException;
@@ -132,6 +134,7 @@
 TOKEN: {<COPYTOLOCAL: "copyToLocal">}
 TOKEN: {<DUMP: "dump">}
 TOKEN: {<DESCRIBE: "describe">}
+TOKEN: {<ALIASES: "aliases">}
 TOKEN: {<EXPLAIN: "explain">}
 TOKEN: {<HELP: "help">}
 TOKEN: {<KILL: "kill">}
@@ -396,9 +399,16 @@
        {processIllustrate(t1.image);}
        |
        <DESCRIBE>
+       (
        t1 = <IDENTIFIER>
        {processDescribe(t1.image);}
        |
+               {processDescribe(null);}
+       )
+       |
+       <ALIASES>
+       {printAliases();}
+       |
     <EXPLAIN>
        t1 = <IDENTIFIER>
        {processExplain(t1.image);}
@@ -568,6 +578,8 @@
        |
        t = <DESCRIBE>
        |
+       t = <ALIASES>
+       |
        t = <EXPLAIN>
        |
        t = <HELP>


Reply via email to