Need to rotate a matrix to do TIMESERIES interpolation / gap filling, and would like to avoid the messy & inefficient UNION ALL approach. Is there anything like Hive's LATERAL VIEW EXPLODE functionality available in Vertica?
EDIT: @marcothesane -- thanks for your interesting scenario -- I like your approach for interpolation. I will play around with it more and see how it goes. Looks promising.
FYI -- here is the solution that I came up with -- My scenario is that I am trying to view memory usage over time by query (and user / resource pool, etc. basically trying to get a cost metric). I need to do interpolation so that I can see the total usage at any point in time. So here is my query which does timeseries slicing by second, then aggregates to give a metric of "Megabyte_Seconds" by minute.
with qry_cte as
(
select
session_id
, request_id
, date_trunc('second',start_timestamp) as dat_str
, timestampadd('ss'
, ceiling(request_duration_ms/1000)::int
, date_trunc('second',start_timestamp)
) as dat_end
, ceiling(request_duration_ms/1000)::int as secs
, memory_acquired_mb
from query_requests
where request_type = 'QUERY'
and request_duration_ms > 0
and memory_acquired_mb > 0
)
select date_trunc('minute',slice_time) as dat_minute
, count(distinct session_id || request_id::varchar) as queries
, sum(memory_acquired_mb) as mb_seconds
from (
select session_id, request_id, slice_time, ts_first_value(memory_acquired_mb) as memory_acquired_mb
from (
select session_id, request_id, dat_str as dat, memory_acquired_mb from qry_cte
union all
select session_id, request_id, dat_end as dat, memory_acquired_mb from qry_cte
) x
timeseries slice_time as '1 second' over (partition by session_id, request_id order by dat)
) x
group by 1 order by 1 desc
;