Skip to content

Commit e5f2365

Browse files
committed
Pass timestamp_column and fixed escape select
1 parent 5584d33 commit e5f2365

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

macros/commands/dump_table.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
{% set order_by_dedup_column = "generated_at" %}
2222
{% set query %}
2323
{% if dedup and (dedup_by_column in column_names) and (order_by_dedup_column in column_names) %}
24-
{{ elementary.dedup_by_column_query(dedup_by_column, order_by_dedup_column, column_names, relation) }}
24+
{{ elementary.dedup_by_column_query(dedup_by_column, order_by_dedup_column, column_names, relation, timestamp_column=timestamp_column) }}
2525
{% else %}
2626
select {{ elementary.select_columns(column_names, timestamp_column) }}
2727
from {{ relation }}
@@ -50,7 +50,7 @@
5050
{% endmacro %}
5151

5252

53-
{% macro dedup_by_column_query(dedup_by_column, order_by_dedup_column, column_names, relation) %}
53+
{% macro dedup_by_column_query(dedup_by_column, order_by_dedup_column, column_names, relation, timestamp_column=none) %}
5454
with indexed_relation as (
5555
select
5656
{{ elementary.escape_select(column_names) }},

macros/utils/sql_utils/format_timestamp_column.sql

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{% macro select_columns(column_names, timestamp_column=none) %}
2-
{%- set columns_to_select = [] -%}
2+
{%- set processed_columns = [] -%}
33
{%- set timestamp_column_lower = timestamp_column | lower if timestamp_column else none -%}
44

55
{%- for column_name in column_names -%}
66
{%- if timestamp_column and column_name | lower == timestamp_column_lower -%}
7-
{%- do columns_to_select.append(elementary.format_timestamp_column(column_name)) -%}
7+
{%- do processed_columns.append(elementary.select_timestamp_column(column_name)) -%}
88
{%- else -%}
9-
{%- do columns_to_select.append(column_name) -%}
9+
{%- do processed_columns.append(elementary.escape_select([column_name])) -%}
1010
{%- endif -%}
1111
{%- endfor -%}
1212

13-
{{ elementary.escape_select(columns_to_select) }}
13+
{{ processed_columns | join(", ") }}
1414
{% endmacro %}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% macro select_timestamp_column(column_name) %}
2+
{{ return(adapter.dispatch('select_timestamp_column', 'elementary')(column_name)) }}
3+
{% endmacro %}
4+
5+
{% macro default__select_timestamp_column(column_name) %}
6+
{{ return(elementary.escape_select([column_name])) }}
7+
{% endmacro %}
8+
9+
{% macro dremio__select_timestamp_column(column_name) %}
10+
{#
11+
Dremio truncates milliseconds when selecting timestamps.
12+
Using TO_CHAR with FFF format preserves them.
13+
#}
14+
{% set escaped_name = elementary.escape_select([column_name]) %}
15+
{{ return('TO_CHAR(' ~ escaped_name ~ ', \'YYYY-MM-DD"T"HH24:MI:SS.FFF\') as ' ~ escaped_name) }}
16+
{% endmacro %}

0 commit comments

Comments
 (0)