[
https://issues.apache.org/jira/browse/PIG-3239?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13599553#comment-13599553
]
Johnny Zhang commented on PIG-3239:
-----------------------------------
[~luibelgo], please correct me if I am wrong, I think 'SPLIT' doesn't work with
'OTHERWISE'. 'SPLIT' only work with 'IF'
http://pig.apache.org/docs/r0.7.0/piglatin_ref2.html#SPLIT
actually below script works with me very well on your example
{noforamt}
DEFINE my_macro(seq) RETURNS valid, invalid {
added = FOREACH $seq GENERATE $0 * 2, $1;
SPLIT added INTO $valid IF $1 == true, $invalid IF $1 ==false;
}
data = LOAD 'case.csv' USING PigStorage(',') AS (value: int, valid: boolean);
P, Q = my_macro(data);
DUMP P;
DUMP Q;
{noformat}
> Unable to return multiple values from a macro using SPLIT
> ---------------------------------------------------------
>
> Key: PIG-3239
> URL: https://issues.apache.org/jira/browse/PIG-3239
> Project: Pig
> Issue Type: Bug
> Affects Versions: 0.10.0
> Environment: Apache Pig version 0.10.0-cdh4.2.0 (rexported)
> compiled Feb 15 2013, 12:19:17
> Linux 3.2.0-38-generic #61-Ubuntu SMP Tue Feb 19 12:18:21 UTC 2013 x86_64
> x86_64 x86_64 GNU/Linux
> Reporter: Luis Belloch
> Priority: Minor
>
> Hi, I'm unable to return multiple values from a macro when values come from a
> SPLIT. Here is an small example:
> {code}
> DEFINE my_macro(seq) RETURNS valid, invalid {
> added = FOREACH $seq GENERATE $0 * 2, $1;
> SPLIT added INTO $valid IF $1 == true, $invalid OTHERWISE;
> }
> data = LOAD 'case.csv' USING PigStorage(',') AS (value: int, valid: boolean);
> P, Q = my_macro(data);
> DUMP P;
> DUMP Q;
> {code}
> Pig is unable to recognize the {{OTHERWISE}} side. Error is: {{ERROR
> org.apache.pig.tools.grunt.Grunt - ERROR 1200: <at case.pig, line 3> Invalid
> macro definition: . Reason: Macro 'my_macro' missing return alias: invalid}}
> Simple workaround is to force {{$invalid}} to be returned as {{FOREACH}}
> result:
> {code}
> SPLIT added INTO $valid IF $1 == true, tmp_invalid OTHERWISE;
> $invalid = FOREACH tmp_invalid GENERATE *;
> {code}
> Samples and logs attached to the issue.
--
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