[ 
https://issues.apache.org/jira/browse/PIG-3153?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Cheolsoo Park updated PIG-3153:
-------------------------------

    Attachment: PIG-3135-2.patch.txt

[~dreambird], I looked into this and am attaching a patch 
(PIG-3135-2.patch.txt) that allows outputSchema to be a tuple. Here is my 
reasoning:

1. The reason why defining outputSchema as "t:(word:chararray,num:long)" causes 
a NPE is because the JavaScript object doesn't have a field called "t". If you 
read "JsFunction.jsToPigTuple()", it recursively searches for every field of 
outputSchema in the JavaScript object.

IMO, the right way to fix this is to wrap the JavaScript object with another 
object and name that wrapper object as "t". 

2. Regarding my change to JsFunction, I removed "outputSchema.size() == 1" in 
addition to adding "outputSchema.getField(0).type == DataType.TUPLE" to the if 
condition.

The former is redundant because the size of outputSchema is always equal to 1 
now due to PIG-3082. The latter is added to wrap the JavaScript object into 
another object as explained above.

With this patch, the test code doesn't have to be modified at all. Please let 
me know what you think. Thanks!
                
> TestScriptUDF.testJavascriptExampleScript fails in trunk
> --------------------------------------------------------
>
>                 Key: PIG-3153
>                 URL: https://issues.apache.org/jira/browse/PIG-3153
>             Project: Pig
>          Issue Type: Bug
>    Affects Versions: 0.12
>            Reporter: Cheolsoo Park
>            Assignee: Johnny Zhang
>             Fix For: 0.12
>
>         Attachments: PIG-3135-2.patch.txt, PIG-3153.patch.txt, 
> PIG-3153.patch.txt
>
>
> To reproduce the failure, do:
> {code}
> ant clean test -Dtestcase=TestScriptUDF
> {code}
> The test fails with the following error:
> {code}
> Caused by: org.apache.pig.impl.logicalLayer.FrontendException: ERROR 0: Given 
> UDF returns an improper Schema. Schema should only contain one field of a 
> Tuple, Bag, or a single type. Returns: {word: chararray,num: long}
>     at 
> org.apache.pig.newplan.logical.expression.UserFuncExpression.getFieldSchema(UserFuncExpression.java:206)
>     at 
> org.apache.pig.newplan.logical.optimizer.FieldSchemaResetter.execute(SchemaResetter.java:264)
>     at 
> org.apache.pig.newplan.logical.expression.AllSameExpressionVisitor.visit(AllSameExpressionVisitor.java:143)
>     at 
> org.apache.pig.newplan.logical.expression.UserFuncExpression.accept(UserFuncExpression.java:88)
>     at 
> org.apache.pig.newplan.ReverseDependencyOrderWalker.walk(ReverseDependencyOrderWalker.java:70)
>     at org.apache.pig.newplan.PlanVisitor.visit(PlanVisitor.java:52)
>     at 
> org.apache.pig.newplan.logical.optimizer.SchemaResetter.visitAll(SchemaResetter.java:67)
>     at 
> org.apache.pig.newplan.logical.optimizer.SchemaResetter.visit(SchemaResetter.java:122)
>     at 
> org.apache.pig.newplan.logical.relational.LOGenerate.accept(LOGenerate.java:240)
>     at 
> org.apache.pig.newplan.DependencyOrderWalker.walk(DependencyOrderWalker.java:75)
>     at 
> org.apache.pig.newplan.logical.optimizer.SchemaResetter.visit(SchemaResetter.java:114)
>     at 
> org.apache.pig.newplan.logical.relational.LOForEach.accept(LOForEach.java:76)
>     at 
> org.apache.pig.newplan.DependencyOrderWalker.walk(DependencyOrderWalker.java:75)
>     at org.apache.pig.newplan.PlanVisitor.visit(PlanVisitor.java:52)
>     at 
> org.apache.pig.parser.LogicalPlanBuilder.expandAndResetVisitor(LogicalPlanBuilder.java:402)
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to