arnoN7 / dbt-incremental-stream

DBT Package reproducing dbt incremental materialization leveraging on Snowflake streams
MIT License
23 stars 4 forks source link

bug when schema name is substring of database name #7

Closed MarthaScheffler closed 1 week ago

MarthaScheffler commented 2 months ago

Thanks for sharing this package! I get an error, when

It seems that the database identifier doesn't get compiled correctly.

models/raw/sources.yml

version: 2

sources:
  - name: raw
    database: QARMA_DEMO  
    schema: QARMA  
    tables:
      - name: inspections_defects

models/raw/inspections_defects.sql

{{ config(materialized='incremental_stream') }}

SELECT *
FROM {{ incr_stream.stream_source('raw','inspections_defects') }}

target/compiled/my_project/models/raw/inspections.sql

SELECT *
FROM MARTHA_DEV_raw_DEMO.MARTHA_DEV_raw.S_inspections_defects_temp_inspections_defects

MARTHA_DEV is my target schema for development, "raw" is the custom schema I defined for all models in the raw folder. So the compiled schema makes sense, but the database is off and should instead be QARMA_DEMO - but apparently the QARMA in there got replaced by the schema name.

I think it comes from the schema replace in here, and similar should happen when the table/schema/database somehow are substrings from each other: https://github.com/arnoN7/dbt-incremental-stream/blob/master/macros/stream_source.sql#L40 but I have no good idea how to solve this.

arnoN7 commented 2 months ago

Hi Martha, Thanks for your good analysis. I'm currently on holiday (without laptop :)) but I think I know what should be changed. The issue is coming from line 40 in stream_source.sql. The replace function is replacing the DB name and schema name. But to do it properly it should replace . And .. As I don’t include the dots it replaces the schema name from the table name I think… 🙈 Big thanks for spotting this bug.

I will try the fix when I will have access to a laptop 😀

MarthaScheffler commented 2 weeks ago

your commit is fixing this issue for me - I have tested it on my project. you can close the issue. thanks!

(will comment on the other issue as well - that's a different one)

arnoN7 commented 1 week ago

Thanks I close the issue