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

fix #236, can't write comments in sql files #292

Merged
merged 5 commits into from
Aug 30, 2023

Conversation

cyyeh
Copy link
Member

@cyyeh cyyeh commented Aug 30, 2023

Description

Remove comments in sql statements

Issue ticket number

closes #236

Additional Context

Previously, we didn't remove comments from sql statements.

@vercel
Copy link

vercel bot commented Aug 30, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vulcan-sql-document ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 30, 2023 7:54am

Copy link
Contributor

@kokokuo kokokuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beside multiple test case suggestion and one typo, others LGTM

@@ -167,3 +167,43 @@ it('Extension should throw error when no profile defined', async () => {
`No profile name found`
);
});

it('xtension should remove comments in sql statements', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: xtension should be Extension

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, Please assist to add the multiple line comment test case, thanks !

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -174,3 +174,41 @@ select count(*) as count from vulcan.user where user.id = {{ context.params.user
expect(binding[0].get('$1')).toBe(`user-id`);
expect(resultData).toEqual([{ count: 1 }]);
});

it('Extension should remove comments in sql statements', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please assist to add the multiple line comment test case, thanks !

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added multi-line comments in the test case

Copy link
Contributor

@kokokuo kokokuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Perfect !

@kokokuo kokokuo merged commit bc00c09 into Canner:develop Aug 30, 2023
2 checks passed
@oscar60310
Copy link
Contributor

Hey @kokokuo @cyyeh, this PR does resolve the issue with the comments, but there are some trade-offs involved in doing so.

The syntax -- is the comments for SQL Engines, not for Jinja, which uses {# #}. So this will work:

{# {{ context.params.business_id  }} #}
SELECT * FROM 'data/yelp_academic_dataset_business.parquet' AS businesses

Vulcan treats -- as a normal string so it will try to parametrize it. So this won't work:

-- {{ context.params.business_id  }}
SELECT * FROM 'data/yelp_academic_dataset_business.parquet' AS businesses
-- $1
SELECT * FROM 'data/yelp_academic_dataset_business.parquet' AS businesses

SQL engine complains about that because of number of bindings doesn't match.

If we can prevent the variables in SQL engine comments from being parametrized, the issue will be resolved.


There are some cases we might break:

  1. If the SQL engine DOES need the comments, e.g. for auditing.
    -- Sent from Vulcan SQL: {{ context.user.name | raw }}
    SELECT * FROM xxxxx
  2. Special comments, e.g. optimizer hints.
    SELECT /*+ BKA(t1) NO_BKA(t2) */ * FROM t1 INNER JOIN t2 WHERE ...;
  3. Special syntax. e.g.
    SELECT {{ 1--1 }} AS RESULT; {# should be 2 #}

@cyyeh cyyeh deleted the fix-comments-in-sql branch September 1, 2023 03:38
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

Successfully merging this pull request may close these issues.

Can't write comments in sql files
3 participants