dbt-labs / dbt-athena

The athena adapter plugin for dbt (https://getdbt.com)
https://dbt-athena.github.io
Apache License 2.0
228 stars 100 forks source link

feat: Allow custom schema def for tmp tables generated by incremental #659

Closed pierrebzl closed 5 months ago

pierrebzl commented 6 months ago

Description

As mentioned in https://github.com/dbt-athena/dbt-athena/issues/613, I would like for all the temporary intermediate tables to be created in a different schema that we could specify as a config argument of the model.

This would enable us to control and limit access or visibility of those tmp tables. In some cases of parallel processing using unique_tmp_table_suffix flag, we end up creating a lot of those transient tables and we would like to avoid them to appear under the production/staging schemas of our glue catalog.

Models used to test - Optional

Checklist

nicor88 commented 6 months ago

Few notes/consideration:

pierrebzl commented 5 months ago

Thank you for your feedback.

I'm wondering if such property could apply to materialized tables Yes, I think it definitely could be by adjusting the table materialization macro. I was thinking to add this


{% set tmp_schema = config.get('tmp_schema') %}

{%- if tmp_schema is not none -%} {%- set tmp_schema = tmp_schema -%} {% else %} {%- set tmp_schema = schema -%} {%- endif -%}


then pass `schema=tmp_schema` to `api.Relation.create(` https://github.com/dbt-athena/dbt-athena/blob/v1.8.1/dbt/include/athena/macros/materializations/models/table/table.sql#L30
Maybe it can be part of a separate PR, what do you think?

I would need to explore more, I'm not very familiar with all the different use case of materialized table you mentioned.
Also this would require to write new tests.
nicor88 commented 5 months ago

Let's keep table materialization out, and even consider to use another issue to track that idea :)

nicor88 commented 5 months ago

@pierrebzl looks good, few nits, also let's consider to use temp_schema as model parameter for consistency with the code implementation, thanks