dbt-sqlserver
dbt-sqlserver copied to clipboard
clean up relation construction
we should try and standardize on a convention of using {{ relation }}
wherever possible over these variants:
-
{{ relation.schema }}.{{ relation.identifier }}
-
to_relation.schema ~ '.' ~ to_relation.identifier
@jtcohen6, how do we disable by default database
being included when calling {{ relation }}
? Do we have create a child of the Relation
class?
https://github.com/dbt-msft/dbt-sqlserver/blob/4b3f7bce48f3ffa8509a6b16bcd55976a973c2c1/dbt/include/sqlserver/macros/adapters.sql#L49
https://github.com/dbt-msft/dbt-sqlserver/blob/4b3f7bce48f3ffa8509a6b16bcd55976a973c2c1/dbt/include/sqlserver/macros/adapters.sql#L111
https://github.com/dbt-msft/dbt-sqlserver/blob/4b3f7bce48f3ffa8509a6b16bcd55976a973c2c1/dbt/include/sqlserver/macros/adapters.sql#L118
https://github.com/dbt-msft/dbt-sqlserver/blob/4b3f7bce48f3ffa8509a6b16bcd55976a973c2c1/dbt/include/sqlserver/macros/adapters.sql#L130
https://github.com/dbt-msft/dbt-sqlserver/blob/4b3f7bce48f3ffa8509a6b16bcd55976a973c2c1/dbt/include/sqlserver/macros/adapters.sql#L152-L154
https://github.com/dbt-msft/dbt-sqlserver/blob/4b3f7bce48f3ffa8509a6b16bcd55976a973c2c1/dbt/include/sqlserver/macros/adapters.sql#L168-L169
+1 to using {{ relation }}
instead of concatenating.
Check out how we did this same thing in dbt-spark
:
-
SparkIncludePolicy, which turns off
database
- That policy is then set within SparkRelation
- Set
Relation = SparkRelation
within SparkAdapter
beautiful. I'll open a PR.
maybe being extra here... but how about concatenating a relation by _
instead of .
? We do this for index naming. Looking for a cleaner way than the below.
https://github.com/dbt-msft/dbt-sqlserver/blob/4b3f7bce48f3ffa8509a6b16bcd55976a973c2c1/dbt/include/sqlserver/macros/adapters.sql#L116-L139
potential solutions
- duplicate
BaseRelation.render()
, but with'_'.join()
instead of'.'.join()
. Seems like overkill to me - just quote the rendered relation with square brackets so that the
.
is ignored? @mikaelene, can you look up an index name that has a.
in it? I'm pretty sure you can - just do something like below. not sure if you can call
.replace()
onrelation
directly like that though.{% set cci_name = relation.replace(".", "_") ~ "_cci" %}
Option 1 doesn't sound crazy to me. You could define a special method on SQLServerRelation
, something like index_render
, and then call {{ full_relation.index_render() }}
as needed.
It's fewer moving pieces if you handle in Jinja or SQL, of course.
Should happen together with #325