From 751a95f9aeebf4f65b8678bc6510d8b23e3c8ea3 Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Fri, 4 Oct 2024 08:42:28 +0200 Subject: [PATCH] modified macro --- ...tamp_to_utc.sql => unix_ms_timestamp_to_utc.sql} | 13 ++----------- .../hubspot/stg_hubspot__form_submissions.sql | 10 ++++++++-- 2 files changed, 10 insertions(+), 13 deletions(-) rename macros/{timestamp_to_utc.sql => unix_ms_timestamp_to_utc.sql} (51%) diff --git a/macros/timestamp_to_utc.sql b/macros/unix_ms_timestamp_to_utc.sql similarity index 51% rename from macros/timestamp_to_utc.sql rename to macros/unix_ms_timestamp_to_utc.sql index 59cbefe..e342ecd 100644 --- a/macros/timestamp_to_utc.sql +++ b/macros/unix_ms_timestamp_to_utc.sql @@ -9,15 +9,6 @@ It generates two output fields: This macro is intended to be used within a SELECT statement and ensures that the output is properly formatted for further analysis. */ -{% macro timestamp_to_utc(column_name) %} - to_timestamp( - {{ adapter.quote(column_name) }}::double precision / 1000 - ) at time zone 'UTC' - as {{ column_name | replace("At", "") | replace("Date", "") }}_at_utc, - - cast( - to_timestamp( - {{ adapter.quote(column_name) }}::double precision / 1000 - ) at time zone 'UTC' as date - ) as {{ column_name | replace("At", "") | replace("Date", "") }}_date_utc +{% macro unix_ms_timestamp_to_utc(column_name) %} + to_timestamp({{ adapter.quote(column_name) }} / 1000) at time zone 'UTC' {% endmacro %} diff --git a/models/staging/hubspot/stg_hubspot__form_submissions.sql b/models/staging/hubspot/stg_hubspot__form_submissions.sql index 705a952..7ec9ed4 100644 --- a/models/staging/hubspot/stg_hubspot__form_submissions.sql +++ b/models/staging/hubspot/stg_hubspot__form_submissions.sql @@ -4,8 +4,14 @@ with select {{ adapter.quote("formId") }} as id_form, {{ adapter.quote("values") }} as "values", - {{ timestamp_to_utc("submittedAt") }}, - {{ timestamp_to_utc("updatedAt") }}, + {{ unix_ms_timestamp_to_utc("submittedAt") }} as submitted_at_utc, + cast( + {{ unix_ms_timestamp_to_utc("submittedAt") }} as date + ) as submitted_date_utc, + {{ unix_ms_timestamp_to_utc("updatedAt") }} as updated_at_utc, + cast( + {{ unix_ms_timestamp_to_utc("updatedAt") }} as date + ) as updated_date_utc, {{ adapter.quote("_airbyte_extracted_at") }} as dwh_extracted_at_utc from raw_form_submissions )