Velir / dbt-ga4

dbt Package for modeling raw data exported by Google Analytics 4. BigQuery support, only.
MIT License
289 stars 128 forks source link

Multi-project support on BigQuery error #308

Open adaskaval opened 3 months ago

adaskaval commented 3 months ago

Package version:

packages:
  - package: Velir/ga4
    version: 6.0.1

My setup:

vars:
  source_project: "prod"
  combined_dataset: "raw_ga4"
  property_ids: [116917736,113827568,16934417]
  start_date: "20230101" # Earliest date to load
  static_incremental_days: 2 # Number of days to scan and reprocess on each run

Error:

10:22:57  Finished running 4 incremental models, 18 view models, 2 table models in 0 hours 0 minutes and 10.50 seconds (10.50s).
10:22:57  
10:22:57  Completed with 1 error and 0 warnings:
10:22:57  
10:22:57    Field "type" of type Optional[RelationType] in BigQueryRelation has invalid value 'clone'
10:22:57  
10:22:57  Done. PASS=0 WARN=0 ERROR=1 SKIP=23 TOTAL=24
dgitis commented 3 months ago

I don't recognize that as a package error.

What version of the dbt BigQuery adapter are you using?

Is this a new project? Or are you upgrading to the latest version of dbt-GA4?

adaskaval commented 3 months ago

Hello @dgitis,

This is not a new dbt project, we've been using this package for a while, but only with 1 google analytics property. We made updates by adding 2 new properties and set "combined_dataset" parameter.

We are using 1.7.0 dbt adapter version:

(.venv) adask@Adass-MBP models % dbt run --models tag:ga4,tag:staging --target prod
08:38:41  Running with dbt=1.7.0
08:38:42  Registered adapter: bigquery=1.7.0

Once we add "combined_dataset", this error appears. As per my understanding this parameter enables macro, which combines all properties into one before executing models, but it fails.

Thank you for your insights.

adamribaudo-velir commented 2 months ago

@adaskaval yes, when combining properties, this macro is run: https://github.com/Velir/dbt-ga4/blob/main/macros/combine_property_data.sql

Can you try to manually execute some of the commands in that macro? I have a feeling this is either related to your dbt execution environment or GCP settings. I've never seen that error.

For example, can you try to run a command like this (filling in your own sample source/target table):

CREATE OR REPLACE TABLE `{{target.project}}.{{var('combined_dataset')}}.events_{{relation_suffix}}{{property_id}}` CLONE `{{var('source_project')}}.analytics_{{property_id}}.events_{{relation_suffix}}`;