Skip to content

Commit d90ce7d

Browse files
llalimohitagarwal-sqlUrvashi RajzijchenMateo Marenco
authored
Sync repos: Release 170.121.2 (#168)
* Merged PR 1790439: Remove unused variable in Antlr grammar file TSql170 # Pull Request Template for ScriptDom ## Description Remove unused local variable from _alterDbModifyAzureOptions_ grammar rule and ensure accurate token position tracking for WITH MANUAL_CUTOVER clause. Details: • Eliminated redundant _hasManualCutover_ variable. • Improved maintainability and clarity. • Ensured UpdateTokenInfo is called for position tracking. ## Code Change - [x] The [Common checklist](https://msdata.visualstudio.com/SQLToolsAndLibraries/_git/Common?path=/Templates/PR%20Checklist%20for%20SQLToolsAndLibraries.md&version=GBmain&_a=preview) has been reviewed and followed - [x] Code changes are accompanied by appropriate unit tests - [x] Identified and included SMEs needed to review code changes - [x] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=make-the-changes-in) here to make changes in the code ## Testing - [x] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=to-extend-the-tests-do-the-following%3A) here to add new tests for your feature Re-ran all existing tests to ensure the code changes are not impacting anything. All tests are passing successfully: ![image.png](https://msdata.visualstudio.com/c6789c20-b819-4bfd-9917-11471655156e/_apis/git/repositories/2247f543-55d8-45df-a9fe-23820ae656af/pullRequests/1790439/attachments/image.png) ## Documentation - [ ] Update relevant documentation in the [wiki](https://dev.azure.com/msdata/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki) and the README.md file ## Additional Information Please provide any additional information that might be helpful for the reviewers N/A. ---- #### AI description (iteration 1) #### PR Classification This pull request is a code cleanup that removes an unused variable and refactors manual cutover token handling in the TSql170 Antlr grammar file. #### PR Summary The changes remove the unused boolean variable in `SqlScriptDom/Parser/TSql/TSql170.g` and replace its assignment with a call to `UpdateTokenInfo` when processing the manual cutover identifier. - `SqlScriptDom/Parser/TSql/TSql170.g`: Removed the unnecessary declaration and assignment of the variable and added `UpdateTokenInfo` to update token information for manual cutover. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> Related work items: #4005325 * Merged PR 1790607: Remove Unused Parameter form External Model # Pull Request Template for ScriptDom ## Description #### AI description (iteration 1) #### PR Classification Code cleanup: Removing an unused parameter from external model parser definitions. #### PR Summary This PR streamlines the T-SQL grammar by removing the unused parameter "encounteredOptions" from external model statement rules. - `SqlScriptDom/Parser/TSql/TSql170.g`: Removed `long encounteredOptions = 0;` from the `createExternalModelStatement` rule. - `SqlScriptDom/Parser/TSql/TSql170.g`: Removed `long encounteredOptions = 0;` from the `alterExternalModelStatement` rule. * Merged PR 1789319: Resend PR for vector type 2nd parameter Resending PR !1780528 which was reverted to unblock release Before submitting your pull request, please ensure you have completed the following: - [ ] The [Common checklist](https://msdata.visualstudio.com/SQLToolsAndLibraries/_git/Common?path=/Templates/PR%20Checklist%20for%20SQLToolsAndLibraries.md&version=GBmain&_a=preview) has been reviewed and followed - [ ] Code changes are accompanied by appropriate unit tests - [ ] Identified and included SMEs needed to review code changes - [ ] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=make-the-changes-in) here to make changes in the code - [ ] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=to-extend-the-tests-do-the-following%3A) here to add new tests for your feature - [ ] Update relevant documentation in the [wiki](https://dev.azure.com/msdata/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki) and the README.md file Please provide any additional information that might be helpful for the reviewers Reverting commit cd69b7806dfbd6a581dbe50779a07ac70047cee8 to unblock release Before submitting your pull request, please ensure you have completed the following: - [ ] The [Common checklist](https://msdata.visualstudio.com/SQLToolsAndLibraries/_git/Common?path=/Templates/PR%20Checklist%20for%20SQLToolsAndLibraries.md&version=GBmain&_a=preview) has been reviewed and followed - [ ] Code changes are accompanied by appropriate unit tests - [ ] Identified and included SMEs needed to review code changes - [ ] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=make-the-changes-in) here to make changes in the code - [ ] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=to-extend-the-tests-do-the-following%3A) here to add new tests for your feature - [ ] Update relevant documentation in the [wiki](https://dev.azure.com/msdata/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki) and the README.md file Please provide any additional information that might be helpful for the reviewers Revert cd69b7806dfbd6a581dbe50779a07ac70047cee8 ---- This PR temporarily reverts a previous commit to remove vector data type support. The pull request reverses vector-related changes by deleting files and code modification... * Merged PR 1792393: Add support for Optimized Locking database option As a result of the new [Optimized Locking](https://learn.microsoft.com/en-us/sql/relational-databases/performance/optimized-locking?view=sql-server-ver17) feature, new DDL has been added: `ALTER DATABASE MyDb SET OPTIMIZED_LOCKING = ON/OFF`. This PR adds this DDL to the grammar. - [X] The [Common checklist](https://msdata.visualstudio.com/SQLToolsAndLibraries/_git/Common?path=/Templates/PR%20Checklist%20for%20SQLToolsAndLibraries.md&version=GBmain&_a=preview) has been reviewed and followed - [X] Code changes are accompanied by appropriate unit tests - [X] Identified and included SMEs needed to review code changes - [X] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=make-the-changes-in) here to make changes in the code - [X] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=to-extend-the-tests-do-the-following%3A) here to add new tests for your feature - [X] Update relevant documentation in the [wiki](https://dev.azure.com/msdata/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki) and the README.md file Please provide any additional information that might be helpful for the reviewers ---- This pull request introduces a new feature by adding support for the Optimized Locking database option. The pull request implements the support for the Optimized Locking option in ALTER DATABASE statements by extending both the parser and code generation components. - `SqlScriptGeneratorVisitor.OptimizedLockingAlterDatabaseOption.cs`: Implements the visitor method to generate script text for the new option based on its state (ON/OFF). - `TSql170.g` and `TSqlFabricDW.g`: Add new grammar rules to parse the Optimized Locking option and integrate it into the database option parsing logic. - `Ast.xml`: Introduces a new AST class for the Optimized Locking database option. - `DatabaseOptionKind.cs` and `CodeGenerationSupporter.cs`: Update the enumeration and constant definitions to include the Optimized Locking option. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> * Update .NET SDK to latest patch version (8.0.414) * Merged PR 1792484: Updating .md files Please provide a detailed description, include the link to the design specification or SQL feature document for the new TSQL syntaxes. Make sure to add links to the Github or DevDiv issue Before submitting your pull request, please ensure you have completed the following: - [ ] The [Common checklist](https://msdata.visualstudio.com/SQLToolsAndLibraries/_git/Common?path=/Templates/PR%20Checklist%20for%20SQLToolsAndLibraries.md&version=GBmain&_a=preview) has been reviewed and followed - [ ] Code changes are accompanied by appropriate unit tests - [ ] Identified and included SMEs needed to review code changes - [ ] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=make-the-changes-in) here to make changes in the code - [ ] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=to-extend-the-tests-do-the-following%3A) here to add new tests for your feature - [ ] Update relevant documentation in the [wiki](https://dev.azure.com/msdata/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki) and the README.md file Please provide any additional information that might be helpful for the reviewers Updating .md files ---- Documentation update. This pull request revises and expands the project’s documentation to clarify developer workflows and update build instructions for SqlScriptDOM. - `/github/copilot-instructions.md` now features detailed sections on key points, build/test workflows, and common pitfalls. - A new file, `/github/BUG_FIXING_GUIDE.md`, has been added to provide a step-by-step guide for bug fixing in SqlScriptDOM. - `/README.md` and `/CONTRIBUTING.md` have been updated to use repository-relative paths and improve instructions for modifying the DOM, parser, and script generator. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> * Merged PR 1804708: [ai_generate_embeddings] PARAMETERS without parentheses This PR fixes a bug for AI_GENERATE_EMBEDDINGS when PARAMETERS comes without parentheses "SELECT AI_GENERATE_EMBEDDINGS(large_text USE MODEL MyAzureOpenAIModel PARAMETERS '{"dimensions" : 768 }')" Current behavior only allows PARAMETERS with parentheses. This PR adds syntax change along with tests. - [X] The [Common checklist](https://msdata.visualstudio.com/SQLToolsAndLibraries/_git/Common?path=/Templates/PR%20Checklist%20for%20SQLToolsAndLibraries.md&version=GBmain&_a=preview) has been reviewed and followed - [X] Code changes are accompanied by appropriate unit tests - [X] Identified and included SMEs needed to review code changes - [X] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=make-the-changes-in) here to make changes in the code - [X] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=to-extend-the-tests-do-the-following%3A) here to add new tests for your feature - [ ] Update relevant documentation in the [wiki](https://dev.azure.com/msdata/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki) and the README.md file Please provide any additional information that might be helpful for the reviewers First commit ---- Bug fix to correctly handle the ScriptDom PARAMETERS clause without parentheses. This pull request fixes the handling of the PARAMETERS clause in the AI_GENERATE_EMBEDDINGS function by conditionally emitting parentheses only when needed. - `SqlScriptGeneratorVisitor.AiGenerateEmbeddingsFunction.cs`: Modified the code to check if OptionalParameters is a StringLiteral and, if so, emit it without surrounding parentheses. - `TSql170.g`: Updated the grammar rules for aiGenerateEmbeddingsFunctionCall to accept either a parenthesized expression or a direct string literal. - Test files: Adjusted baseline and test scripts, including error expectations, to validate the new syntax support. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> Related work items: #4692491 * Merged PR 1808102: [AI_GENERATE_EMBEDDINGS] Additional Syntax Change # Pull Request Template for ScriptDom ## Description Please provide a detailed description, include the link to the design specification or SQL feature document for the new TSQL syntaxes. Make sure to add links to the Github or DevDiv issue This PR updates the `aiGenerateEmbeddingsFunctionCall` grammar and the script generator to: - **Constrain model names** after `USE MODEL` to a **single token** (either an `Identifier` or one `QuotedIdentifier` like `[dbo.MyDefaultModel]`). Multi-part names (e.g., `dbo.MyDefaultModel`, `[dbo].[MyDefaultModel]`, `MyDb.dbo.Model`) now **fail at parse time**. - **Refine `PARAMETERS`** parsing to accept an **expression** with or without parentheses, but **reject** a **bare JSON string literal** (e.g., `PARAMETERS '{"a":1}'`). This is because the optional PARAMETERS can only be a MSJSON not varchar/nvarchar. ## What changed ### Grammar (`TSql170.g`) - **Model name**: - Replaced `schemaObjectThreePartName` with a **single-part** alternative: - `Identifier` **or** `QuotedIdentifier` (one token). - This allows `[dbo.MyDefaultModel]` (single token), but rejects dotted multi-part forms. - **PARAMETERS**: - Accept as **keyword** *or* **identifier** matched to `"Parameters"`. - Value can be either: - `PARAMETERS ( <expr> )` → wraps `<expr>` in a `ParenthesisExpression` to preserve parens. - `PARAMETERS <expr>` → **guarded** to **forbid** a leading ASCII/Unicode **string literal** (blocks `PARAMETERS '{...}'`). - No support added for `=` (kept “same as before” by design). ### Script generator (`SqlScriptGeneratorVisitor.AIGenerateEmbeddingsFunction.cs`) - **Do not force parentheses** for `OptionalParameters`. Emit: - `PARAMETERS {space} <fragment>` - If the AST contains a `ParenthesisExpression`, it prints its own `(`…`)`. Bare expressions print without parens. Before submitting your pull request, please ensure you have completed the following: ## Code Change - [X] The [Common checklist](https://msdata.visualstudio.com/SQLToolsAndLibraries/_git/Common?path=/Templates/PR%20Checklist%20for%20SQLToolsAndLibraries.md&version=GBmain&_a=preview) has been reviewed and followed - [X] Code changes are accompanied by appropriate unit tests - [X] Identified and included SMEs needed to review code changes - [X] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=make-the-changes-in) here to make changes in the code ## Testing - [X] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=to-extend-the-tests-do-the-following%3A) here to add new tests for your feature ## Documentation - [ ] Update relevant documentation in the [wiki](https://dev.azure.com/msdata/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki) and the README.md file ## Additional Information Please ... * Merged PR 1814233: add OPTIMIZE_FOR_ARRAY_SEARCH option for Json index # Pull Request Template for ScriptDom ## Description Please provide a detailed description, include the link to the design specification or SQL feature document for the new TSQL syntaxes. Make sure to add links to the Github or DevDiv issue Before submitting your pull request, please ensure you have completed the following: ## Code Change - [ ] The [Common checklist](https://msdata.visualstudio.com/SQLToolsAndLibraries/_git/Common?path=/Templates/PR%20Checklist%20for%20SQLToolsAndLibraries.md&version=GBmain&_a=preview) has been reviewed and followed - [ ] Code changes are accompanied by appropriate unit tests - [ ] Identified and included SMEs needed to review code changes - [ ] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=make-the-changes-in) here to make changes in the code ## Testing - [ ] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=to-extend-the-tests-do-the-following%3A) here to add new tests for your feature ## Documentation - [ ] Update relevant documentation in the [wiki](https://dev.azure.com/msdata/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki) and the README.md file ## Additional Information Please provide any additional information that might be helpful for the reviewers This PR added OPTIMIZE_FOR_ARRAY_SEARCH option for Json index. A test case is added. ---- #### AI description (iteration 1) #### PR Classification This PR introduces a new feature by adding support for the OPTIMIZE_FOR_ARRAY_SEARCH option in JSON indexes. #### PR Summary The changes enable the OPTIMIZE_FOR_ARRAY_SEARCH option in ScriptDom by updating parser mappings, constants, and test cases to validate the new JSON index syntax. - `SqlScriptDom/Parser/TSql/IndexOptionKind.cs`: Added a new enum value for OptimizeForArraySearch. - `SqlScriptDom/Parser/TSql/CodeGenerationSupporter.cs`: Introduced a new constant for OPTIMIZE_FOR_ARRAY_SEARCH. - `SqlScriptDom/Parser/TSql/IndexOptionHelper.cs`: Mapped the new index option to support the updated feature. - Test files (`Test/SqlDom/TestScripts/JsonIndexTests170.sql`, `Test/SqlDom/Baselines170/JsonIndexTests170.sql`, `Test/SqlDom/Only170SyntaxTests.cs`): Updated to include and validate the new JSON index option. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> Related work items: #4709838 * Merged PR 1815158: Add test case for PAD_INDEX and DROP_EXISTING options for Json index # Pull Request Template for ScriptDom ## Description Please provide a detailed description, include the link to the design specification or SQL feature document for the new TSQL syntaxes. Make sure to add links to the Github or DevDiv issue Before submitting your pull request, please ensure you have completed the following: ## Code Change - [ ] The [Common checklist](https://msdata.visualstudio.com/SQLToolsAndLibraries/_git/Common?path=/Templates/PR%20Checklist%20for%20SQLToolsAndLibraries.md&version=GBmain&_a=preview) has been reviewed and followed - [ ] Code changes are accompanied by appropriate unit tests - [ ] Identified and included SMEs needed to review code changes - [ ] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=make-the-changes-in) here to make changes in the code ## Testing - [ ] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=to-extend-the-tests-do-the-following%3A) here to add new tests for your feature ## Documentation - [ ] Update relevant documentation in the [wiki](https://dev.azure.com/msdata/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki) and the README.md file ## Additional Information This PR added a test case for PAD_INDEX and DROP_EXISTING options for Json index. These options are shared options with other indexes, so only a test case is needed. ---- #### AI description (iteration 1) #### PR Classification This PR adds new test cases to validate the PAD_INDEX and DROP_EXISTING options for JSON indexes. #### PR Summary The changes extend the JSON index tests by including scenarios for the PAD_INDEX and DROP_EXISTING options. - `Test/SqlDom/TestScripts/JsonIndexTests170.sql`: Adds a JSON index creation statement with PAD_INDEX and DROP_EXISTING options. - `Test/SqlDom/Baselines170/JsonIndexTests170.sql`: Updates the baseline to include the new JSON index command with PAD_INDEX and DROP_EXISTING options. - `Test/SqlDom/Only170SyntaxTests.cs`: Adjusts the expected error counts for JSON index tests to reflect the new options. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> Related work items: #4711081 * fixing merge issues * Merged PR 1815666: Release notes for 170.121.2 # Pull Request Template for ScriptDom ## Description Please provide a detailed description, include the link to the design specification or SQL feature document for the new TSQL syntaxes. Make sure to add links to the Github or DevDiv issue Before submitting your pull request, please ensure you have completed the following: ## Code Change - [ ] The [Common checklist](https://msdata.visualstudio.com/SQLToolsAndLibraries/_git/Common?path=/Templates/PR%20Checklist%20for%20SQLToolsAndLibraries.md&version=GBmain&_a=preview) has been reviewed and followed - [ ] Code changes are accompanied by appropriate unit tests - [ ] Identified and included SMEs needed to review code changes - [ ] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=make-the-changes-in) here to make changes in the code ## Testing - [ ] Follow the [steps](https://msdata.visualstudio.com/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki/33838/Adding-or-Extending-TSql-support-in-Sql-Dom?anchor=to-extend-the-tests-do-the-following%3A) here to add new tests for your feature ## Documentation - [ ] Update relevant documentation in the [wiki](https://dev.azure.com/msdata/SQLToolsAndLibraries/_wiki/wikis/SQLToolsAndLibraries.wiki) and the README.md file ## Additional Information Please provide any additional information that might be helpful for the reviewers * replace smart apostrophe --------- Co-authored-by: Mohit Agarwal <[email protected]> Co-authored-by: Urvashi Raj <[email protected]> Co-authored-by: Zi Chen <[email protected]> Co-authored-by: Mateo Marenco <[email protected]> Co-authored-by: GitOps (Git LowPriv) <GitOps (Git LowPriv)> Co-authored-by: Sicong Liu <[email protected]> Co-authored-by: Lijun Ji <[email protected]> Co-authored-by: Drew Skwiers-Koballa <[email protected]>
1 parent 52523ab commit d90ce7d

24 files changed

+388
-52
lines changed

CONTRIBUTING.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,37 @@ Before sending a Pull Request, please do the following:
117117

118118
### Helpful notes for SQLDOM extensions
119119

120-
1. For changing the DOM classes, modify the XML file (the C# code is generated based on this during the build process) `$(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\Parser\TSql\Ast.xml`. Change Ast.xml to put the class pieces on their appropriate statements.
121-
1. The build process is defined in `$(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\SqlScriptDom.props` (Target Name="CreateAST")
122-
2. The generated files are dropped in `$(EnlistmentRoot)\obj\<x64|x86>\<Debug|Release>\SqlScriptDom.csproj\`
120+
1. For changing the DOM classes, modify the XML file (the C# code is generated based on this during the build process) `SqlScriptDom\Parser\TSql\Ast.xml`. Change Ast.xml to put the class pieces on their appropriate statements.
121+
1. The build process is defined in `SqlScriptDom\GenerateFiles.props` (Target Name="CreateAST")
122+
2. The generated files are dropped in `obj\SqlScriptDom\AnyCPU\<Debug|Release>\<TargetPlatform>\Microsoft.SqlServer.TransactSql.ScriptDom.csproj\`
123+
124+
Regenerating generated sources (what to run and when)
125+
---------------------------------------------------
126+
When you modify `Source\SqlDom\SqlScriptDom\Parser\TSql\Ast.xml` or any `TSql<#>.g` grammar file, the C# parser and DOM sources are produced by MSBuild generation targets (for example `CreateAST`). These targets are invoked automatically during a normal build, so in most cases you can simply run:
127+
128+
```powershell
129+
dotnet build Source\SqlDom\SqlScriptDom\Microsoft.SqlServer.TransactSql.ScriptDom.csproj -c Debug
130+
```
131+
132+
If you only want to run generation targets (no compile) or need more detailed generation logs, invoke the MSBuild targets directly:
133+
134+
```powershell
135+
dotnet msbuild Source\SqlDom\SqlScriptDom\Microsoft.SqlServer.TransactSql.ScriptDom.csproj -t:GLexerParserCompile;GSqlTokenTypesCompile;CreateAST -p:Configuration=Debug
136+
```
137+
138+
Generated files are written into the `obj` folder for that project (for example `obj\SqlScriptDom\AnyCPU\<Debug|Release>\<TargetPlatform>\Microsoft.SqlServer.TransactSql.ScriptDom.csproj\`). If antlr or related tools are missing, see `Directory.Build.props` for `AntlrLocation` and follow the repo guidance to supply the binaries.
123139
124140
2. For changing the parser, modify the .g file here:
125-
`$(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\Parser\TSql\TSql<#>.g` where # is the version (ie - 100, 120, 130). This will usually be the latest number if adding new grammar. Change the Tsql(xxx).g file to parse the new syntax.
126-
1. The build process is defined in `$(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\SqlScriptDom.props` (Target Name="CreateAST")
127-
2. The generated files are dropped in `$(EnlistmentRoot)\obj\x86|x64\Debug|Release\sqlscriptdom.csproj\`
141+
`SqlScriptDom\Parser\TSql\TSql<#>.g` where # is the version (ie - 100, 120, 130). This will usually be the latest number if adding new grammar. Change the Tsql(xxx).g file to parse the new syntax.
142+
1. The build process is defined in `SqlScriptDom\GenerateFiles.props` (Target Name="CreateAST")
143+
2. The generated files are dropped in `obj\SqlScriptDom\AnyCPU\<Debug|Release>\<TargetPlatform>\Microsoft.SqlServer.TransactSql.ScriptDom.csproj\`
128144
129-
3. For changing the ScriptGenerator, modify the appropriate file (i.e. Visitor that accepts the modified DOM class) in here: `$(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\ScriptDom\SqlServer\ScriptGenerator`.
130-
1. To add a new ScriptGenerator, you need to add the file to `$(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\SqlScriptDom.props`
145+
3. For changing the ScriptGenerator, modify the appropriate file (i.e. Visitor that accepts the modified DOM class) in here: `SqlScriptDom\ScriptDom\SqlServer\ScriptGenerator`.
131146
1. Change The visitors SqlScriptGenerator.X to use the new piece from AST.XML
132147
1. If you're adding syntax that's Azure-only or Standalone-only, implement appropriate Versioning Visitor for your constructs.
133148
134-
4. When adding/removing new files please add/remove an entry to/from `$(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\SqlScriptDom.csproj`
135149
136-
5. To extend the tests do the following:
150+
4. To extend the tests do the following:
137151
1. Baselines# needs to be updated or added with the appropriate .sql file as expected results.
138152
1. The Only#SyntaxTests.cs needs to be extended or added to specify the appropriate TestScripts script.
139153
1. Positive tests go in Only#SyntaxTests.cs if adding new grammar.

SqlScriptDom/Parser/TSql/Ast.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@
271271
Summary="The xml data type option."/>
272272
<Member Name="XmlSchemaCollection" Type="SchemaObjectName" Summary="The xml schema collection. Optional may be null."/>
273273
</Class>
274+
<Class Name="VectorDataTypeReference" Base="DataTypeReference" Summary="Represents vector data types">
275+
<InheritedClass Name="DataTypeReference" />
276+
<Member Name="Dimension" Type="IntegerLiteral" Summary="The dimension of the vector."/>
277+
<Member Name="BaseType" Type="Identifier" Summary="Type of dimension values."/>
278+
</Class>
274279
<Class Name="ScalarFunctionReturnType" Base="FunctionReturnType" Summary="The return type definition for scalar-valued functions">
275280
<Member Name="DataType" Type="DataTypeReference" Summary="The data type of the return."/>
276281
</Class>
@@ -2520,6 +2525,10 @@
25202525
<InheritedClass Name="DatabaseOption" />
25212526
<Member Name="OptionState" Type="OptionState" GenerateUpdatePositionInfoCall="false" Summary="Option state."/>
25222527
</Class>
2528+
<Class Name="OptimizedLockingDatabaseOption" Base="DatabaseOption" Summary="OPTIMIZED_LOCKING option in ALTER DATABASE statement, SET case">
2529+
<InheritedClass Name="DatabaseOption" />
2530+
<Member Name="OptionState" Type="OptionState" GenerateUpdatePositionInfoCall="false" Summary="Option state."/>
2531+
</Class>
25232532
<Class Name="QueryStoreDatabaseOption" Base="DatabaseOption" Summary="Query Store (QDS) option in ALTER DATABASE statement, SET case">
25242533
<InheritedClass Name="DatabaseOption" />
25252534
<Member Name="Clear" Type="bool" Summary="True if Clear QDS option was specified"/>

SqlScriptDom/Parser/TSql/CodeGenerationSupporter.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ internal static class CodeGenerationSupporter
427427
internal const string FlushIntervalSecondsAlt = "DATA_FLUSH_INTERVAL_SECONDS";
428428
internal const string Fn = "FN";
429429
internal const string Float = "FLOAT";
430+
internal const string Float16 = "FLOAT16";
431+
internal const string Float32 = "FLOAT32";
430432
internal const string For = "FOR";
431433
internal const string ForceFailoverAllowDataLoss = "FORCE_FAILOVER_ALLOW_DATA_LOSS";
432434
internal const string ForceScan = "FORCESCAN";
@@ -718,6 +720,8 @@ internal static class CodeGenerationSupporter
718720
internal const string OperatorAudit = "OPERATOR_AUDIT";
719721
internal const string Optimistic = "OPTIMISTIC";
720722
internal const string Optimize = "OPTIMIZE";
723+
internal const string OptimizedLocking = "OPTIMIZED_LOCKING";
724+
internal const string OptimizeForArraySearch = "OPTIMIZE_FOR_ARRAY_SEARCH";
721725
internal const string OptimizeForSequentialKey = "OPTIMIZE_FOR_SEQUENTIAL_KEY";
722726
internal const string OptimizerQueue = "OPTIMIZER_QUEUE";
723727
internal const string Order = "ORDER";

SqlScriptDom/Parser/TSql/DatabaseOptionKind.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ public enum DatabaseOptionKind
9898
Ledger = 68,
9999

100100
ManualCutover = 69,
101-
PerformCutover = 70
101+
PerformCutover = 70,
102+
OptimizedLocking = 71
102103
}
103104

104105
#pragma warning restore 1591

SqlScriptDom/Parser/TSql/IndexOptionHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ private IndexOptionHelper()
4646
AddOptionMapping(IndexOptionKind.VectorMetric, CodeGenerationSupporter.Metric, SqlVersionFlags.TSql170AndAbove);
4747
AddOptionMapping(IndexOptionKind.VectorType, CodeGenerationSupporter.Type, SqlVersionFlags.TSql170AndAbove);
4848

49+
AddOptionMapping(IndexOptionKind.OptimizeForArraySearch, CodeGenerationSupporter.OptimizeForArraySearch, SqlVersionFlags.TSql170AndAbove);
50+
4951
}
5052

5153
internal static readonly IndexOptionHelper Instance = new IndexOptionHelper();

SqlScriptDom/Parser/TSql/IndexOptionKind.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public enum IndexOptionKind
4040
XmlCompression = 23,
4141
VectorMetric = 24,
4242
VectorType = 25,
43+
OptimizeForArraySearch = 26,
4344
}
4445

4546
#pragma warning restore 1591

SqlScriptDom/Parser/TSql/TSql170.g

Lines changed: 146 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3064,17 +3064,14 @@ alterDbModify returns [AlterDatabaseStatement vResult = null]
30643064
;
30653065

30663066
alterDbModifyAzureOptions returns [AlterDatabaseSetStatement vResult = FragmentFactory.CreateFragment<AlterDatabaseSetStatement>()]
3067-
{
3068-
bool hasManualCutover = false;
3069-
}
30703067
:
30713068
azureOptions[vResult, vResult.Options]
30723069
(
30733070
With tManualCutover:Identifier
30743071
{
30753072
Match(tManualCutover, CodeGenerationSupporter.ManualCutover);
3076-
hasManualCutover = true;
30773073
vResult.WithManualCutover = true;
3074+
UpdateTokenInfo(vResult, tManualCutover);
30783075
}
30793076
)?
30803077
;
@@ -3247,6 +3244,8 @@ dbOptionStateItem[ref ulong encounteredOptions] returns [DatabaseOption vResult
32473244
vResult = changeTrackingDbOption
32483245
| {NextTokenMatches(CodeGenerationSupporter.AcceleratedDatabaseRecovery)}?
32493246
vResult = acceleratedDatabaseRecoveryOption
3247+
| {NextTokenMatches(CodeGenerationSupporter.OptimizedLocking)}?
3248+
vResult = optimizedLockingOption
32503249
| {NextTokenMatches(CodeGenerationSupporter.Containment)}?
32513250
vResult = dbContainmentOption
32523251
| {NextTokenMatches(CodeGenerationSupporter.Hadr)}?
@@ -3560,6 +3559,30 @@ acceleratedDatabaseRecoveryOption returns [AcceleratedDatabaseRecoveryDatabaseOp
35603559
)
35613560
;
35623561

3562+
optimizedLockingOption returns [OptimizedLockingDatabaseOption vResult = FragmentFactory.CreateFragment<OptimizedLockingDatabaseOption>()]
3563+
: tOptimizedLocking:Identifier
3564+
{
3565+
Match(tOptimizedLocking, CodeGenerationSupporter.OptimizedLocking);
3566+
vResult.OptionKind = DatabaseOptionKind.OptimizedLocking;
3567+
UpdateTokenInfo(vResult, tOptimizedLocking);
3568+
}
3569+
(
3570+
(EqualsSign tOff:Off
3571+
{
3572+
vResult.OptionState = OptionState.Off;
3573+
UpdateTokenInfo(vResult, tOff);
3574+
}
3575+
)
3576+
|
3577+
(EqualsSign tOn:On
3578+
{
3579+
vResult.OptionState = OptionState.On;
3580+
UpdateTokenInfo(vResult, tOn);
3581+
}
3582+
)
3583+
)
3584+
;
3585+
35633586
changeTrackingOnOptions [ChangeTrackingDatabaseOption vParent]
35643587
{
35653588
bool autoCleanupEncountered = false;
@@ -23930,7 +23953,6 @@ dropSecurityPolicyStatement returns [DropSecurityPolicyStatement vResult = Fragm
2393023953
createExternalModelStatement returns [CreateExternalModelStatement vResult = FragmentFactory.CreateFragment<CreateExternalModelStatement>()]
2393123954
{
2393223955
Identifier vName;
23933-
long encounteredOptions = 0;
2393423956
}
2393523957
: tModel:Identifier vName = identifier
2393623958
{
@@ -24092,7 +24114,6 @@ externalModelParameters[ExternalModelStatement vParent]
2409224114
alterExternalModelStatement returns [AlterExternalModelStatement vResult = FragmentFactory.CreateFragment<AlterExternalModelStatement>()]
2409324115
{
2409424116
Identifier vName;
24095-
long encounteredOptions = 0;
2409624117
}
2409724118
: tModel:Identifier vName = identifier
2409824119
{
@@ -30680,6 +30701,32 @@ xmlDataType [SchemaObjectName vName] returns [XmlDataTypeReference vResult = Fra
3068030701
)?
3068130702
;
3068230703

30704+
vectorDataType [SchemaObjectName vName] returns [VectorDataTypeReference vResult = FragmentFactory.CreateFragment<VectorDataTypeReference>()]
30705+
{
30706+
vResult.Name = vName;
30707+
vResult.UpdateTokenInfo(vName);
30708+
30709+
IntegerLiteral vDimension = null;
30710+
Identifier vBaseType = null;
30711+
}
30712+
:
30713+
( LeftParenthesis vDimension=integer
30714+
{
30715+
vResult.Dimension = vDimension;
30716+
}
30717+
(
30718+
Comma vBaseType=identifier
30719+
{
30720+
vResult.BaseType = vBaseType;
30721+
}
30722+
)?
30723+
tRParen:RightParenthesis
30724+
{
30725+
UpdateTokenInfo(vResult,tRParen);
30726+
}
30727+
)
30728+
;
30729+
3068330730
scalarDataType returns [DataTypeReference vResult = null]
3068430731
{
3068530732
SchemaObjectName vName;
@@ -30700,6 +30747,9 @@ scalarDataType returns [DataTypeReference vResult = null]
3070030747
(
3070130748
{isXmlDataType}?
3070230749
vResult = xmlDataType[vName]
30750+
|
30751+
{typeOption == SqlDataTypeOption.Vector}?
30752+
vResult = vectorDataType[vName]
3070330753
|
3070430754
{typeOption != SqlDataTypeOption.None}?
3070530755
vResult = sqlDataTypeWithoutNational[vName, typeOption]
@@ -32103,6 +32153,7 @@ aiGenerateEmbeddingsFunctionCall
3210332153
ScalarExpression vInput;
3210432154
SchemaObjectName vModelName;
3210532155
ScalarExpression vParams = null;
32156+
ScalarExpression vParamsInner;
3210632157
}
3210732158
:
3210832159
tFunc:Identifier LeftParenthesis
@@ -32114,30 +32165,105 @@ aiGenerateEmbeddingsFunctionCall
3211432165
{
3211532166
vResult.Input = vInput;
3211632167
}
32117-
32118-
tUse:Use // your reserved keyword
32168+
tUse:Use
3211932169
{
3212032170
UpdateTokenInfo(vResult, tUse);
3212132171
}
3212232172

3212332173
tModel:Identifier
3212432174
{
3212532175
Match(tModel, CodeGenerationSupporter.Model);
32126-
}
32127-
32128-
vModelName=schemaObjectThreePartName
32129-
{
32130-
vResult.ModelName = vModelName;
32131-
}
32132-
32133-
(
32134-
tParams:Identifier
32176+
UpdateTokenInfo(vResult, tModel);
32177+
}
32178+
32179+
// --- MODEL NAME: single-part only (strict) ---------------------------------------------
32180+
// We accept exactly **one identifier token** after "USE MODEL".
32181+
//
32182+
// Why:
32183+
// - Users may store model names that *visually* contain dots or spaces, e.g. [dbo.MyDefaultModel].
32184+
// When bracket-delimited, the lexer emits this as a **single** token (QuotedIdentifier), so it's OK.
32185+
// - True multipart names (db.schema.model) must be rejected here, so we do NOT consume any Dot tokens.
32186+
//
32187+
// Allowed (single token):
32188+
// USE MODEL MyDefaultModel -- Identifier
32189+
// USE MODEL [dbo.MyDefaultModel] -- QuotedIdentifier (one token; dot lives inside the brackets)
32190+
//
32191+
// Rejected (multipart):
32192+
// USE MODEL dbo.MyDefaultModel -- Identifier '.' Identifier (two tokens + Dot)
32193+
// USE MODEL [dbo].[MyDefaultModel] -- QuotedIdentifier '.' QuotedIdentifier
32194+
//
32195+
// Token notes:
32196+
// - Identifier : unquoted identifier; cannot contain spaces or '.'.
32197+
// - QuotedIdentifier : bracket-delimited; may contain spaces and '.' inside the brackets.
32198+
(
32199+
vModelId:Identifier
32200+
{
32201+
vModelName = this.FragmentFactory.CreateFragment<SchemaObjectName>();
32202+
vModelName.Identifiers.Add(this.CreateIdentifierFromToken(vModelId));
32203+
vResult.ModelName = vModelName;
32204+
}
32205+
|
32206+
vModelQId:QuotedIdentifier
3213532207
{
32136-
Match(tParams, CodeGenerationSupporter.Parameters);
32208+
vModelName = this.FragmentFactory.CreateFragment<SchemaObjectName>();
32209+
vModelName.Identifiers.Add(this.CreateIdentifierFromToken(vModelQId));
32210+
vResult.ModelName = vModelName;
3213732211
}
32138-
LeftParenthesis
32212+
)
32213+
32214+
// --- Optional PARAMETERS clause ---------------------------------------------------------
32215+
// Shape: [PARAMETERS (<expr>)] | [PARAMETERS <expr-not-string>]
32216+
// Goals:
32217+
// 1) Accept a general **expression** as the PARAMETERS value.
32218+
// 2) Preserve user-written parentheses by constructing a ParenthesisExpression node
32219+
// for the "( <expr> )" variant so pretty-printing round-trips exactly.
32220+
// 3) **Reject** a bare JSON string literal (e.g., PARAMETERS '{...}'); callers must pass
32221+
// a parsed JSON expression (e.g., TRY_CONVERT(JSON, N'{}')).
32222+
// Notes:
32223+
// - Some builds tokenize PARAMETERS as a keyword; others as an Identifier. Support both.
32224+
(
32225+
(
32226+
// PARAMETERS as a true keyword token.
32227+
tParamsKw:Parameters
32228+
{
32229+
UpdateTokenInfo(vResult, tParamsKw);
32230+
}
32231+
|
32232+
// PARAMETERS as an identifier token; enforce its text equals "Parameters".
32233+
tParams:Identifier
32234+
{
32235+
Match(tParams, CodeGenerationSupporter.Parameters);
32236+
UpdateTokenInfo(vResult, tParams);
32237+
}
32238+
)
32239+
32240+
// ---- Value of PARAMETERS -----------------------------------------------------------
32241+
(
32242+
// Variant A: user wrote parentheses around the value: PARAMETERS ( <expr> )
32243+
// Build a ParenthesisExpression so the printer re-emits parens.
32244+
tLP:LeftParenthesis
32245+
vParamsInner=expression
32246+
tRP:RightParenthesis
32247+
{
32248+
ParenthesisExpression p = this.FragmentFactory.CreateFragment<ParenthesisExpression>();
32249+
p.Expression = vParamsInner;
32250+
vParams = p;
32251+
32252+
// Attach LP/RP token info for accurate script generation.
32253+
UpdateTokenInfo(p, tLP);
32254+
UpdateTokenInfo(p, tRP);
32255+
}
32256+
|
32257+
// Variant B: bare expression without surrounding parentheses.
32258+
// Guardrail: Disallow a leading string literal so that
32259+
// PARAMETERS '{"dimensions":768}'
32260+
// is a **syntax error**, while
32261+
// PARAMETERS TRY_CONVERT(JSON, N'{}')
32262+
// is allowed.
32263+
// LA(1) is the next token type; block both ASCII ('...') and Unicode (N'...') strings.
32264+
{ LA(1) != AsciiStringLiteral && LA(1) != UnicodeStringLiteral }?
3213932265
vParams=expression
32140-
RightParenthesis
32266+
)
3214132267
{
3214232268
vResult.OptionalParameters = vParams;
3214332269
}

0 commit comments

Comments
 (0)