Below is the data.
col1,col2 combination will give unique key. col3 has 2 different timestamp formats with one being TZ format(2015-02-14T03:45:23.345Z), the other being normal format(2015-02-14 03:45:23).
col1,col2,col3,col4
rank1,IP1,2015-02-14T03:45:23.345Z,2015-02-12 00:00:00Z
rank1,IP1,2015-02-14T03:45:23.145Z,2015-02-12 00:00:00Z
rank1,IP1,2015-02-14T03:45:23.465Z,2015-02-12 00:00:00Z
rank1,IP2,2015-02-14T03:45:23.345Z,2015-02-12 00:00:00Z
rank1,IP2,2015-02-14T03:45:23.125Z,2015-02-12 00:00:00Z
rank2,IP1,2015-02-14 03:44:11,2015-02-12 00:00:00Z
rank2,IP1,2015-02-14 03:45:23,2015-02-12 00:00:00Z
rank2,IP1,2015-02-14 03:45:23,2015-02-12 00:00:00Z
Based on unique key(col1,col2) combination,col3 needs to be sorted in ascending. Once col3 is in ascending, we need to increment col4 by every 1 second of that combination.
Below is my query.
select col1,col2,col3,CONCAT(from_unixtime(unix_timestamp(col4, "yyyy-MM-dd HH:mm:ss") + row_number() over
(partition by col1,col2 order by from_unixtime(unix_timestamp(col3, "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")) asc) ),'Z') As col4
from ipconf;
I am getting the output below which is incorrect
rank1,IP1,2015-02-14T03:45:23.465Z,2015-02-12 00:00:01Z
rank1,IP1,2015-02-14T03:45:23.345Z,2015-02-12 00:00:02Z
rank1,IP1,2015-02-14T03:45:23.145Z,2015-02-12 00:00:03Z
rank1,IP2,2015-02-14T03:45:23.125Z,2015-02-12 00:00:01Z
rank1,IP2,2015-02-14T03:45:23.345Z,2015-02-12 00:00:02Z
rank2,IP1,2015-02-14 03:44:11,2015-02-12 00:00:01Z
rank2,IP1,2015-02-14 03:45:23,2015-02-12 00:00:02Z
rank2,IP1,2015-02-14 03:45:23,2015-02-12 00:00:03Z
Expected output:
rank1,IP1,2015-02-14T03:45:23.145Z,2015-02-12 00:00:01Z
rank1,IP1,2015-02-14T03:45:23.345Z,2015-02-12 00:00:02Z
rank1,IP1,2015-02-14T03:45:23.465Z,2015-02-12 00:00:03Z
rank1,IP2,2015-02-14T03:45:23.125Z,2015-02-12 00:00:01Z
rank1,IP2,2015-02-14T03:45:23.345Z,2015-02-12 00:00:02Z
rank2,IP1,2015-02-14 03:44:11,2015-02-12 00:00:01Z
rank2,IP1,2015-02-14 03:45:23,2015-02-12 00:00:02Z
rank2,IP1,2015-02-14 03:45:23,2015-02-12 00:00:03Z
col3
. You will get null for one of the formats, I think. – philantrovert