-
Notifications
You must be signed in to change notification settings - Fork 3
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
Restructure SQL Parsing for SQL Server to use Microsoft.SqlServer.DacFx
#4
Comments
While doing any code refactoring around variable parsing/substitution as part of this issue #1 should be kept in mind. Likely |
An initial, rough implementation is available via the draft pull request DbUp/DbUp#455. A potential issue with this solution is it pulls in a large new dependency (i.e. We also now need to handle errors from the parser, which is much more strict at checking syntax than our existing custom built one. What are everyone's feelings on continuing down this road? (ping @droyad @dazinator @sungam3r ) |
My preference would be - firstly to keep our native go splitter in place without these additional dependencies. It's a simple and lightweight solution -- we dont care about fully parsing or validating the t-sql language- we only need go splitting. The splitter we have has occasional new edge cases found (and fixed) to enable that but it does that job in a comparatively lightweight manner. Then secondly - we could put this new dacfx based splitter in a new and entirely optionally adopted package / project (DbUp.SqlServer.DacFx?). I personally wouldn't adopt this package myself just for its go splitter (because I find the dbup native one sufficient) but perhaps over time it will get other compelling features that leverage the more capable dacfx parser such as sqlcmd variable support etc - in which case if I needed those features I'd adopt this package and accept the cost of additional dependencies. . |
Yes, the package is really big - 10 mb, even if you try to get only one required library from it - Microsoft.SqlServer.ScriptDom, it will be 4.5 mb. On the other hand, I see a benefit in removing all parsing code from this project. DbUp is not about parsing or it should not be about it. |
@sungam3r Unfortunately you can't remove the parsing code because then many scripts do not work. In SQL Server's case at least, the "GO" statement is only respected by the client. If you send "GO" to the server in the text of a We have to split scripts on "GO" statements somehow. I was hoping we could use Microsoft's code to do that reliably. |
@dazinator Not sure I agree that our "GO" splitting code is simple or particularly lightweight, however you are making some good points there. The size of the package is making me have second thoughts. |
Are you sure? |
@sungam3r yes. "Go" is not valid t-sql. Tooling (such as sql management studio) use it as a batch seperator within script files. https://docs.microsoft.com/en-us/sql/t-sql/language-elements/sql-server-utilities-statements-go?view=sql-server-ver15 |
@AdrianJSClark - yep fair enough. By lightweight I meant in terms of dependencies - I think it only leverages very basic low level stuff like stream and char etc. By simple - I guess it depends on your outlook :-) I certainly found it simplistic well.. simpler code than what a full sql parser would look like - it's not a recursive descent parser, its not tokenising or using a grammar etc. Perhaps I should have used the word "primitive" instead of simple :-D |
@dazinator I know that |
@sungam3r not sure what you mean. Just to avoid confusion and for my own sanity I'd like to make the distinction that |
Right. I am talking only about SqlServer. Ok. It doesn’t matter, and it’s already clear that the parser is heavy. |
DbUp parses the text of each SQL script for two purposes:
Currently these two purposes are handled using the same parsing logic. This issue was opened to split these two purposes into their own code paths so that each can be handled by appropriate code.
Initially the Variable Substitution parsing will keep the existing
SqlParser
functionality.To split the SQL Server T-SQL statements, the parsing will be achieved using a Microsoft-supplied package called "Microsoft.SqlServer.DacFx" which includes a T-SQL parser. This offloads the responsibility for writing a performant, resiliant, compliant parser.
A simple LINQPad-based proof-of-concept to split SQL into batches using
Microsoft.SqlServer.DacFx
which you can see here: DacFx Parsing LINQPad POCEdited from original comment posted by @AdrianJSClark in DbUp/DbUp#439 (comment)
The text was updated successfully, but these errors were encountered: