本文介绍了如何使用pig将UTC时间转换为IST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个机器数据进入hdfs如下,第8个字段是UTC时间(060037),我需要将其转换为IST,并将时间格式设置为hh:mm:ss使用pig

I have a machine data comes into hdfs as below , the 8th field is UTC time(060037) , i need to convert it into IST and make the time format as hh:mm:ss using pig

VTS,01,0097,9739965515,NM,GP,20,060037,V,0000.0000,N,00000.0000,E,0.0,0.0,061114,0068,00,4000,00,999,149,9594
VTS,01,0097,9739965515,SP,GP,33,060113,V,0000.0000,N,00000.0000,E,0.0,0.0,061114,0068,00,4000,00,999,152,B927

使用字符串函数我试图将其转换为unix日期格式现在我得到时间像 2014-11-06 06:01:13 它的UTC格式如何将它转换成IST有没有任何内建函数可以这样做?

using string function i tried to convert it into a unix date format now i am getting time like 2014-11-06 06:01:13 its in UTC format how to convert it into IST is there any inbuild functions available to do this?

A = LOAD '/user/hue/Anas' AS (line:chararray);
B = FOREACH A {
             splitRow = TOKENIZE(line,'+++');
             GENERATE FLATTEN(splitRow) AS newList;
          }
C = FOREACH B GENERATE FLATTEN(STRSPLIT(newList,',',23));
D = FILTER C BY $1==01;
E = foreach D generate $7 as time,$15 as date;
F = foreach E generate SUBSTRING(time,0,2) as hh,SUBSTRING(time,2,4) as mm,SUBSTRING(time,4,6) as ss,SUBSTRING(date,0,2) as date,SUBSTRING(date,2,4) as month,SUBSTRING(date,4,6) as year;
G = foreach F generate CONCAT('20',CONCAT(year,CONCAT('-',CONCAT(month,CONCAT('-',date))))) as date,CONCAT(hh,CONCAT(':',CONCAT(mm,CONCAT(':',ss)))) as time;
H = FOREACH G GENERATE CONCAT(date,CONCAT(' ',time)) AS UTC;
DUMP H;


推荐答案

请将以下3行添加到现有代码中,它将工作

Please add the below 3 lines to your existing code, it will work

I = FOREACH H GENERATE ToDate(UTC,'yyyy-MM-dd HH:mm:ss','UTC') AS UTCTime;
J = FOREACH I GENERATE ToDate(ToString(UTCTime,'yyyy-MM-dd HH:mm:ss.SSSZ'),'yyyy-MM-dd HH:mm:ss.SSSZ','Asia/Kolkata') AS ISTTime;
DUMP J

UTC时间的输出:

(2014-11-06 06:00:37)
(2014-11-06 06:01:13)

IST时间的输出:

(2014-11-06T11:30:37.000+05:30)
(2014-11-06T11:31:13.000+05:30)

这个 ISTTime 在datetime对象中,现在可以使用所有的内置函数(GetDay(),GetTime()等)。

This ISTTime is in datetime object, now you can use all the build-in functions (GetDay(),GetTime() etc).

这篇关于如何使用pig将UTC时间转换为IST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 07:42