使用 PIG 加载日期时间格式文件 [英] Loading datetime format files using PIG

查看:33
本文介绍了使用 PIG 加载日期时间格式文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下方式的数据集.

I have a dataset in the following way.

ravi,savings,avinash,2,char,33,F,22,44,12,13,33,44,22,11,10,22,2006-01-23
avinash,current,sandeep,3,char,44,M,33,11,10,12,33,22,39,12,23,19,2001-02-12
supreeth,savings,prabhash,4,char,55,F,22,12,23,12,44,56,7,88,34,23,1995-03-11
lavi,current,nirmesh,5,char,33,M,11,10,33,34,56,78,54,23,445,66,1999-06-15
Venkat,savings,bunny,6,char,11,F,99,12,34,55,33,23,45,66,23,23,2016-05-18

最后一列(例如:2006-01-23)是日期.我正在尝试使用 PIG 使用以下命令加载上述数据.以下是我用来加载文件的代码.

the last column(example:2006-01-23) is date. I am trying to load the above data with following command using PIG. Following is the code which i am using to load the file.

file = LOAD 'FI_USER_CREDS_TBL_T.txt' 
       USING PigStorage(',') AS (USER_ID:chararray,
                                 ROLE_ID:chararray,
                                 USER_PW:chararray,
                                 NUM_PWD_HISTORY:int,
                                 PWD_HISTORY:chararray,                                     
                                 PWD_LAST_MOD_TIME:int,
                                 NUM_PWD_ATTEMPTS:int,
                                 NEW_USER_FLG:chararray,
                                 LOGIN_TIME_LOW:int,
                                 LOGIN_TIME_HIGH:int,
                                 DISABLED_FROM_DATE:int,
                                 DISABLED_UPTO_DATE:int,
                                 PW_EXPY_DATE:int,
                                 ACCT_EXPY_DATE:int,
                                 ACCT_INACTIVE_DAYS:int,                                     
                                 LAST_ACCESS_TIME:int,
                                 TS_CNT:int,
                                 DTL__CAPXTIMESTAMP:int,
                                 ETL_INSERT_DATE:datetime);

但它没有读取日期列,而是在使用转储文件命令后给出以下输出.

But it is not reading the date column instead it is giving following output after using dump file command.

(ravi,savings,avinash,2,char,33,,22,44,12,13,33,44,22,11,10,22,,)
(avinash,current,sandeep,3,char,44,,33,11,10,12,33,22,39,12,23,19,,)
(supreeth,savings,prabhash,4,char,55,,22,12,23,12,44,56,7,88,34,23,,)
(lavi,current,nirmesh,5,char,33,,11,10,33,34,56,78,54,23,445,66,,)
(Venkat,savings,bunny,6,char,11,,99,12,34,55,33,23,45,66,23,23,,)

如何读取日期列.

请在这方面帮助我.

谢谢.

推荐答案

将日期加载为字符数组,然后转换为日期格式

Load date as chararray and then convert into date format

喜欢:

file2 = FOREACH file GENERATE ToDate(date, 'dd/MM/yyyy') AS date,....

file2 = FOREACH file GENERATE ToDate(date, 'dd/MM/yyyy') AS date,....

试试这个链接以供参考,http://pig.apache.org/docs/r0.11.0/api/org/apache/pig/builtin/ToDate.html或者http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

Try this link for reference, http://pig.apache.org/docs/r0.11.0/api/org/apache/pig/builtin/ToDate.html OR http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

这篇关于使用 PIG 加载日期时间格式文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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