duckdb / dbt-duckdb

dbt (http://getdbt.com) adapter for DuckDB (http://duckdb.org)
Apache License 2.0
935 stars 89 forks source link

Incorrect Case Sensitivity Handling of Identifier Names in Table Creation #374

Closed the-ALAM closed 7 months ago

the-ALAM commented 8 months ago

description

reproduction Steps

  1. set up DBT with DuckDB.
  2. define a model named Zipcode - or any other name with the first letter capitalized - and set the materialization to table.
  3. execute the DBT run/build command - also with --full-refresh -.

expected Behavior

detailed Behavior

actual Behavior

discovery Process

environment

additional Information

jwills commented 8 months ago

ah yes that sounds like a real bug, will look into it-- thank you!

jwills commented 8 months ago

huh when I ran this locally with my jaffle shop project I got a dbt (not a DuckDB) compilation error when I tried to name a model "Orders.sql":


05:11:57  Completed with 1 error and 0 warnings:
05:11:57
05:11:57    Compilation Error in model Orders (models/Orders.sql)
  When searching for a relation, dbt found an approximate match. Instead of guessing
  which relation to use, dbt will move on. Please delete "jaffle_shop"."main"."orders", or rename it to be less ambiguous.
  Searched for: "jaffle_shop"."main"."Orders"
  Found: "jaffle_shop"."main"."orders"

  > in macro load_cached_relation (macros/adapters/relation.sql)
  > called by macro materialization_table_duckdb (macros/materializations/table.sql)
  > called by model Orders (models/Orders.sql)```

that was against dbt-core 1.7.11; do you not see that? Or am I missing something about how to reproduce the error you got with the `tmp` renaming issue not working?
the-ALAM commented 7 months ago

the error you have is because the orders identifier exists already, and if you dropped the orders and rerun the Orders model it should work on your end and to see the tmp try adding the --debug option to your command.

and i must clarify two things:

1- sorry i missed a step from the repro which is: 'attaching a postgres database the model will be build on' eg;

extensions:
        - postgres
attach:
    - path: 'postgres:host= password= user= dbname='
      alias: pg

i didnt add it since i wanted to focus our attention on duckdb

2- second i could've made this issue in duckdb since i suspected the issue is from duckdb except for this https://github.com/duckdb/duckdb/issues/10356#issuecomment-1914089650, so given duckdb's deliberate identifier case insensitivity and that the problem happened with DBT in combination with duckdb, i though it's only rational that i post here first and see if we can reach a solution together

the-ALAM commented 7 months ago

the fix should come from duckdb's support for postgres, not a work around from your end