You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by Muni mahesh <ma...@gmail.com> on 2013/09/19 16:44:30 UTC

Timestamp difference between login and logout

*Sample data *

*       Login                         Logout*
2013-01-16 04:01:18    2013-01-16 04:01:36
2013-01-16 04:02:19    2013-01-16 04:03:11

*Query *

grunt> A = load '/home/user/Desktop/1' using PigStorage(';') AS (f1 :
double, f2: double);

2013-09-19 20:19:02,316 [main] WARN  org.apache.pig.PigServer - Encountered
Warning IMPLICIT_CAST_TO_DOUBLE 6 time(s).

grunt> B = foreach A generate (f2-f1);

2013-09-19 20:19:04,611 [main] WARN  org.apache.pig.PigServer - Encountered
Warning IMPLICIT_CAST_TO_DOUBLE 6 time(s).

grunt> dump B;

*output :*

()
()


*Output expected *

(18)
(52)

Re: Timestamp difference between login and logout

Posted by Tom Wheeler <to...@gmail.com>.
Was there meant to be a question there?

At first glance, one problem seems to be that you're loading fields
delimited by semicolons, but the sample data you posted is separated by
whitespace. Another is that you're defining those fields as type double,
but that is probably not the best choice for timestamp data.

There are various ways to find the difference between two timestamps
depending on the version of Pig that you're using, but one approach that
should work in any version is to use a function to convert those timestamps
to UNIX time format (i.e. of type long) and then subtract the login time
from the logout time.



On Thu, Sep 19, 2013 at 9:44 AM, Muni mahesh <ma...@gmail.com>wrote:

> *Sample data *
>
> *       Login                         Logout*
> 2013-01-16 04:01:18    2013-01-16 04:01:36
> 2013-01-16 04:02:19    2013-01-16 04:03:11
>
> *Query *
>
> grunt> A = load '/home/user/Desktop/1' using PigStorage(';') AS (f1 :
> double, f2: double);
>
> 2013-09-19 20:19:02,316 [main] WARN  org.apache.pig.PigServer - Encountered
> Warning IMPLICIT_CAST_TO_DOUBLE 6 time(s).
>
> grunt> B = foreach A generate (f2-f1);
>
> 2013-09-19 20:19:04,611 [main] WARN  org.apache.pig.PigServer - Encountered
> Warning IMPLICIT_CAST_TO_DOUBLE 6 time(s).
>
> grunt> dump B;
>
> *output :*
>
> ()
> ()
>
>
> *Output expected *
>
> (18)
> (52)
>



-- 
Tom Wheeler
http://www.tomwheeler.com/