如何在dbt的sources.yml中定义含特殊字符的BigQuery源表?
Got it, let's break this down for you. The issue here is that you're trying to cram the full BigQuery table path (project.dataset.table) into the name field of your source tables—this doesn't play nicely with YAML syntax or dbt's expected source structure. Here's how to fix it properly:
Correct Source Configuration Structure
dbt lets you split your BigQuery table path into three distinct, manageable fields in sources.yml, which handles special characters without breaking YAML rules:
database: Maps to your BigQuery project ID (the part before the first dot)schema: Maps to your BigQuery dataset name (the middle part)name(undertables): Maps to your individual table name (the last part)
If any of these components have special characters (like your fa--task project ID), wrap them in backticks directly in the relevant field.
Updated sources.yml Example
version: 2 sources: - name: bigquery_source # Custom name for your source (pick anything you like) database: `fa--task` # BigQuery project ID with special characters, wrapped in backticks schema: dataset # Your dataset name (add backticks here too if it has special chars) tables: - name: addresses - name: devices - name: orders - name: payments
How to Reference the Source in Your Models
You don't need to include backticks in your source() macro call—dbt will automatically handle quoting the special characters when it compiles the SQL:
SELECT * FROM {{ source('bigquery_source', 'addresses') }}
When compiled, this will output the valid BigQuery syntax: SELECT * FROM fa--task.dataset.addresses``
Edge Case: If Your Table Name Has Special Characters
If your table itself had special characters (e.g., user--data), just wrap the table name in backticks in the name field:
tables: - name: `user--data`
dbt will still compile the correct quoted reference for you.
内容的提问来源于stack exchange,提问作者sgdata

