pig tutorial - apache pig tutorial - Apache Pig STARTSWITH() - pig latin - apache pig - pig hadoop
What is STARTSWITH() method in Apache Pig ?
- The startsWith() method determines whether a string begins with the characters of a specified string.
- This method returns true if the string begins with the characters, and false if not. Note: The startsWith() method is case sensitive.
- This function accepts two string parameters. It verifies whether the first string starts with the second.
- Given below is the syntax of the STARTSWITH() 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.
- Following is an example of the STARTSWITH() function. In this example, we have verified whether the names of all the employees start with the substring “Aa”.
- The above statement parses the names of all the employees if any of these names starts with the substring ‘Aa’.
- Since the names of the employees ‘Aadav’ and ‘Aadhi’ starts with the substring ‘Aa’ for these two tuples the STARTSWITH() function returns the Boolean value ‘true’ and for remaining tuples the value will be ‘false’.
- The result of the statement will be stored in the relation named startswith_data. Verify the content of the relation startswith_data, using the Dump operator as shown below.