func.first_value

FIRST_VALUE is a function that returns the first value in an ordered set of values

FIRST_VALUE is a function that returns the first value in an ordered set of values

Syntax

func.first_value(field).over(partition_by=field, order_by=field)

Examples

This is an example of using the first_value() capability to calculate the running time of the time series data where each event is on a distinct row.

This assumes you have a table of time series data that looks like this:

locationemployeetimestamp
Building AJohn Doe2022-01-05 15:34:31
Building AJohn Doe2022-01-05 15:44:31
Building AJohn Doe2022-01-05 15:46:41
table.timestamp - func.first_value(table.timestamp, 1).over(partition_by=[table.location, table.employee], order_by=table.timestamp)

Adding the expression above to an Interval column called run_time would result in an output table like this:

locationemployeetimestamprun_time
Building AJohn Doe2022-01-05 15:34:3100:00:00
Building AJohn Doe2022-01-05 15:44:3100:10:00
Building AJohn Doe2022-01-05 15:46:4100:12:10
Last modified November 27, 2023 at 12:56 PM EST: Restructured the file structure/a few changes (f6c58b8)