Skip to content

Commit d432520

Browse files
authored
Merge pull request #492 from brooklyn-data/bug/missing-datetime-object-fix
Bug: Handle event time flags for microbatch
2 parents 51d08d1 + 1924bb9 commit d432520

File tree

10 files changed

+55
-9
lines changed

10 files changed

+55
-9
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ env.sh
1414
.python-version
1515
.vscode
1616
.venv
17+
.env
18+
.secrets
19+
*.lock
20+
**/*/package-lock.yml
1721
pyproject.toml
1822

1923
.DS_Store

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ See the generated [dbt docs site](https://brooklyn-data.github.io/dbt_artifacts/
4747
```
4848
packages:
4949
- package: brooklyn-data/dbt_artifacts
50-
version: 2.9.1
50+
version: 2.9.2
5151
```
5252

5353
:construction_worker: Make sure to fix at least the **minor** version, to avoid issues when a new release is open. See the notes on upgrading below for more detail.

dbt_project.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: "dbt_artifacts"
2-
version: "2.9.1"
2+
version: "2.9.2"
33
config-version: 2
44
require-dbt-version: [">=1.3.0", "<1.10.0"]
55
profile: "dbt_artifacts"

integration_test_project/models/microbatch.sql

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
{{
22
config(
3-
materialized = 'incremental',
4-
incremental_strategy = 'microbatch',
5-
unique_key = 'transaction_id',
6-
event_time = 'transaction_ts',
7-
begin = (modules.datetime.datetime.now().replace(hour=6, minute=0, second=0) - modules.datetime.timedelta(2)).isoformat(),
8-
batch_size = 'day'
3+
materialized = 'incremental',
4+
incremental_strategy = 'microbatch',
5+
event_time = 'transaction_ts',
6+
begin = (modules.datetime.datetime.now().replace(hour=6, minute=0, second=0) - modules.datetime.timedelta(2)).isoformat(),
7+
batch_size = 'day',
8+
9+
unique_key = 'transaction_id',
10+
partition_by = {
11+
'field': 'store_name',
12+
'data_type': 'text',
13+
}
914
)
1015
}}
1116

integration_test_project/models/sources.yml

+9
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ sources:
1111
tables:
1212
- name: doesnt_exist
1313
- name: '"GROUP"'
14+
15+
- name: freshness_check
16+
database: "{% if target.type not in ('spark', 'databricks') %}{{ var('dbt_artifacts_database', target.database) }}{% endif %}"
17+
schema: "{{ target.schema }}"
18+
freshness:
19+
error_after: {count: 1, period: hour}
20+
loaded_at_field: load_timestamp
21+
tables:
22+
- name: freshness
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
id,load_timestamp
2+
101,2025-04-09 12:00:00
3+
102,2025-04-09 12:05:00
4+
103,2025-04-09 12:10:00
5+
104,2025-04-09 12:15:00
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
3+
seeds:
4+
- name: freshness
5+
config:
6+
column_types:
7+
id: integer
8+
load_timestamp: timestamp

macros/upload_individual_datasets/upload_invocations.sql

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@
1717
{% endif %}
1818
{% endif %}
1919

20+
{% if "event_time_start" in invocation_args_dict and invocation_args_dict.strftime is not none %}
21+
{% do invocation_args_dict.update(
22+
{"event_time_start": invocation_args_dict.event_time_start.strftime(dbt_artifacts.get_strftime_format())}
23+
) %}
24+
{% endif %}
25+
{% if "event_time_end" in invocation_args_dict and invocation_args_dict.strftime is not none %}
26+
{% do invocation_args_dict.update(
27+
{"event_time_end": invocation_args_dict.event_time_end.strftime(dbt_artifacts.get_strftime_format())}
28+
) %}
29+
{% endif %}
30+
31+
{{ log(invocation_args_dict) }}
2032
{{ return(adapter.dispatch("get_invocations_dml_sql", "dbt_artifacts")()) }}
2133
{%- endmacro %}
2234

macros/utils/copy_model.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{% set model_copy = model.copy() %}
33
{% do model_copy.pop('raw_code', None) %}
44
{% if model_copy.config.begin %}
5-
{% set _ = model_copy.config.update({"begin": model_copy.config.begin.strftime("%Y-%m-%dT%H:%M:%S.%f")}) %}
5+
{% set _ = model_copy.config.update({"begin": model_copy.config.begin.strftime(dbt_artifacts.get_strftime_format())}) %}
66
{% endif %}
77

88
{{ return(model_copy) }}

macros/utils/get_strftime_fmt.sql

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{% macro get_strftime_format() %}
2+
{{ return("%Y-%m-%dT%H:%M:%S.%f") }}
3+
{% endmacro %}

0 commit comments

Comments
 (0)