Skip to content

MSSQL: Add support for functionality MERGE output clause #1790

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 20 commits into from
Apr 5, 2025

Conversation

dilovancelik
Copy link
Contributor

@dilovancelik dilovancelik commented Apr 1, 2025

Hey I have added a feature to handle OUTPUT Statements in the end of merge statements, which is used in MS SQL fixes #1789 that I created.

  • I've added the OUTPUT Keyword
  • I've added a struct in for Output in ast/mod.rs
  • I've added an optional Output parameter to the Merge struct in ast/mod.rs
  • added function for parsing the output parameter in parser/mod.rs
  • updated parse merge clause function, to break on output keyword
  • updated parse merge to handling of the output clause
  • added and updated tests

This is my first Pull Request to an open source project so please let me know, if there is something missing, or something I did wrong.

Thank you for a great crate.

@dilovancelik dilovancelik changed the title added functionality to handle output statement added functionality to handle MSSQL output statement Apr 2, 2025
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.

Thanks @dilovancelik! The changes look reasonable to me overall, left some comments

Comment on lines 14595 to 14607
self.expect_keyword_is(Keyword::INTO)?;
let temporary = self
.parse_one_of_keywords(&[Keyword::TEMP, Keyword::TEMPORARY])
.is_some();
let unlogged = self.parse_keyword(Keyword::UNLOGGED);
let table = self.parse_keyword(Keyword::TABLE);
let name = self.parse_object_name(false)?;
let into_table = SelectInto {
temporary,
unlogged,
table,
name,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks to be the same code as in parse_select? could we factor that into a function like parse_into_clause() that could be reused in both places?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that makes sense. I made it, it's own function, which I called parse_select_into, since it returns the SelectInto structure, that way its consistent

@dilovancelik
Copy link
Contributor Author

Thanks @dilovancelik! The changes look reasonable to me overall, left some comments

@iffyio thanks a lot for the comments, I just applied your suggestions. For the other comments, I believe they make a lot of sense, and have implemented what you suggested. I have not resolved those conversations, since I don't know if you would like to do it your self after checking my new commits :)

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.

left a comment to reuse the new select_into function, beyond that this looks good to me!

})
}

fn parse_select_into(&mut self) -> Result<SelectInto, ParserError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

oh could we also update this usage to call this parse_select_into() function as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea, I've changed it to use the new function!

@dilovancelik
Copy link
Contributor Author

I updated the old usage to use the new parse_select_into function and ran all tests :)

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! Thanks @dilovancelik!
cc @alamb

@iffyio iffyio changed the title added functionality to handle MSSQL output statement MSSQL: Add support for functionality MERGE output clause Apr 4, 2025
@iffyio
Copy link
Contributor

iffyio commented Apr 4, 2025

@dilovancelik when you get the chance to could you merge in latest from main, in order to fix the CI issue?

@dilovancelik
Copy link
Contributor Author

dilovancelik commented Apr 4, 2025

should be added now, and thank you for the review

@iffyio
Copy link
Contributor

iffyio commented Apr 4, 2025

@dilovancelik Oh could you take a look at the added commits, not sure how the merge from main was done but there's some extraneous diffs that's been brought into the PR

@dilovancelik
Copy link
Contributor Author

Hey I did a rebase, and I think something went wrong, now I just did a classic merge, and et looks like the extra commits are gone. Sorry.

@dilovancelik
Copy link
Contributor Author

I don't understudy why run clippy fails, It does. not do it on my machine, and it also seems to be we code which is not part of my PR. Is there anything I can do to help out with it?

@iffyio
Copy link
Contributor

iffyio commented Apr 5, 2025

Oh yes so that failure is my bad and came from the last PR that landed on main yesterday, it fails on rust 1.86. To be clear its not related to this PR but its possible to resolve, @dilovancelik would you be able to resolve the lint failure in this PR and I can merge both in the same go? Sorry for the hassle

@dilovancelik
Copy link
Contributor Author

No worries, I just couldn't get the error locally so couldn't fix. That however was because my main was one commit behind. I synced and removed the borrow which threw the error.

Again thanks for all the feedback, this has been a really pleasant first OS experience

@iffyio
Copy link
Contributor

iffyio commented Apr 5, 2025

Awesome thanks again @dilovancelik!

@iffyio iffyio merged commit 610096c into apache:main Apr 5, 2025
9 checks passed
@dilovancelik dilovancelik deleted the add-support-for-output-clause-tsql branch April 5, 2025 18:53
ayman-sigma pushed a commit to sigmacomputing/sqlparser-rs that referenced this pull request Apr 10, 2025
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.

Add support for OUTPUT Clause in TSQL (MS SQL) Merge statements
4 participants