From e236276efa4d346ea9efd60d9bdfb728a352fa36 Mon Sep 17 00:00:00 2001 From: Celine Verhoef Date: Tue, 29 Mar 2022 13:58:43 +0200 Subject: [PATCH] feat: add ms to time format and put back variables per macro --- README.md | 18 +++++++++++++++++- macros/multiple_databases/to_time.sql | 4 ++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 609f7c5..e83c570 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ vars: # Date and time formats. # For SQL Server defined by integers and for Snowflake defined by strings. date_format: 23 # default: SQL Server: 23, Snowflake: 'YYYY-MM-DD' - time_format: 8 # default: SQL Server: 8, Snowflake: 'hh24:mi:ss' + time_format: 14 # default: SQL Server: 14, Snowflake: 'hh24:mi:ss.ff3' datetime_format: 21 # default: SQL Server: 21, Snowflake: 'YYYY-MM-DD hh24:mi:ss.ff3' ``` @@ -101,6 +101,9 @@ This macro converts an attribute to a date attribute. Usage: `{{ pm_utils.to_date('[expression]') }}` +Variables: +- date_format + #### to_double ([source](macros/multiple_databases/to_double.sql)) This macro converts an attribute to a double attribute. @@ -119,12 +122,18 @@ This macro converts an attribute to a time attribute. Usage: `{{ pm_utils.to_time('[expression]') }}` +Variables: +- time_format + #### to_timestamp ([source](macros/multiple_databases/to_timestamp.sql)) This macro converts an attribute to a timestamp attribute. Usage: `{{ pm_utils.to_timestamp('[expression]') }}` +Variables: +- datetime_format + #### to_varchar ([source](macros/multiple_databases/to_varchar.sql)) This macro converts an attribute to a string attribute. @@ -309,6 +318,13 @@ To keep the SQL in the model more readable, you can define a Jinja variable for `{% set source_table = source(source_name, table_name) %}` +Variables: +- date_format +- time_format +- datetime_format + +These variables are only required when the `data_type` is used with the values `date`, `time`, or `datetime`. + ### Process mining tables #### generate_edge_table ([source](macros/process_mining_tables/generate_edge_table.sql)) diff --git a/macros/multiple_databases/to_time.sql b/macros/multiple_databases/to_time.sql index b33a4e9..0a55653 100644 --- a/macros/multiple_databases/to_time.sql +++ b/macros/multiple_databases/to_time.sql @@ -1,9 +1,9 @@ {%- macro to_time(attribute) -%} {%- if target.type == 'snowflake' -%} - try_to_time(to_varchar({{ attribute }}), '{{ var("time_format", "hh24:mi:ss") }}') + try_to_time(to_varchar({{ attribute }}), '{{ var("time_format", "hh24:mi:ss.ff3") }}') {%- elif target.type == 'sqlserver' -%} - try_convert(time, {{ attribute }}, {{ var("time_format", 8) }}) + try_convert(time, {{ attribute }}, {{ var("time_format", 14) }}) {%- endif -%} {%- endmacro -%}