- Apache Pig 教程
- Apache Pig - 首頁
- Apache Pig 簡介
- Apache Pig - 概述
- Apache Pig - 架構
- Apache Pig 環境
- Apache Pig - 安裝
- Apache Pig - 執行
- Apache Pig - Grunt Shell
- Pig Latin
- Pig Latin - 基礎
- 載入和儲存運算子
- Apache Pig - 讀取資料
- Apache Pig - 儲存資料
- 診斷運算子
- Apache Pig - 診斷運算子
- Apache Pig - Describe 運算子
- Apache Pig - Explain 運算子
- Apache Pig - Illustrate 運算子
- Pig Latin 內建函式
- Apache Pig - 評估函式
- 載入和儲存函式
- Apache Pig - Bag 和 Tuple 函式
- Apache Pig - 字串函式
- Apache Pig - 日期時間函式
- Apache Pig - 數學函式
- Apache Pig 有用資源
- Apache Pig - 快速指南
- Apache Pig - 有用資源
- Apache Pig - 討論
Apache Pig - AddDuration() 函式
此函式接受一個日期時間物件和一個持續時間物件,並將給定的持續時間新增到日期時間物件中,並返回一個包含已新增持續時間的新日期時間物件。
語法
以下是 AddDuration() 函式的語法。
grunt> AddDuration(datetime, duration)
注意 - 持續時間以 ISO 8601 標準表示。根據 ISO 8601 標準,P 放在開頭表示持續時間,稱為持續時間指示符。
Y 是年份指示符。我們在宣告年份後使用它。
示例 - P1Y 代表 1 年。
M 是月份指示符。我們在宣告月份後使用它。
示例 - P1M 代表 1 個月。
W 是星期指示符。我們在宣告星期後使用它。
示例 - P1W 代表 1 周。
D 是日指示符。我們在宣告日後使用它。
示例 - P1D 代表 1 天。
T 是時間指示符。我們在宣告時間前使用它。
示例 - PT5H 代表 5 小時。
H 是小時指示符。我們在宣告小時後使用它。
示例 - PT1H 代表 1 小時。
M 是分鐘指示符。我們在宣告分鐘後使用它。
示例 - PT1M 代表 1 分鐘。
S 是秒指示符。我們在宣告秒後使用它。
示例 - PT1S 代表 1 秒。
示例
假設在 HDFS 目錄 `/pig_data/` 中有一個名為 `date.txt` 的檔案。此檔案包含特定人員的出生日期詳細資訊、ID、日期和時間以及一些符合 ISO 8601 標準的持續時間。
date.txt
001,1989/09/26 09:00:00,PT1M 002,1980/06/20 10:22:00,P1Y 003,1990/12/19 03:11:44,P3M
並且,我們已使用名為 `date_duration` 的關係將此檔案載入到 Pig 中,如下所示。
grunt> date_duration = LOAD 'hdfs://:9000/pig_data/date.txt' USING PigStorage(',')
as (id:int, date:chararray, duration:chararray)
以下是 `AddDuration()` 函式的示例。您可以使用此方法將某些持續時間新增到給定的日期時間物件,如下所示。
grunt> Add_duration_data = foreach date_duration generate(date,duration), AddDuration(ToDate(date,'yyyy/MM/dd HH:mm:ss'), duration);
語句的結果將儲存在名為 `add_duration_data` 的關係中。使用 Dump 運算子驗證此關係的內容,如下所示。
grunt> Dump add_duration_data; ((1989/09/26 09:00:00,PT1M),1989-09-26 T09:01:00.000+05:30) ((1980/06/20 10:22:00,P1Y),1981-06-20 T10:22:00.000+05:30) ((1990/12/19 03:11:44,P3M),1991-03-19 T03:11:44.000+05:30)
apache_pig_date_time_functions.htm
廣告