Q:

Apache Pig reading name value pairs in data file

i have a sample pig script with data that will read a csv file and dump it ot screen; however, my data has name value pairs.   how can i read in a line of name value pairs and split the pairs using the name for the field and the value for the value? 
data:
1,Smith,Bob,Business Development
2,Doe,John,Developer
3,Jane,Sally,Tester

script:  
data = LOAD 'example-data.txt' USING PigStorage(',') 
           AS (id:chararray, last_name:chararray, 
           first_name:chararray, role:chararray);
DESCRIBE data;
DUMP data;

output:
data: {id: chararray,last_name: chararray,first_name: chararray,role: chararray}
(1,Smith,Bob,Business Development)
(2,Doe,John,Developer)
(3,Jane,Sally,Tester)

however, given the following input (as name value pairs); how could i process the data to get the same "data object"? 
id=1,last_name=Smith,first_name=Bob,role=Business Development
id=2,last_name=Doe,first_name=John,role=Developer
id=3,last_name=Jane,first_name=Sally,role=Tester

A:

Refer to STRSPLIT
A = LOAD 'example-data.txt' USING PigStorage(',') AS (f1:chararray,f2:chararray,f3:chararray, f4:chararray);
B = FOREACH A GENERATE
               FLATTEN(STRSPLIT(f1,'=',2)) as (n1:chararray,v1:chararray),
               FLATTEN(STRSPLIT(f2,'=',2)) as (n2:chararray,v2:chararray),
               FLATTEN(STRSPLIT(f3,'=',2)) as (n3:chararray,v3:chararray),
               FLATTEN(STRSPLIT(f4,'=',2)) as (n4:chararray,v4:chararray);
C = FOREACH B GENERATE v1,v2,v3,v4;
DUMP C;

