Skip to content

Commit

Permalink
Try out this hack
Browse files Browse the repository at this point in the history
  • Loading branch information
jwills committed Sep 26, 2024
1 parent 85862a1 commit 1e83813
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions dbt/adapters/duckdb/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,17 @@ def render_column_constraint(cls, constraint: ColumnLevelConstraint) -> Optional
"""Render the given constraint as DDL text. Should be overriden by adapters which need custom constraint
rendering."""
if constraint.type == ConstraintType.foreign_key:
# DuckDB doesn't support 'foreign key' as an alias
return f"references {constraint.expression}"
if constraint.to and constraint.to_columns:
# TODO: this is a hack to get around a limitation in DuckDB around setting FKs
# across databases.
pieces = constraint.to.split(".")
if len(pieces) > 2:
constraint_to = ".".join(pieces[1:])
else:
constraint_to = constraint.to
return f"references {constraint_to} ({', '.join(constraint.to_columns)})"
else:
return f"references {constraint.expression}"
else:
return super().render_column_constraint(constraint)

Expand Down
6 changes: 3 additions & 3 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# install latest changes in dbt-core + dbt-tests-adapter
# git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core
# git+https://github.com/dbt-labs/dbt-adapters.git#subdirectory=dbt-tests-adapter
git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core
git+https://github.com/dbt-labs/dbt-adapters.git#subdirectory=dbt-tests-adapter

dbt-tests-adapter==1.9.2
#dbt-tests-adapter==1.9.2

boto3
mypy-boto3-glue
Expand Down

0 comments on commit 1e83813

Please sign in to comment.