I'm trying to structure the un-structured data using PIG for doing some processing.
Here's the sample of the data:
Nov 1 18:23:34 dev_id=03 user_id=000 int_ip=198.0.13.24 ext_ip=68.67.0.14 src_port=99 dest_port=213 response_code=5
Expected output:
Nov 1 18:23:34, 03 , 000, 198.0.13.24, 68.67.0.14, 99, 213, 5
As we can see data is not properly separated (like tab or comma), so i tried to load the data using '\t' and dumped on the terminal.
A = LOAD '----' using PigStorage('\t') as (mnth: chararray, day: int, --------);
dump A;
Store A into '\root\output';
Output:
Dump output:
(Nov,1,18:23:34,dev_id=03,user_id=000,int_ip=198.0.13.24,ext_ip=68.67.0.14,src_port=99,dest_port=213,response_code=5)
Store oputut: Results are stored as the same as the input, not as dump(comma separated).
Nov 1 18:23:34 dev_id=03 user_id=000 int_ip=198.0.13.24 ext_ip=68.67.0.14 src_port=99 dest_port=213 response_code=5
Alternative: I also tried to load the data using DataStorage() as (value: varchar) and performed TOKENIZE also, but not able to achieve the objective.
Few more suggestion i need:
As i stored 3 fields as Month:"Nov", Day:"1", and Time:"18:23:34". Is it possible to join all three fields as time: "Nov 1 18:23:34".
All data stored with information like dev_id=03, user_id=000 but i need to remove the information and stored the information like 03,000,198.0.13.24 etc.
Is it possible to do all the processing using PIG or we need to write the MapReduce program.
EDIT:1
After getting the comment, I tried REGEX_EXTRACT for single column which works fine. For multiple column, i tried REGEX_EXTRACT_ALL as follows:
A = LOAD '----' using PigStorage('\t') as (mnth: chararray, day: int, dev: chararray, user: chararray --------);
B = foreach A generate REGEX_EXTRACT_All(devid, userid, '(^.*=(.*)$) (^.*=(.*)$)');
Dump B;
I got error:
Error: ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1070: Could not resolve REGEX_EXTRACT_All using imports.
Can we extract multiple fields using REGEX_EXTRACT_All.