在猪身上正确加载日期时间 [英] properly loading datetime in pig
本文介绍了在猪身上正确加载日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用datetime列和long列加载tsv文件:
A = LOAD'tweets-clean .txt'USING PigStorage('\t')AS(date:datetime,userid:long);
DUMP A;
一行输入示例:
2月11日星期二05:02:10 +0000 2014 205291417
该行的输出:
,205291417
如何正确执行此操作?
解决方案
一个chararray(日期:chararray),然后可以使用 FOREACH GENERATE
以及 ToDate
猪内置函数。
格式字符串基于 SimpleDateFormat
$ b
A = LOAD'tweets-clean.txt'使用PigStorage('\t')AS(date:chararray,userid:long);
B = FOREACH A GENERATE ToDate(日期,'<某个格式字符串>')AS日期,userid;
DUMP B;
I'm loading a tsv file with a datetime column and long column with:
A = LOAD 'tweets-clean.txt' USING PigStorage('\t') AS (date:datetime, userid:long);
DUMP A;
An example line of input:
Tue Feb 11 05:02:10 +0000 2014 205291417
that line of output:
, 205291417
How do I do this properly?
解决方案
You'd want to load date as a chararray (date:chararray) and then can convert it to to a datetime using FOREACH GENERATE
along with the ToDate
Pig built-in function.
The format string is based on the SimpleDateFormat
A = LOAD 'tweets-clean.txt' USING PigStorage('\t') AS (date:chararray, userid:long);
B = FOREACH A GENERATE ToDate(date, '<some format string>') AS date, userid;
DUMP B;
这篇关于在猪身上正确加载日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文