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




What is TAN() function?

  • Tangent (tan) function is a Trigonometry function.
  • In a right triangle, the tangent of an angle is the length of the opposite side divided by the length of the adjacent side.
  • Sine, Cosine and Tangent are the main functions used in Trigonometry and are based on a Right-Angled Triangle.
  • Before getting stuck into the functions, it helps to give a name to each side of a right triangle: "Opposite" is opposite to the angle θ "Adjacent" is adjacent (next to) to the angle θ.
 tangent

Learn Apache Pig - Apache Pig tutorial - tangent - Apache Pig examples - Apache Pig programs

TAN() function in Apache Pig

  • The TAN() function is used to calculate the trigonometric tangent of a given expression (angle).

Syntax

grunt> TAN(expression)
  • Ensure that we have a file named wikitechy_math.txt in the HDFS directory /pig_data/. This file contains integer and floating point values as 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 given below.
grunt> math_data = LOAD 'hdfs://localhost:9000/pig_data/wikitechy_math.txt' USING PigStorage(',')
   as (data:float);
  • Now you can generate the tan values of the contents of the wikitechy_math.txt file using TAN() function as given below.
grunt> tan_data = foreach math_data generate (data), TAN(data);

Verification

  • Verify the contents of the relation using the Dump operator as given below.
grunt> Dump tan_data;

Output

  • The above statement stores the result in the relation named tan_data.
(5.0,-3.380515006246586) 
(16.0,0.3006322420239034) 
(9.0,-0.45231565944180985) 
(2.5,-0.7470222972386603) 
(5.9,-0.4031107890087444) 
(3.1,-0.041616750118239246)

Related Searches to Apache Pig - TAN()