pig tutorial - apache pig tutorial - Apache Pig LAST_INDEX_OF() - pig latin - apache pig - pig hadoop
What is LAST_INDEX_OF?
- The LAST_INDEX_OF() function accepts a string value and a character.
- It returns the last occurrence of the given character in the string, searching backward from the end of the string.
- Given below is the syntax of the LAST_INDEX_OF() function.
- Assume that there is a file named wikitechy_emp.txt in the HDFS directory /pig_data/as shown below. This file contains the employee details such as id, name, age, and city.
- And, we have loaded this file into Pig with a relation named Wikitechy_emp_data as shown below.
- Given below is an example of the LAST_INDEX_OF() function. In this example, we are going to find the occurrence of the letter 'e' from the end, in the names of every employee.
- The above statement parses the name of each employee from the end and returns the index value at which the letter ‘e’ occurred for the first time. If the name doesn’t contain the letter ‘e’ it returns the value −1
- The result of the statement will be stored in the relation named last_index_data. Verify the content of the relation last_index_data using the Dump operator as shown below.