From 93868e8da2af7ce718ecb36821977f7193d24553 Mon Sep 17 00:00:00 2001 From: Yam ZhengLim Date: Wed, 2 Aug 2023 14:24:14 +0000 Subject: [PATCH] dates model --- ...g_googlesheet__event_and_holiday_lists.sql | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 models/staging/googlesheet/stg_googlesheet__event_and_holiday_lists.sql diff --git a/models/staging/googlesheet/stg_googlesheet__event_and_holiday_lists.sql b/models/staging/googlesheet/stg_googlesheet__event_and_holiday_lists.sql new file mode 100644 index 0000000..61fbfb3 --- /dev/null +++ b/models/staging/googlesheet/stg_googlesheet__event_and_holiday_lists.sql @@ -0,0 +1,78 @@ +-- IMPORT +WITH holiday_lists AS ( + SELECT * FROM {{ source('src_googlesheet_airbyte', '_airbyte_raw_event_and_holiday_lists') }} +), + +-- LOGIC +parse_jason_holidays AS ( + + SELECT + _airbyte_ab_id AS airbyte_id, + parse_json(_airbyte_data) AS holiday_json, + _airbyte_emitted_at AS _airbyte_emitted_datetime + + FROM holiday_lists +), + +flatten_json AS ( + + SELECT + airbyte_id, + holiday_json['id']::INTEGER AS holiday_id, + holiday_json['date']::DATE AS date, + holiday_json['day']::STRING AS day, + holiday_json['event_name']::STRING AS event_name, + holiday_json['event_desc']::STRING AS event_description, + holiday_json['general_type']::STRING AS holiday_general_type, + holiday_json['holiday_type']::STRING AS holiday_specific_type, + holiday_json['country']::STRING AS country, + holiday_json['state']::STRING AS state, + holiday_json['event_cultural_origin']::STRING AS religion, + holiday_json['is_malaysia_holiday']::INTEGER AS is_malaysia_holiday, + holiday_json['is_company_holiday']::INTEGER AS is_company_holiday, + holiday_json['is_china_holiday']::INTEGER AS is_china_holiday, + holiday_json['is_china_warehouse_holiday']::INTEGER AS is_china_warehouse_holiday, + holiday_json['special_remark']::STRING AS remark, + + _airbyte_emitted_datetime, + '{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime + + FROM parse_jason_holidays +), + +-- FINAL +final__stg_googlesheet__event_and_holiday_lists AS ( + + SELECT + -- ids + holiday_id, + airbyte_id, + + -- dimensions + day, + event_name, + event_description, + holiday_general_type, + holiday_specific_type, + country, + state, + religion, + is_malaysia_holiday, + is_company_holiday, + is_china_holiday, + is_china_warehouse_holiday, + + -- measures + + -- date/times + date, + + -- metadata + remark, + _airbyte_emitted_datetime, + _dbt_ran_datetime + + FROM flatten_json +) + +SELECT * FROM final__stg_googlesheet__event_and_holiday_lists