Skip to content

Commit

Permalink
feat: add ms to time format and put back variables per macro
Browse files Browse the repository at this point in the history
  • Loading branch information
cverhoef committed Mar 29, 2022
1 parent 5a129c6 commit e236276
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
```

Expand Down Expand Up @@ -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.

Expand All @@ -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.

Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions macros/multiple_databases/to_time.sql
Original file line number Diff line number Diff line change
@@ -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 -%}

0 comments on commit e236276

Please sign in to comment.