Skip to content

Conversation

mariusandra
Copy link
Collaborator

@mariusandra mariusandra commented Apr 18, 2023

Problem

No support for window functions.

Changes

Adds support for window functions.

What are window functions?

The following syntax is now enabled:

   select distinct_id,
          timestamp,
          event,
          groupArray(event) OVER (PARTITION BY distinct_id ORDER BY timestamp ASC ROWS BETWEEN 2 PRECEDING AND 1 PRECEDING) AS two_before,
          groupArray(event) OVER (PARTITION BY distinct_id ORDER BY timestamp ASC ROWS BETWEEN 1 FOLLOWING AND 2 FOLLOWING) AS two_after
     from events
    where timestamp > toDateTime('2020-01-09 00:00:00')
      and person.properties.random_uuid = '{random_uuid}'
 order by distinct_id, timestamp

also this:

 select distinct_id,
        timestamp,
        event,
        groupArray(event) OVER w1 AS two_before,
        groupArray(event) OVER w2 AS two_after
   from events
  where timestamp > toDateTime('2020-01-09 00:00:00')
    and distinct_id like '%_{random_uuid}'
 window w1 as (PARTITION BY distinct_id ORDER BY timestamp ASC ROWS BETWEEN 2 PRECEDING AND 1 PRECEDING),
        w2 as (PARTITION BY distinct_id ORDER BY timestamp ASC ROWS BETWEEN 1 FOLLOWING AND 2 FOLLOWING)
order by distinct_id, timestamp

How did you test this code?

Added the relevant tests.

@mariusandra mariusandra marked this pull request as ready for review May 31, 2023 08:37
@mariusandra
Copy link
Collaborator Author

Finally ready for a review.

@mariusandra mariusandra merged commit e23d4f5 into master May 31, 2023
@mariusandra mariusandra deleted the hogql-window-functions branch May 31, 2023 10:53
@abegehr
Copy link

abegehr commented Oct 12, 2024

This doesn't add support for windows with date ranges, like RANGE BETWEEN INTERVAL 6 DAY PRECEDING AND CURRENT ROW, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants