×

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 诊断运算符

Apache Pig Diagnostic运算符Apache Pig Describe运算符Apache Pig Explain运算符Apache Pig illustrate运算符

Apache Pig 分组和连接

Apache Pig Group运算符Apache Pig Cogroup运算符Apache Pig Join运算符Apache Pig Cross运算符

Apache Pig 合并和拆分

Apache Pig Union运算符Apache Pig Split运算符

Apache Pig 过滤

Apache Pig Filter运算符Apache Pig Distinct运算符Apache Pig Foreach运算符

Apache Pig 排序

Apache Pig Order By运算符Apache Pig Limit运算符

Pig Latin 内置函数

Apache Pig Eval函数Apache Pig 加载和存储函数Apache Pig 包和元组函数Apache Pig 字符串函数Apache Pig 日期时间函数Apache Pig 数学函数

Apache Pig 其他执行模式

Apache Pig 用户定义函数Apache Pig 运行脚本

Apache Pig 有用的资源

Apache Pig 有用资源Apache Pig 讨论

Apache Pig SubtractDuration()函数


Apache Pig 日期时间函数Apache Pig 日期时间函数


此函数接受日期时间对象和持续时间对象,并从日期时间对象中减去给定的持续时间,返回新的日期时间对象。

语法

这是 SubtractDuration() 函数的语法。

grunt> SubtractDuration(datetime, duration)

假设在 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://localhost:9000/pig_data/date.txt' USING PigStorage(',')
   as (id:int, date:chararray, duration:chararray)

以下是 SubtractDuration() 函数的示例。你可以使用此方法从给定的日期时间对象中减去某个持续时间,如下所示。

subtractduration_data = foreach date_duration generate(date,duration), 
   SubtractDuration(ToDate(date,'yyyy/MM/dd HH:mm:ss'), duration);

语句的结果将存储在名为 subtractduration_data 的关系中。使用Dump运算符验证此关系的内容,如下所示。

grunt> Dump subtractduration_data;
  
((1989/09/26 09:00:00,PT1M),1989-09-26 T08:59:00.000+05:30)
((1980/06/20 10:22:00,P1Y),1979-06-20 T10:22:00.000+05:30)
((1990/12/19 03:11:44,P3M),1990-09-19 T03:11:44.000+05:30)

Apache Pig 日期时间函数Apache Pig 日期时间函数


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)
0.037741s