Skip to content

[Feature] Datasharing: cross-database support #637

Description

@dataders

Describe the feature

What

I think this is a direct successor to dbt-labs/dbt-redshift#217. There's many other related issues listed below.

Today, the only supported cross-database scenario in dbt-redshift is to allow source tables to be in another database. There are considerable caveats to this narrow use case:

  1. a cluster is used of node_type ra3 or serverless
  2. a profiles.yml profile that specifies: ra3_node: true
  3. a source table is defined in a database different than what's given in profile
  4. all models referencing the "foreign db" source table must be materialized as a table (views are not supported)

there is a newer feature, still in preview, Datashare, that allows writes to external databases. For example, if I am logged into the FOO database on cluster FIZZ, a configuration exists such that I can create tables within database BAR on cluster BUZZ (and vise versa).

Ideal end-state

A dbt-redshift project could take any model in the DAG and have it materialized in another with a simply as providing {{ config( database = 'BAR' ) }} at the top of the model. That is, provided that the databases used have been properly configured as such.

How

Challenges

The challenges in supporting this new feature are varied:

problem example
dbt-redshift inheirits from dbt-postgres redshift__create_schema() which invokes postgres__create_schema() which only uses two-part names, schema.relation, exlcuding a required database
dbt-redshift relies on postgres metadata views that don't support Datashares redshift__get_columns_in_relation() queries information_schema."columns" but should perhaps use SVV_ALL_COLUMNS instead`
discrepancy across Redshift SKUs for support of Datashares ra3_node and serverless supports Datasharing/crossdb-writes, dc2 clusters do not
discrepancy in performance between pg_* metadata tables and SVV_* datashare-supporting Redshift system tables information_schema."columns" takes a few dozen millisecionds to return all column metadata in the current database. SVV_ALL_COLUMNS can be more than 50X slower than this

Work required

Before the actual coding begins, it is imperative that we first learn the following:

  • what datasharing scenarios could feasibly be supported
  • the current & future best practice for fetching metadata
  • the performance impact of using SVV_* tables for all SKUs (ra3, serverless, dc2)
### Possible work required
- [ ] shift away from `pg_` metadata queries to those that include "external" database metadata
- [ ] override any `postgres` macros that exclude `database` from `relation` name e.g. redshift__create_schema()
- [ ] (possible) remove both `verify_database` method and `ra3_node` profile parameter
- [ ] ensure functionality of metadata-related macros in "core" packages such as dbt-codegen, dbt-utils, dbt-audit-helper etc 
- [ ] write cross database integration tests
- [ ] add RA3 and serverless to our CI pipeline

related

### related issues
- [ ] https://github.com/dbt-labs/dbt-core/issues/3179
- [ ] https://github.com/dbt-labs/dbt-core/issues/3236
- [ ] https://github.com/dbt-labs/dbt-core/issues/5297
- [ ] dbt-labs/dbt-redshift#94
- [ ] dbt-labs/dbt-adapters#652
- [ ] dbt-labs/dbt-redshift#217
- [ ] dbt-labs/dbt-redshift#281 
- [ ] dbt-labs/dbt-redshift#501
- [ ] dbt-labs/dbt-adapters#645
- [ ] dbt-labs/dbt-adapters#643
- [ ] dbt-labs/dbt-adapters#639
- [ ] https://github.com/dbt-labs/dbt-redshift/pull/905

relevant AWS Redshift docs

Who will this benefit?

dbt-redshift users who want to use Datasharing to federate a dbt project across databases and clusters

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions