You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
generate_surrogate_key macro adds unnecessary empty lines before the compiled code. These empty lines cause fails of sqlfluff linting.
Steps to reproduce
Create a model with the following code:
SELECT
1 AS COLUMN_1,
2 AS COLUMN_2,
{{ dbt_utils.generate_surrogate_key(['COLUMN_1', 'COLUMN_2']) }} AS PK_ID
Compile this model
Expected results
Compiled code should look like this:
SELECT
1 AS COLUMN_1,
2 AS COLUMN_2,
md5(cast(coalesce(cast(COLUMN_1 as TEXT), '_dbt_utils_surrogate_key_null_') || '-' || coalesce(cast(COLUMN_2 as TEXT), '_dbt_utils_surrogate_key_null_') as TEXT)) AS PK_ID
Actual results
The actual compiled code looks like this:
SELECT
1 AS COLUMN_1,
2 AS COLUMN_2,
md5(cast(coalesce(cast(COLUMN_1 as TEXT), '_dbt_utils_surrogate_key_null_') || '-' || coalesce(cast(COLUMN_2 as TEXT), '_dbt_utils_surrogate_key_null_') as TEXT)) AS PK_ID
Core:
- installed: 1.3.0
- latest: 1.3.2 - Update available!
Your version of dbt-core is out of date!
You can find instructions for upgrading here:
https://docs.getdbt.com/docs/installation
Plugins:
- snowflake: 1.3.0 - Up to date!
Describe the bug
generate_surrogate_key
macro adds unnecessary empty lines before the compiled code. These empty lines cause fails of sqlfluff linting.Steps to reproduce
Expected results
Compiled code should look like this:
Actual results
The actual compiled code looks like this:
Screenshots and log output
System information
The contents of your
packages.yml
file:Which database are you using dbt with?
The output of
dbt --version
:Are you interested in contributing the fix?
Yes, I'm interested in contributing. The local tests showed that the problem can be solved by adding whitespace control to the macro code https://github.com/dbt-labs/dbt-utils/blob/main/macros/sql/generate_surrogate_key.sql
If lines 7 to 11 of the macro code look like in the example below
dbt compile
produce the expected results:The text was updated successfully, but these errors were encountered: