Kevin Lee
Kevin Lee

Reputation: 469

How to change the timezone of dbt

I have installed dbt on my on-premise server and running, my data connection is bigquery.

$ cat ~/.dbt/profiles.yml
www:
  outputs:
    dev:
      dataset: dw
      job_execution_timeout_seconds: 300
      job_retries: 1
      keyfile: /mykey.json
      location: asia-east2
      method: service-account
      priority: interactive
      project: myprojectid
      threads: 4
      type: bigquery
  target: dev

However, dbt is showing event timestamp with timezone UTC, which does not align with my os timezone.

$ dbt run
04:18:08  Running with dbt=1.3.2
04:18:09  Unable to do partial parsing because a project config has changed
04:18:10  [WARNING]: Configuration paths exist in your dbt_project.yml file which do not apply to any resources.
There are 1 unused configuration paths:
- models.www.example

04:18:10  Found 1 model, 0 tests, 0 snapshots, 0 analyses, 319 macros, 0 operations, 0 seed files, 0 sources, 0 exposures, 0 metrics
04:18:10  
04:18:11  Concurrency: 4 threads (target='dev')
04:18:11  
04:18:11  1 of 1 START sql table model dw.dim_wine_color ................................. [RUN]
04:18:15  1 of 1 OK created sql table model dw.dim_wine_color ............................ [CREATE TABLE (195.1k rows, 6.5 MB processed) in 4.08s]
04:18:15  
04:18:15  Finished running 1 table model in 0 hours 0 minutes and 5.14 seconds (5.14s).
04:18:15  
04:18:15  Completed successfully
04:18:15  
04:18:15  Done. PASS=1 WARN=0 ERROR=0 SKIP=0 TOTAL=1

On my linux server, it should be in UTC+8 timezone.

$ date
Thu 12 Jan 2023 12:18:20 PM HKT

Are there any configuration I can change to modify dbt's timezone to align with my os?

Upvotes: 1

Views: 4662

Answers (1)

Aleix CC
Aleix CC

Reputation: 2099

Just as a reminder: it is not dbt that shows the timestamp in UTC, but BigQuery. I am not sure on whether BigQuery has any config that you can set up to always show a specific timezone in your timestamps (supposing that these are always set in UTC). What I do know, though, is that you can use the calogica/dbt-date package (link here) to automatically transform a timestamp to a specific timezone.

You'll need to:

  • Add the calogica/dbt-date package in your packages.yml and then run dbt deps
  • Add a variable in your dbt_project.yml as follows:
# dbt_project.yml
vars:
  'dbt_date:time_zone': 'Asia/Hong_Kong'
  • At this point, you could now use the following package macro to convert your desired fields into the timezone stated above by using:

{{ dbt_date.convert_timezone("my_column", source_tz="UTC") }}

Upvotes: 1

Related Questions