pig tutorial - apache pig tutorial - Apache Pig - COS() - pig latin - apache pig - pig hadoop




What is COS() function?

  • The cosine function is one of the basic functions encountered in trigonometry (the others being the cosecant, cotangent, secant, sine, and tangent).
  • Let be an angle measured counterclockwise from the x-axis along the arc of the unit circle. Then is the horizontal coordinate of the arc endpoint.
 cos function in apache pig

Learn apache pig - apache pig tutorial - cos function in apache pig - apache pig examples - apache pig programs

COS() function in Apache pig

  • The COS() function of Apache Pig Latin is used to calculate the cosine value of a specified expression.

Syntax:

grunt> COS(expression)

Example:

  • Ensure that we have a file named wikitechy_math.txt in the HDFS directory /pig_data/.
  • This file contains integer and floating point values is given below.

wikitechy_math.txt

5 
16 
9 
2.5 
5.9 
3.1
  • We have loaded this file into Pig with a relation named math_data as shown below.
grunt> math_data = LOAD 'hdfs://localhost:9000/pig_data/wikitechy_math.txt' USING PigStorage(',')
   as (data:float)
  • We are calculate the cosine values of the contents of the wikitechy_math.txt file using COS() function as given below.
grunt> cos_data = foreach math_data generate (data), COS(data);
  • Above statement stores the result in the relation named cos_data

Verification:

  • Now you can verify the contents of the relation using the Dump operator as shown below.
grunt> Dump cos_data;

Output:

The output shows that the result in the file>cos_data.

(5.0,0.28366218546322625) 
(16.0,-0.9576594803233847) 
(9.0,-0.9111302618846769) 
(2.5,-0.8011436155469337) 
(5.9,0.9274784663996888) 
(3.1,-0.999135146307834) 

Related Searches to Apache Pig - COS()