Clean wrong data

This commit is contained in:
CIEF ACC1
2023-09-24 11:47:14 +00:00
parent 772de3711a
commit 362cec7fa0
@@ -34,8 +34,7 @@ companies_map_constant AS (
companies.deleted_datetime,
companies.created_datetime,
companies.updated_datetime,
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
companies.updated_datetime
FROM companies
@@ -49,6 +48,40 @@ companies_map_constant AS (
ON (companies.status = status.id)
),
/*
Data cleaning for the 4 company_id (1405, 2030, 3095, 4275) which has a company registration date later than the first order_created_datetime.
Median number of days to placing first order (4 days) is used to revert the company created datetime.
*/
data_clean AS (
SELECT
company_id,
company_marking_id,
autocount_id,
name,
company_type,
business_type,
status,
deleted_datetime,
updated_datetime,
CASE
-- 2030 has an order placed 5 months before the registration date, so using the first order_datetime as base
WHEN company_id = 2030 THEN DATEADD(day, -4, TO_TIMESTAMP_TZ('2021-06-28T14:04:30+08:00'))
WHEN company_id = 1405 THEN DATEADD(day, -4, created_datetime)
WHEN company_id = 3095 THEN DATEADD(day, -4, created_datetime)
WHEN company_id = 4275 THEN DATEADD(day, -4, created_datetime)
ELSE created_datetime
END AS created_datetime,
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
FROM companies_map_constant
),
-- FINAL
final__stg_companies__exchange AS (
@@ -74,7 +107,7 @@ final__stg_companies__exchange AS (
-- metadata
_dbt_ran_datetime
FROM companies_map_constant
FROM data_clean
)