Apache Pig - CurrentTime() 函式



此函式用於生成當前時間的DateTime物件。

語法

以下是CurrentTime()函式的語法。

grunt> CurrentTime() 

示例

假設在HDFS目錄/pig_data/中有一個名為date.txt的檔案。此檔案包含特定人員的出生日期詳細資訊,包括ID、日期和時間。

date.txt

001,1989/09/26 09:00:00
002,1980/06/20 10:22:00
003,1990/12/19 03:11:44 

並且,我們已使用名為date的關係將此檔案載入到 Pig 中,如下所示。

grunt> date_data = LOAD 'hdfs://:9000/pig_data/date.txt' USING PigStorage(',')
   as (id:int,date:chararray);

以下是CurrentTime()函式的示例。在這裡,我們正在生成當前時間。

grunt> currenttime_data = foreach todate_data generate CurrentTime();

語句的結果將儲存在名為currenttime_data的關係中。使用 Dump 運算子驗證此關係的內容。

grunt> Dump currenttime_data;
  
(2015-11-06T11:31:02.013+05:30)
(2015-11-06T11:31:02.013+05:30) 
(2015-11-06T11:31:02.013+05:30) 
apache_pig_date_time_functions.htm
廣告
© . All rights reserved.