Skip to content

Commit 60760b9

Browse files
author
Koji Noguchi
committed
PIG-5243: describe with typecast on as-clause shows the types before the typecasting (knoguchi)
git-svn-id: https://svn.apache.org/repos/asf/pig/trunk@1882545 13f79535-47bb-0310-9956-ffa450edef68
1 parent e22fcb2 commit 60760b9

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

CHANGES.txt

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ OPTIMIZATIONS
100100

101101
BUG FIXES
102102

103+
PIG-5243: describe with typecast on as-clause shows the types before the typecasting (knoguchi)
104+
103105
PIG-5403: streaming job stuck with script failure when combined with ORDER BY (knoguchi)
104106

105107
PIG-5362: Parameter substitution of shell cmd results doesn't handle backslash addendum (szita)

src/org/apache/pig/PigServer.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1511,7 +1511,11 @@ private LogicalRelationalOperator getOperatorForAlias(String alias) throws IOExc
15111511
String msg = "No plan for " + alias + " to describe";
15121512
throw new FrontendException(msg, errCode, PigException.INPUT, false, null);
15131513
}
1514-
return op;
1514+
if( op instanceof LOForEach && ((LOForEach)op).getCasterForAsClause() != null) {
1515+
return ((LOForEach)op).getCasterForAsClause();
1516+
} else {
1517+
return op;
1518+
}
15151519
}
15161520

15171521
/**

src/org/apache/pig/newplan/logical/relational/LOForEach.java

+10
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,21 @@ public class LOForEach extends LogicalRelationalOperator {
3636
private static final long serialVersionUID = 2L;
3737

3838
private LogicalPlan innerPlan;
39+
40+
private LOForEach casterForAsClause = null;
3941

4042
public LOForEach(OperatorPlan plan) {
4143
super("LOForEach", plan);
4244
}
4345

46+
public LOForEach getCasterForAsClause() {
47+
return casterForAsClause;
48+
}
49+
50+
public void setCasterForAsClause(LOForEach casterForAsClause) {
51+
this.casterForAsClause = casterForAsClause;
52+
}
53+
4454
public LogicalPlan getInnerPlan() {
4555
return innerPlan;
4656
}

src/org/apache/pig/newplan/logical/visitor/ForEachUserSchemaVisitor.java

+2
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ public void visit(LOForEach foreach) throws FrontendException {
209209
plan.connect(foreach,casterForEach);
210210
}
211211

212+
foreach.setCasterForAsClause(casterForEach);
213+
212214
// Since the explict cast is now inserted after the original foreach,
213215
// throwing away the user defined "types" but keeping the user
214216
// defined names from the original foreach.

test/org/apache/pig/test/TestPigServer.java

+11
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,17 @@ public void testDescribeComplex() throws Throwable {
532532
assertEquals(expectedSchema, dumpedSchema);
533533
}
534534

535+
// PIG-5243
536+
@Test
537+
public void testDescribeAsClause() throws Throwable {
538+
PigServer pig = new PigServer(cluster.getExecType(), properties);
539+
pig.registerQuery("a = load 'a' as (field1: int);");
540+
pig.registerQuery("b = FOREACH a generate field1 as (new_field:chararray);") ;
541+
Schema dumpedSchema = pig.dumpSchema("b") ;
542+
Schema expectedSchema = Utils.getSchemaFromString("new_field: chararray");
543+
assertEquals(expectedSchema, dumpedSchema);
544+
}
545+
535546
private void registerScalarScript(boolean useScalar, String expectedSchemaStr) throws IOException {
536547
PigServer pig = new PigServer(cluster.getExecType(), properties);
537548
pig.registerQuery("A = load 'adata' AS (a: int, b: int);");

0 commit comments

Comments
 (0)