pig tutorial - apache pig tutorial - Splitting input into substrings in PIG (Hadoop) ? - pig latin - apache pig - pig hadoop
What is substring ?
- A substring of a string is a string that occurs "in" . For example, "the best of" is a substring of "It was the best of times".
- This is not to be confused with subsequence, which is a generalization of substring. For example, "Itwastimes" is a subsequence of "It was the best of times", but not a substring.
What is hadoop ?
- Hadoop is an open source, Java-based programming framework that supports the processing and storage of extremely large data sets in a distributed computing environment
- On Hadoop system using Apache Pig you can write very simple code that will split file on the fly. we will have the flexibility to control flow of data and do manipulations (if any) and split file.
Now we see how to split file into individual files using Pig Script. Here is our sample file
- In the sample file if we see there are lot of headers and trailers and some data between them. Our requirement is to split each set of data with HEADER, TRAILER and DETAIL DATA into individual files. For our sample it should generate 6 different files.
- We will split file using key values in the file. Here we use positions 11-15 (5 characters) in DETAIL DATA and positions 8-12 in HEADER and TRAILER data. We must maintain the consistency of the data as Header row, Details rows and Trailer row.
- This makes the complete structure of file and keeps all data together.
Now we write Pig Script to split the file -
- File is split on the value we taken as key value. Here our key value from all rows (Header, Details and Trailer) is 5 characters specified using function substring() at transformtions ‘D’ and ‘E’.
Now we will see output directory for files -
Learn Apache pig - Apache pig tutorial - Pig split string example - Apache pig examples - Apache pig programs
Learn Apache pig - Apache pig tutorial - Pig Substring - Apache pig examples - Apache pig programs
Learn Apache pig - Apache pig tutorial - Split in pig - Apache pig examples - Apache pig programs