You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by da...@apache.org on 2012/01/14 01:05:56 UTC

svn commit: r1231417 - in /pig/branches/branch-0.9: CHANGES.txt src/org/apache/pig/parser/LogicalPlanGenerator.g test/org/apache/pig/test/TestParser.java

Author: daijy
Date: Sat Jan 14 00:05:55 2012
New Revision: 1231417

URL: http://svn.apache.org/viewvc?rev=1231417&view=rev
Log:
PIG-2428: In pig9, can't have limit(order by) without getting a null error

Modified:
    pig/branches/branch-0.9/CHANGES.txt
    pig/branches/branch-0.9/src/org/apache/pig/parser/LogicalPlanGenerator.g
    pig/branches/branch-0.9/test/org/apache/pig/test/TestParser.java

Modified: pig/branches/branch-0.9/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.9/CHANGES.txt?rev=1231417&r1=1231416&r2=1231417&view=diff
==============================================================================
--- pig/branches/branch-0.9/CHANGES.txt (original)
+++ pig/branches/branch-0.9/CHANGES.txt Sat Jan 14 00:05:55 2012
@@ -40,6 +40,8 @@ PIG-2410: Piggybank does not compile in 
 
 BUG FIXES
 
+PIG-2428: In pig9, can't have limit(order by) without getting a null error (jcoveney via daijy)
+
 PIG-2462: getWrappedSplit is incorrectly returning the first split instead of the current split. (arov via daijy)
 
 PIG-2473: Fix eclipse files for pig 9 (daijy)

Modified: pig/branches/branch-0.9/src/org/apache/pig/parser/LogicalPlanGenerator.g
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.9/src/org/apache/pig/parser/LogicalPlanGenerator.g?rev=1231417&r1=1231416&r2=1231417&view=diff
==============================================================================
--- pig/branches/branch-0.9/src/org/apache/pig/parser/LogicalPlanGenerator.g (original)
+++ pig/branches/branch-0.9/src/org/apache/pig/parser/LogicalPlanGenerator.g Sat Jan 14 00:05:55 2012
@@ -884,16 +884,17 @@ bin_expr[LogicalExpressionPlan plan] ret
 ;
 
 limit_clause returns[String alias]
- : ^( LIMIT rel INTEGER  )
+ : ^( LIMIT rel ( INTEGER
    {
        $alias = builder.buildLimitOp( new SourceLocation( (PigParserNode)$LIMIT ), $statement::alias,
            $statement::inputAlias, Long.valueOf( $INTEGER.text ) );
    }
- | ^( LIMIT rel LONGINTEGER )
+ | LONGINTEGER
    {
        $alias = builder.buildLimitOp( new SourceLocation( (PigParserNode)$LIMIT ), $statement::alias,
            $statement::inputAlias, builder.parseLong( $LONGINTEGER.text ) );
    }
+ ) )
 ;
 
 sample_clause returns[String alias]

Modified: pig/branches/branch-0.9/test/org/apache/pig/test/TestParser.java
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.9/test/org/apache/pig/test/TestParser.java?rev=1231417&r1=1231416&r2=1231417&view=diff
==============================================================================
--- pig/branches/branch-0.9/test/org/apache/pig/test/TestParser.java (original)
+++ pig/branches/branch-0.9/test/org/apache/pig/test/TestParser.java Sat Jan 14 00:05:55 2012
@@ -21,7 +21,12 @@ package org.apache.pig.test;
 import static org.apache.pig.ExecType.LOCAL;
 import static org.apache.pig.ExecType.MAPREDUCE;
 
+import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.PrintStream;
+import java.text.DecimalFormat;
+import java.util.Iterator;
 import java.util.Properties;
 
 import junit.framework.TestCase;
@@ -33,6 +38,8 @@ import org.apache.pig.PigServer;
 import org.apache.pig.ExecType;
 import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.backend.hadoop.datastorage.ConfigurationUtil;
+import org.apache.pig.data.DataType;
+import org.apache.pig.data.Tuple;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
@@ -90,6 +97,42 @@ protected final Log log = LogFactory.get
         }
     }
     
+    private static final int DATALEN = 1024;
+    private String[][] DATA = new String[2][DATALEN];
+
+    @Test
+    public void testOrderNestedInLimit() throws ExecException, IOException {
+        DecimalFormat myFormatter = new DecimalFormat("0000000");
+        for (int i = 0; i < DATALEN; i++) {
+            DATA[0][i] = myFormatter.format(i);
+            DATA[1][i] = myFormatter.format(DATALEN - i - 1);
+        }
+
+        File tmpFile = File.createTempFile("test", "txt");
+        tmpFile.deleteOnExit();
+        PrintStream ps = new PrintStream(new FileOutputStream(tmpFile));
+        for(int i = 0; i < DATALEN; i++) {
+            ps.println("1\t" + DATA[1][i] + "\t" + DATA[0][i]);
+        }
+        ps.close();
+
+        Util.copyFromLocalToCluster(cluster, tmpFile.getAbsolutePath(), tmpFile.getName());
+        int limit=100;
+
+        pigServer.registerQuery("myid = limit (order (load '"+tmpFile.getName()+"') by $2) "+limit+";");
+
+        boolean descending = true;
+
+        Iterator<Tuple> it = pigServer.openIterator("myid");
+        int col = (descending ? 1 : 0);
+        for(int i = 0; i < 100; i++) {
+            Tuple t = (Tuple)it.next();
+            int value = DataType.toInteger(t.get(1));
+            assertEquals(Integer.parseInt(DATA[col][i]), value);
+        }
+        assertFalse(it.hasNext());
+    }
+
     @Test
     public void testRemoteServerList() throws ExecException, IOException {
         try {