Home > Software engineering >  How to reference table name in DBT Model (GitHub)
How to reference table name in DBT Model (GitHub)

Time:11-08

How do I reference the table name (highlighted cursor) from a csv file in DBT Model (GitHub)?

My current yml file only has "models: ...".

enter image description here

The csv file to be referenced is named orders.csv, uploaded under tables -> datawarehouse folder.

CodePudding user response:

I think you're referring to a seed, which is a feature where dbt can create a table in your warehouse using a .csv file that is stored alongside the code in your project.

After you add the .csv file to your seeds directory inside your project (or some other directory nested under /seeds/), you run dbt seed in your terminal to create the table from the data in the CSV. From your example, let's say the CSV is called orders.csv and is located at /seeds/tables/datawarehouse/orders.csv.

After that, you can select from the seed in other models by using ref with the seed's filename, so {{ ref('orders') }}.

If you are using another tool (not dbt seed) to upload the CSV, you need to find the location of the table in your data warehouse, and then add that location as a source, and you will specify the database/schema/table name in the sources.yml file. If you have the table defined as a source, you select from it with {{ source('my_source', 'my_table') }}.

  • Related