Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DBT SNOWFLAKE : reference internal stage as source

Is it possible to reference internal Snowflake stage in DBT source yml ?
I know this is possible with external stage using the module : https://github.com/dbt-labs/dbt-external-tables
But this does not work for internal stages.
This functionnality would enable to parse csv from stage directly in dbt, and access the metadata that come with snowflake stage.
Thanks for your help !

like image 337
tacou_st Avatar asked May 22 '26 20:05

tacou_st


2 Answers

I have done that by leaving the @ outside the jinja code. Like this:

SELECT
  $1 AS column1,
  $2 AS column2
FROM @{{source('MY_SOURCE','MY_TABLE')}} (file_format => MY_DB.MY_SCHEMA.MY_FILE_FORMAT)

In the schema.yml put the information as usual:

version: 2

sources:
    - name: MY_SOURCE
      database: MY_DB
      schema: MY_SCHEMA
      tables: 
        - name: MY_TABLE
like image 121
Lewuap Avatar answered May 25 '26 14:05

Lewuap


This can be done, but I don't recommend it (will break docs). You can reference your stage like this:

version: 2

sources:
  - name: bi
    database: '@raw'
    schema: datalake
    description: activation flat file data from s3
    tables:
      - name: power_bi_usage
        identifier: 'DATALAKE_STAGE_FULL_DATALAKE/powerbi/activity-events/'
        description: power bi usage information

It would act the same as if you queried the stage directly as such:

SELECT * FROM @RAW.DATALAKE.DATALAKE_STAGE_FULL_DATALAKE/powerbi/activity-events/

like image 22
jymbo Avatar answered May 25 '26 15:05

jymbo