[Solved-1 Solution] How to get the value for a variable key from a pig map ?



What is pigmap ?

  • A map in Pig is a chararray to data element mapping, where that element can be any Pig type, including a complex type.
  • The chararray is called a key and is used as an index to find the element, referred to as the value.

Problem :

How to get the value for a variable key from a pig map ?

Solution 1:

  • Its not possible to do that in Pig. The key has to be static value.

Example:

final_company_data = FOREACH company_data GENERATE
                                         value.locale as locale
                                         value.name#'en_US';
  • If the key set size of the above program is not too big.we can use the below one.
= FILTER company_data BY value.locale == 'en_US';
final_company_data_en = FOREACH company_data GENERATE
                                         value.locale as locale
                                         value.name#'en_US';
fr = FILTER company_data BY value.locale == 'fr_FR';
final_company_data_en = FOREACH company_data GENERATE
                                         value.locale as locale
                                         value.name#'fr_FR';

How to get the value for a variable key from a pig map

Learn Apache pig - Apache pig tutorial - Pig value chain map - Apache pig examples - Apache pig programs


Related Searches to How to get the value for a variable key from a pig map?