Pig Latin的 LOG10() 函數(shù)用于計算給定表達式的基于10的自然對數(shù)值。
grunt> LOG10(expression)
假設(shè)在HDFS目錄/pig_data/中有一個名為math.txt的文件。此文件包含整數(shù)和浮點值,如下所示。
math.txt
5 16 9 2.5 5.9 3.1
通過使用math_data關(guān)系將此文件加載到Pig中,如下所示。
grunt> math_data = LOAD 'hdfs://localhost:9000/pig_data/math.txt' USING PigStorage(',') as (data:float);
現(xiàn)在使用 LOG10() 函數(shù)計算math.txt文件內(nèi)容的log10值,如下所示。
grunt> log_data = foreach math_data generate (data),LOG10(data);
上述語句結(jié)果將存儲在名為 log_data 的關(guān)系中。使用Dump運算符驗證關(guān)系的內(nèi)容,如下所示。
grunt> Dump log10_data; (5.0,0.6989700043360189) (16.0,1.2041199826559248) (9.0,0.9542425094393249) (2.5,0.3979400086720376) (5.9,0.7708520186620678) (3.1,0.4913616804737727)
更多建議: