forked from mattermost/mattermost-data-warehouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: lint utils module, part 2 (mattermost#1129)
- Loading branch information
1 parent
422552c
commit b11862a
Showing
3 changed files
with
29 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,37 @@ | ||
import os | ||
import pandas as pd | ||
import sys | ||
from extract.utils import snowflake_engine_factory, execute_query, execute_dataframe | ||
|
||
from extract.utils import execute_query, snowflake_engine_factory | ||
|
||
|
||
def update_chronological_sequence(): | ||
engine = snowflake_engine_factory(os.environ, "TRANSFORMER", "util") | ||
|
||
query = f''' | ||
query = ''' | ||
UPDATE ANALYTICS.EVENTS.USER_EVENTS_BY_DATE | ||
SET chronological_sequence = a.chronological_sequence, | ||
seconds_after_prev_event = a.seconds_after_prev_event | ||
FROM ( | ||
SELECT id, | ||
updated_at, | ||
ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY min_timestamp) as chronological_sequence, | ||
datediff(second, lag(min_timestamp) over (partition by user_id order by min_timestamp), min_timestamp) as seconds_after_prev_event | ||
datediff( | ||
second, | ||
lag(min_timestamp) over (partition by user_id order by min_timestamp), | ||
min_timestamp | ||
) as seconds_after_prev_event | ||
FROM ANALYTICS.EVENTS.USER_EVENTS_BY_DATE | ||
WHERE length(user_id) < 36 | ||
AND user_id IS NOT NULL | ||
) a | ||
WHERE user_events_by_date.updated_at::timestamp = (SELECT MAX(UPDATED_AT)::timestamp FROM analytics.events.user_events_by_date) | ||
WHERE | ||
user_events_by_date.updated_at::timestamp = ( | ||
SELECT MAX(UPDATED_AT)::timestamp FROM analytics.events.user_events_by_date | ||
) | ||
AND a.id = user_events_by_date.id; | ||
''' | ||
|
||
execute_query(engine, query) | ||
|
||
|
||
if __name__ == "__main__": | ||
update_chronological_sequence() | ||
update_chronological_sequence() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters