我有以下方式的数据集。
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使用以下命令加载上述数据。 以下是我用来加载文件的代码。
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);
但它不是在读取日期列而是在使用dump file命令后给出以下输出。
(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,,)
我如何阅读日期栏。
请在这方面帮助我。
感谢-你。
答案 0 :(得分:1)
将日期加载为chararray,然后转换为日期格式
像:
file2 = FOREACH文件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
答案 1 :(得分:0)
将数据加载为chararray。
file = LOAD'FI_USER_CREDS_TBL_T.txt'使用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:chararray);
- ToDate builtIn函数用于转换为datetime,格式需要指定
文件2 = FOREACH文件GENERATE USER_ID,ROLE_ID,USER_PW,NUM_PWD_HISTORY,PWD_HISTORY,PWD_LAST_MOD_TIME,NUM_PWD_ATTEMPTS,NEW_USER_FLG,LOGIN_TIME_LOW,LOGIN_TIME_HIGH,DISABLED_FROM_DATE,DISABLED_UPTO_DATE,PW_EXPY_DATE,ACCT_EXPY_DATE,ACCT_INACTIVE_DAYS,LAST_ACCESS_TIME,TS_CNT,DTL__CAPXTIMESTAMP,TODATE(ETL_INSERT_DATE,“YYYY -MM-dd')AS ETL_INSERT_DATE;
描述file2; dump file2;