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

sqlfmt removes Comments when there are multiple C-style comments on one line #419

Closed
aersam opened this issue May 10, 2023 · 2 comments · Fixed by #429
Closed

sqlfmt removes Comments when there are multiple C-style comments on one line #419

aersam opened this issue May 10, 2023 · 2 comments · Fixed by #429
Labels
bug Something isn't working

Comments

@aersam
Copy link

aersam commented May 10, 2023

Describe the bug
I have the following sql:

SELECT t.customer_sk AS `Customer_IdDWH`, t.customer_id AS `Customer_IdOrig`, t.__identity AS `CustomerCreditLimit_Agg_IdDWH`, t.kreditlimit_intern /* not existing, proposal: credit_limit_intern (92%) */ AS `KreditlimitIntern`, t.kreditlimit_versichert /* not existing */ AS `KreditlimitVersichert`, t.valid_from /* not existing */ AS `ValidFrom`, t.valid_to /* not existing */ AS `ValidTo` FROM `gold`.`dim_customer_credit_limit_agg` AS t

sqlfmt produces this:

select  /* not existing */
    t.customer_sk as `Customer_IdDWH`,
    t.customer_id as `Customer_IdOrig`,
    t.__identity as `CustomerCreditLimit_Agg_IdDWH`,
    t.kreditlimit_intern as `KreditlimitIntern`,
    t.kreditlimit_versichert as `KreditlimitVersichert`,
    t.valid_from as `ValidFrom`,
    t.valid_to as `ValidTo`
from `gold`.`dim_customer_credit_limit_agg` as t  /* not existing */

Some comments are removed entirely, others are just at the wrong place

Expected behavior
The comments should stick where they are. Interestingly, if I first format the SQL above with the VS Code SQLTools and start with this:

SELECT t.customer_sk AS `Customer_IdDWH`,
    t.customer_id AS `Customer_IdOrig`,
    t.__identity AS `CustomerCreditLimit_Agg_IdDWH`,
    t.kreditlimit_intern
    /* not existing, proposal: credit_limit_intern (92%) */
    AS `KreditlimitIntern`,
    t.kreditlimit_versichert
    /* not existing */
    AS `KreditlimitVersichert`,
    t.valid_from
    /* not existing */
    AS `ValidFrom`,
    t.valid_to
    /* not existing */
    AS `ValidTo`
FROM `gold`.`dim_customer_credit_limit_agg` AS t

then it works. Don't know if that helps

Additional context
What is the output of sqlfmt --version?
sqlfmt, version 0.18.0

@tconbeer
Copy link
Owner

Wow, I'm shocked, but can repro. I'm sure it's because there are multiple comments on one line -- I don't think we have a test case for that, and that's impossible with the typical -- comments. Thanks for the report!

@tconbeer tconbeer changed the title sqlfmt removes Comments sqlfmt removes Comments when there are multiple C-style comments on one line May 10, 2023
@tconbeer tconbeer added the bug Something isn't working label May 10, 2023
@dnuzz
Copy link

dnuzz commented May 16, 2023

This actually causes some real conflicts in a project we have. Following for a fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants