[ https://issues.apache.org/jira/browse/PIG-1793?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12994601#comment-12994601 ]
Richard Ding commented on PIG-1793: ----------------------------------- See review comment here: https://reviews.apache.org/r/419/ > Add macro expansion to Pig Latin > -------------------------------- > > Key: PIG-1793 > URL: https://issues.apache.org/jira/browse/PIG-1793 > Project: Pig > Issue Type: New Feature > Reporter: Richard Ding > Assignee: Richard Ding > Fix For: 0.9.0 > > Attachments: PIG-1793.patch, PIG-1793_1.patch, PIG-1793_2.patch > > > As production Pig scripts grow longer and longer, Pig Latin has a need to > integrate standard programming techniques of separation and code sharing > offered by functions and modules. A proposal of adding macro expansion to > Pig Latin is posted here: http://wiki.apache.org/pig/TuringCompletePig > Below is a brief summary of the proposed syntax (and examples): > * Macro Definition > The existing DEFINE keyword will be expanded to allow definitions of Pig > macros. > *Syntax* > {code} > define <name> (<params>) returns <aliases> { > <Pig Latin fragment> > }; > {code} > *Example* > {code} > define my_macro(A, sortkey) returns C { > B = filter $A by my_filter(*); > $C = order B by $sortkey; > } > {code} > * Macro Expansion > *Syntax* > {code} > <aliases> = <macro name> (<params>); > {code} > *Example:* Use above macro in a Pig script: > {code} > X = load 'foo' as (user, address, phone); > Y = my_macro(X, user); > store Y into 'bar'; > {code} > This script is expanded into the following Pig Latin statements: > {code} > X = load 'foo' as (user, address, phone); > macro_my_macro_B_1 = filter X by my_filter(*); > Y = order macro_my_macro_B_1 by user; > store Y into 'bar'; > {code} > *Notes* > 1. Any alias in the macro which isn't visible from outside will be prefixed > with macro name and suffixed with instance id to avoid namespace collision. > 2. Macro expansion is not a complete replacement for function calls. > Recursive expansions are not supported. > * Macro Import > The new IMPORT keyword can be used to add macros defined in another Pig Latin > file. > *Syntax* > {code} > import <Pig Latin file name>; > {code} > *Example* > {code} > import my_macro.pig; > {code} > *Note:* All macro names are in the global namespace. -- This message is automatically generated by JIRA. - For more information on JIRA, see: http://www.atlassian.com/software/jira