Skip to content

Commit

Permalink
PIG-5243: describe with typecast on as-clause shows the types before …
Browse files Browse the repository at this point in the history
…the typecasting (knoguchi)

git-svn-id: https://svn.apache.org/repos/asf/pig/trunk@1882545 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Koji Noguchi committed Oct 15, 2020
1 parent e22fcb2 commit 60760b9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion src/org/apache/pig/PigServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,11 @@ private LogicalRelationalOperator getOperatorForAlias(String alias) throws IOExc
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;
}
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/org/apache/pig/newplan/logical/relational/LOForEach.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,21 @@ public class LOForEach extends LogicalRelationalOperator {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ public void visit(LOForEach foreach) throws FrontendException {
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.
Expand Down
11 changes: 11 additions & 0 deletions test/org/apache/pig/test/TestPigServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,17 @@ public void testDescribeComplex() throws Throwable {
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);");
Expand Down

0 comments on commit 60760b9

Please sign in to comment.