dbt-labs / dbt-project-evaluator

This package contains macros and models to find DAG issues automatically
https://dbt-labs.github.io/dbt-project-evaluator/latest/
Apache License 2.0
440 stars 64 forks source link

sql syntax is unconventional and fails when I install the package and run it. #405

Closed dbrtly closed 8 months ago

dbrtly commented 10 months ago

Describe the bug

The query is weird. When I add this package to my dbt project and run it, this model fails. Suggest refactoring to conventionalize the query by moving the placeholders to the cte and selecting * from the cte. On my testing, this change makes the error go away.

/* Bigquery won't let us `where` without `from` so we use this workaround */
with dummy_cte as (
    select 1 as foo
)

select 

    cast(null as {{ dbt.type_string() }} ) as unique_id,
    cast(null as {{ dbt.type_string() }} ) as name,
    cast(null as {{ dbt.type_string() }} ) as resource_type,
    cast(null as {{ dbt.type_string() }} ) as file_path,
    cast(True as boolean) as is_described,
    cast(null as {{ dbt.type_string() }} ) as exposure_type,
    cast(null as {{ dbt.type_string() }} ) as maturity,
    cast(null as {{ dbt.type_string() }} ) as package_name,
    cast(null as {{ dbt.type_string() }} ) as url,
    cast(null as {{ dbt.type_string() }} ) as owner_name,
    cast(null as {{ dbt.type_string() }} ) as owner_email,
    cast(null as {{ dbt.type_string() }} ) as meta

from dummy_cte
where false 

Steps to reproduce

run the package on bigquery

Expected results

pass all

Actual results

4 of 71 OK created sql table model main.stg_exposures ........................ [FAIL in 0.04s]

Screenshots and log output

System information

unchanged from main

Which database are you using dbt with?

The output of dbt --version:

➜  dbt-project-evaluator git:(refactor-simplify-cte) ✗ dbt --version                        
Core:
  - installed: 1.7.4
  - latest:    1.7.4 - Up to date!

Plugins:
  - bigquery: 1.7.2 - Up to date!
  - duckdb:   1.7.0 - Up to date!

Additional context

proposed change to models/staging/graph/stg_exposures.sql

with
cte as (
    select
        cast(null as {{ dbt.type_string() }} ) as unique_id,
        cast(null as {{ dbt.type_string() }} ) as name,
        cast(null as {{ dbt.type_string() }} ) as resource_type,
        cast(null as {{ dbt.type_string() }} ) as file_path,
        cast(True as boolean) as is_described,
        cast(null as {{ dbt.type_string() }} ) as exposure_type,
        cast(null as {{ dbt.type_string() }} ) as maturity,
        cast(null as {{ dbt.type_string() }} ) as package_name,
        cast(null as {{ dbt.type_string() }} ) as url,
        cast(null as {{ dbt.type_string() }} ) as owner_name,
        cast(null as {{ dbt.type_string() }} ) as owner_email,
        cast(null as {{ dbt.type_string() }} ) as meta
)

select *
from cte
where false

Are you interested in contributing the fix?

yes. https://github.com/dbrtly/dbt-project-evaluator/tree/refactor-simplify-cte

dbrtly commented 10 months ago

Also I tried overriding the model (and insert_resources_from_graph) in my project but now I get a ZeroDivisionError in file "