比较猪中的datetime [英] comparing datetime in pig

查看:95
本文介绍了比较猪中的datetime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在pig 11中,是否有比较datetime类型的支持?例如:date1:​​datetime

in pig 11, is there a support for comparing datetime types? for example: date1:datetime

并且过滤条件:date1> = ToDate('1999-01-01')

and filter has condition: date1 >= ToDate('1999-01-01')

这个比较是否返回正确的结果?

does this comparison returns correct result?

推荐答案

日期比较可以被视为数值比较。
例如:

Date comparison can be considered as a numerical comparison. E.g:

cat date1.txt
1999-01-01
2011-03-19
2011-02-24
2011-02-25
2011-05-23
1978-12-13

A = load 'date1.txt' as (in:chararray);
B = foreach A generate ToDate(in, 'yyyy-MM-dd') as (dt:datetime);
--filter dates that are equal or greater than 2011-02-25: 
C = filter B by DaysBetween(dt, 
      (datetime)ToDate('2011-02-25', 'yyyy-MM-dd')) >=(long)0;

dump C;
(2011-03-19T00:00:00.000+01:00)
(2011-02-25T00:00:00.000+01:00)
(2011-05-23T00:00:00.000+02:00)

自定义格式模式传递到ToDate 遵循Java的SimpleDateFormat 约会。

注意大写和小写字母,例如 D 表示日期,但 d 指的是

The custom format pattern passed to ToDate follows the Java's SimpleDateFormat convention.
Watch out for the uppercase and lowercase letters, for example D means Day in year but d refers to Day in month . This can lead to an inappropriate date conversion from chararray to datetime.

或者,如果您的字符集日期采用ISO格式,则可以使用 Piggybank 的UDF。

Alternatively, if your chararray dates are in ISO format, you may use the Piggybank's UDFs as well.

这篇关于比较猪中的datetime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆