pig tutorial - apache pig tutorial - Apache Pig - GetYear() - pig latin - apache pig - pig hadoop
What is GetYear() method?
- The getYear() method returns the year in the specified date according to local time.
- Because getYear() does not return full years ("year 2000 problem"), it is no longer used and has been replaced by the getFullYear() method.
Syntax
Learn apache pig - apache pig tutorial - get year in apache pig - apache pig examples - apache pig programs
GetYear() function in Apache Pig
- This function accepts a date-time object as parameter and returns the current year from the given date-time object.
Syntax
Example
- Ensure that we have a file named wikitechy_date.txt in the HDFS directory /pig_data/ as shown below.
- This file contains the date-of-birth details of a particular person, it has person id, date and time.
wikitechy_date.txt
We have loaded this file into Pig with a relation named date_data as given below.
- Following is an example of the GetYear() function.
- It will retrive the current year from the given date-time object.
- So, First we can generate the date-time objects of all employees using todate() function as given below.
- Now we get the year from the date-of-birth of each employee using the GetYear() function and store it in the relation named getyear_data.
Verification
- Now verify the contents of the getyear_data relation using Dump operator as given below.
Output
The above statement stores the result in the relation named getyear_data.