Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

star macro issue when no columns returned #898

Open
Datarogie opened this issue May 23, 2024 · 3 comments
Open

star macro issue when no columns returned #898

Datarogie opened this issue May 23, 2024 · 3 comments

Comments

@Datarogie
Copy link

If there are no columns returned in the macro it returns as commented out block but the issue is if the star macro isn't the last selected field in a select statement, it will place a comma on the outside of the comment block.

-- example
with
  final as (
    select
      {{ dbt_utils.star( ref("foo")) }},
      {{ dbt_utils.star( ref("bar")) }}
      
      from ...
)

select * from final

-- In this example let say the table foo doesn't return any columns. The compiled code looking like 
with
  final as (
    select
      /* no columns returned from star() macro */,
      bar_column1,
      bar_column2...
     
    from ...
)

select * from final
-- The above will fail to execute due to the comma outside of the comment block.

Simple fix would be to change the method being used to comment to simple double dash. Also believe this change will still comply with SQLFluff.

Reference source line

{% do return("/* no columns returned from star() macro */") %}

@asarraf
Copy link
Contributor

asarraf commented Jul 9, 2024

I am also thinking ... While =0 makes sense, what purpose does <0 serve in this line?

{%- if cols|length <= 0 -%}

@asarraf
Copy link
Contributor

asarraf commented Jul 10, 2024

@Datarogie, Shouldn't this fail loud if no columns are returned from foo?
What use case would a change serve?

@asarraf
Copy link
Contributor

asarraf commented Jul 17, 2024

The addition of , will help the user remind that something is missing otherwise, one might totally miss the issue that the first Ref isn't returning any column

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants