I'm attempting to do the following query where I use a windowing to fetch the next log timestamp and then do a subtraction between it and the current timestamp.
SELECT
LEAD(timestamp) OVER (PARTITION BY id ORDER BY timestamp) AS lead_timestamp,
timestamp,
(lead_timestamp - timestamp) as delta
FROM logs;
However, when I do this, I get the following error:
FAILED: SemanticException [Error 10004]: Line 4:1 Invalid table alias or column reference 'lead_timestamp': (possible column names are: logs.timestamp, logs.latitude, logs.longitude, logs.principal_id)
If I drop this subtraction, the rest of the query works, so I'm stumped - am I using the AS syntax wrong above for lead_timestamp?