Skip to content

Add support for MSSQL's OPENJSON WITH clause #1498

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

Merged
merged 5 commits into from
Nov 13, 2024
Merged

Conversation

gaoqiangz
Copy link
Contributor

Resolves issue #1494

Copy link
Contributor

@lovasoa lovasoa left a comment

Choose a reason for hiding this comment

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

No blocker for me ! This would be of great use for us at SQLPage, where the use of sql json functions is common.

@@ -10000,7 +10000,7 @@ impl<'a> Parser<'a> {
table_with_joins: Box::new(table_and_joins),
alias,
})
} else if dialect_of!(self is SnowflakeDialect | GenericDialect) {
} else if dialect_of!(self is SnowflakeDialect | GenericDialect | MsSqlDialect) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You may want to update the comments below too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah to @lovasoa's suggestion, one double check on my end @gaoqiangz is the parenthesis around the joined table supported syntax for the openjson syntax? Thinking if its not, then we would be able to skip this change entirely. If it is then indeed lets update the comments to account for mssql.
Additionally, can we add a test case covering the behavior (as in a roundtrip test like SELECT ... FROM T AS A CROSS APPLY (OPENJSON(...) WITH ...) AS B so that we catch any regression on the behavior going forward

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have checked that MSSQL doesn't support parenthesis around the openjson syntax.
I'll revert this change.

@@ -10000,7 +10000,7 @@ impl<'a> Parser<'a> {
table_with_joins: Box::new(table_and_joins),
alias,
})
} else if dialect_of!(self is SnowflakeDialect | GenericDialect) {
} else if dialect_of!(self is SnowflakeDialect | GenericDialect | MsSqlDialect) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah to @lovasoa's suggestion, one double check on my end @gaoqiangz is the parenthesis around the joined table supported syntax for the openjson syntax? Thinking if its not, then we would be able to skip this change entirely. If it is then indeed lets update the comments to account for mssql.
Additionally, can we add a test case covering the behavior (as in a roundtrip test like SELECT ... FROM T AS A CROSS APPLY (OPENJSON(...) WITH ...) AS B so that we catch any regression on the behavior going forward

Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

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

LGTM! cc @alamb

@coveralls
Copy link

Pull Request Test Coverage Report for Build 11716305539

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 264 of 303 (87.13%) changed or added relevant lines in 3 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.02%) to 89.376%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/ast/query.rs 20 22 90.91%
src/parser/mod.rs 38 41 92.68%
tests/sqlparser_mssql.rs 206 240 85.83%
Files with Coverage Reduction New Missed Lines %
src/ast/query.rs 1 86.43%
Totals Coverage Status
Change from base Build 11712467818: -0.02%
Covered Lines: 30876
Relevant Lines: 34546

💛 - Coveralls

@alamb
Copy link
Contributor

alamb commented Nov 13, 2024

🚀

@alamb alamb merged commit 9082448 into apache:main Nov 13, 2024
8 checks passed
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.

5 participants