Author: knoguchi
Date: Thu Oct 15 15:14:07 2020
New Revision: 1882545

URL: http://svn.apache.org/viewvc?rev=1882545&view=rev
Log:
PIG-5243: describe with typecast on as-clause shows the types before the 
typecasting (knoguchi)

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/PigServer.java
    pig/trunk/src/org/apache/pig/newplan/logical/relational/LOForEach.java
    
pig/trunk/src/org/apache/pig/newplan/logical/visitor/ForEachUserSchemaVisitor.java
    pig/trunk/test/org/apache/pig/test/TestPigServer.java

Modified: pig/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1882545&r1=1882544&r2=1882545&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Thu Oct 15 15:14:07 2020
@@ -100,6 +100,8 @@ OPTIMIZATIONS
  
 BUG FIXES
 
+PIG-5243: describe with typecast on as-clause shows the types before the 
typecasting (knoguchi)
+
 PIG-5403: streaming job stuck with script failure when combined with ORDER BY 
(knoguchi)
 
 PIG-5362: Parameter substitution of shell cmd results doesn't handle backslash 
addendum (szita)

Modified: pig/trunk/src/org/apache/pig/PigServer.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/PigServer.java?rev=1882545&r1=1882544&r2=1882545&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/PigServer.java (original)
+++ pig/trunk/src/org/apache/pig/PigServer.java Thu Oct 15 15:14:07 2020
@@ -1511,7 +1511,11 @@ public class PigServer {
             String msg = "No plan for " + alias + " to describe";
             throw new FrontendException(msg, errCode, PigException.INPUT, 
false, null);
         }
-        return op;
+        if( op instanceof LOForEach && ((LOForEach)op).getCasterForAsClause() 
!= null) {
+            return ((LOForEach)op).getCasterForAsClause();
+        } else {
+            return op;
+        }
     }
 
     /**

Modified: pig/trunk/src/org/apache/pig/newplan/logical/relational/LOForEach.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/newplan/logical/relational/LOForEach.java?rev=1882545&r1=1882544&r2=1882545&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/newplan/logical/relational/LOForEach.java 
(original)
+++ pig/trunk/src/org/apache/pig/newplan/logical/relational/LOForEach.java Thu 
Oct 15 15:14:07 2020
@@ -36,11 +36,21 @@ public class LOForEach extends LogicalRe
     private static final long serialVersionUID = 2L;
 
     private LogicalPlan innerPlan;
+
+    private LOForEach casterForAsClause = null;
       
     public LOForEach(OperatorPlan plan) {
         super("LOForEach", plan);              
     }
 
+    public LOForEach getCasterForAsClause() {
+        return casterForAsClause;
+    }
+
+    public void setCasterForAsClause(LOForEach casterForAsClause) {
+        this.casterForAsClause = casterForAsClause;
+    }
+
     public LogicalPlan getInnerPlan() {
         return innerPlan;
     }

Modified: 
pig/trunk/src/org/apache/pig/newplan/logical/visitor/ForEachUserSchemaVisitor.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/newplan/logical/visitor/ForEachUserSchemaVisitor.java?rev=1882545&r1=1882544&r2=1882545&view=diff
==============================================================================
--- 
pig/trunk/src/org/apache/pig/newplan/logical/visitor/ForEachUserSchemaVisitor.java
 (original)
+++ 
pig/trunk/src/org/apache/pig/newplan/logical/visitor/ForEachUserSchemaVisitor.java
 Thu Oct 15 15:14:07 2020
@@ -209,6 +209,8 @@ public class ForEachUserSchemaVisitor ex
                 plan.connect(foreach,casterForEach);
             }
 
+            foreach.setCasterForAsClause(casterForEach);
+
             // Since the explict cast is now inserted after the original 
foreach,
             // throwing away the user defined "types" but keeping the user
             // defined names from the original foreach.

Modified: pig/trunk/test/org/apache/pig/test/TestPigServer.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestPigServer.java?rev=1882545&r1=1882544&r2=1882545&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestPigServer.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestPigServer.java Thu Oct 15 15:14:07 
2020
@@ -532,6 +532,17 @@ public class TestPigServer {
         assertEquals(expectedSchema, dumpedSchema);
     }
 
+    // PIG-5243
+    @Test
+    public void testDescribeAsClause() throws Throwable {
+        PigServer pig = new PigServer(cluster.getExecType(), properties);
+        pig.registerQuery("a = load 'a' as (field1: int);");
+        pig.registerQuery("b = FOREACH a generate field1 as 
(new_field:chararray);") ;
+        Schema dumpedSchema = pig.dumpSchema("b") ;
+        Schema expectedSchema = Utils.getSchemaFromString("new_field: 
chararray");
+        assertEquals(expectedSchema, dumpedSchema);
+    }
+
     private void registerScalarScript(boolean useScalar, String 
expectedSchemaStr) throws IOException {
         PigServer pig = new PigServer(cluster.getExecType(), properties);
         pig.registerQuery("A = load 'adata' AS (a: int, b: int);");


Reply via email to