I am using macros in pig , however it throws me an error saying : undefined alias 'result_1'.
The macro i am using :
define macro_result (source , metric_name , metric_value) returns result_metric
{
result_1= foreach $source generate
timestamp,
member_sk as id,
'$metric_name' as minor_metric,
'Lts_seo' as major_metric,
$metric_value as value;
$result_metric = result_1;
};
I am calling the macro as :
page_views_to_jserp_from_job_detail = macro_result(metadata_final,'PAGE_VIEWS_TO_JSERP_FROM_JOB_DETAIL', PV_to_jserp_from_job_detail );
I changed the macro to this and the error seems to be resolved (change bolded) :
define macro_result (source , metric_name , metric_value) returns result_metric
{
***$result_metric***= foreach $source generate
timestamp,
member_sk as id,
'$metric_name' as minor_metric,
'Lts_seo' as major_metric,
$metric_value as value;
***-- $result_metric = result_1;***
};
What was causing the error initially? why can't i use result_1 as an intermediate step and store it in result_metric inside the macro?
We can NOT assign one alias directly to another.
We can project the required fields from one alias and return the same.
For the use case shared :
$result_metric = FOREACH result_1 GENERATE *;
This step is not required unless there is a change in projected fields between these two aliases.