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

SqlCreateStatementFormatter fails on SQL graph edge tables with no additional columns #1445

Open
noelbundick-msft opened this issue Mar 26, 2022 · 0 comments

Comments

@noelbundick-msft
Copy link

I'm following along the SQL Graph sample and ran into a bug with the ms-mssql.mssql VS Code extension, which originates from the tools service here

In the doc, it creates an EDGE table like the following - note the lack of additional defined columns:

CREATE TABLE friendOf AS EDGE;

If you place the above valid statement in a file by itself and hit Format Document, I get the following stack trace. When in a file with other statements, the entire document fails to format

[Error - 11:19:01 PM] Request textDocument/formatting failed.
  Message: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.SqlTools.ServiceLayer.Formatter.SqlCreateTableStatementFormatter.ProcessInterChildRegion(SqlCodeObject previousChild, SqlCodeObject nextChild) in D:\a\1\s\src\Microsoft.SqlTools.ServiceLayer\Formatter\Impl\SqlCreateTableStatementFormatter.cs:line 129
   at Microsoft.SqlTools.ServiceLayer.Formatter.ASTNodeFormatterT`1.Format() in D:\a\1\s\src\Microsoft.SqlTools.ServiceLayer\Formatter\Impl\ASTNodeFormatterT.cs:line 152
   at Microsoft.SqlTools.ServiceLayer.Formatter.ASTNodeFormatterT`1.Format() in D:\a\1\s\src\Microsoft.SqlTools.ServiceLayer\Formatter\Impl\ASTNodeFormatterT.cs:line 158
   at Microsoft.SqlTools.ServiceLayer.Formatter.FormatterVisitor.Visit(SqlBatch codeObject) in D:\a\1\s\src\Microsoft.SqlTools.ServiceLayer\Formatter\Impl\FormatterVisitor_SqlCodeObjectVisitor.cs:line 31
   at Microsoft.SqlServer.Management.SqlParser.SqlCodeDom.SqlBatch.Accept(ISqlCodeObjectVisitor visitor)
   at Microsoft.SqlTools.ServiceLayer.Formatter.ASTNodeFormatterT`1.Format() in D:\a\1\s\src\Microsoft.SqlTools.ServiceLayer\Formatter\Impl\ASTNodeFormatterT.cs:line 158
   at Microsoft.SqlTools.ServiceLayer.Formatter.FormatterVisitor.Visit(SqlScript codeObject) in D:\a\1\s\src\Microsoft.SqlTools.ServiceLayer\Formatter\Impl\FormatterVisitor_SqlCodeObjectVisitor.cs:line 222
   at Microsoft.SqlServer.Management.SqlParser.SqlCodeDom.SqlScript.Accept(ISqlCodeObjectVisitor visitor)
   at Microsoft.SqlTools.ServiceLayer.Formatter.TSqlFormatterService.DoFormat(String input, FormatOptions options, Boolean verifyOutput, Action`1 postFormatAction) in D:\a\1\s\src\Microsoft.SqlTools.ServiceLayer\Formatter\TSqlFormatterService.cs:line 291
   at Microsoft.SqlTools.ServiceLayer.Formatter.TSqlFormatterService.Format(String input, FormatOptions options, Boolean verifyOutput) in D:\a\1\s\src\Microsoft.SqlTools.ServiceLayer\Formatter\TSqlFormatterService.cs:line 264
   at Microsoft.SqlTools.ServiceLayer.Formatter.TSqlFormatterService.DoFormat(DocumentFormattingParams docFormatParams, TextEdit edit, String text) in D:\a\1\s\src\Microsoft.SqlTools.ServiceLayer\Formatter\TSqlFormatterService.cs:line 172
   at Microsoft.SqlTools.ServiceLayer.Formatter.TSqlFormatterService.<>c__DisplayClass13_0.<FormatAndReturnEdits>b__0() in D:\a\1\s\src\Microsoft.SqlTools.ServiceLayer\Formatter\TSqlFormatterService.cs:line 162
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at Microsoft.SqlTools.ServiceLayer.Formatter.TSqlFormatterService.FormatAndReturnEdits(DocumentFormattingParams docFormatParams) in D:\a\1\s\src\Microsoft.SqlTools.ServiceLayer\Formatter\TSqlFormatterService.cs:line 147
   at Microsoft.SqlTools.ServiceLayer.Formatter.TSqlFormatterService.HandleRequest[T](Func`1 handler, RequestContext`1 requestContext, String requestType) in D:\a\1\s\src\Microsoft.SqlTools.ServiceLayer\Formatter\TSqlFormatterService.cs:line 246
  Code: 0 

The following statement, which defines an edge that does include additional columns, works correctly & allows the document to be formatted as expected:

CREATE TABLE likes (rating INTEGER) AS EDGE;
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

No branches or pull requests

1 participant