Skip to content

Conversation

@llali
Copy link
Member

@llali llali commented Jan 23, 2026

Description

Sync repos for release 170.157.0

llali and others added 3 commits January 23, 2026 09:10
Parser would timeout or crash when parsing queries with VECTOR data types in deeply nested JOIN structures due to exponential complexity (O(2^n)) in ANTLR's syntactic predicate lookahead.

The `selectTableReferenceElement` grammar rule uses recursive syntactic predicates that cause exponential backtracking when VECTOR types appear in complex join hierarchies. Each additional nesting level doubles the parsing attempts.

Implemented conditional optimization using `ContainsVectorInLookahead()` helper method:
- Scans ahead up to 200 tokens to detect VECTOR keyword
- When VECTOR detected: applies `SaveGuessing` optimization to reduce complexity from O(2^n) to O(n²)
- When no VECTOR: uses standard grammar path with minimal overhead (~1-2ms)

- **TSql170.g**: Modified `selectTableReferenceElement` rule with conditional SaveGuessing
- **TSql170ParserBaseInternal.cs**: Added `ContainsVectorInLookahead()` helper method
- **ComplexQueryTests170.sql**: Added comprehensive test coverage (6 queries)
  - 5 VECTOR scenarios: CAST, CONVERT, deeply nested JOINs with VECTOR types
  - 1 non-VECTOR scenario: Complex 6-way nested JOIN to validate no regression

- All 1,122 tests passing (0 failures)
- VECTOR queries: Previously timeout/crash → now parse successfully
- Non-VECTOR queries: No measurable performance impact
- Cross-version validation: Appropriate error counts for TSql80-160

- **Overhead**: O(1) per table reference (200-token scan)
- **Typical queries**: <2ms additional overhead
- **VECTOR queries**: Massive improvement (timeout → completes)
- **Verdict**: Acceptable tradeoff for critical fix

Related work items: #4819213
…functions

This PR adds support for Fabric DW specific AI functions:
- `ai_analyze_sentiment(<input>)`
- `ai_classify(<input>, <class1>, <class2>[, <class 3>, ...])`
- `ai_extract(<input>, <label1>[, <label2>, ...])`
- `ai_fix_grammar(<input>)`
- `ai_generate_response(<promptPart1>[, <promptPart2>])`
- `ai_summarize(<input>)`
- `ai_translate(<input>, <lang>)`

Detailed design document is here: https://microsoft.sharepoint.com/:w:/r/teams/AzurePolaris/_layouts/15/doc2.aspx?sourcedoc=%7B75BAC667-A870-4482-8A37-F80E6EC8FCE0%7D&file=AI%20and%20Extensibiliy.docx

Before submitting your pull request, please ensure you have completed the following:

- [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

----
New feature: Adding support for Fabric DW–specific AI built-in functions.

This pull request extends the SQL parser for Fabric DW by introducing new AI functions and their corresponding AST representations, script generators, and tests. Key changes include:
- **`TSqlFabricDW.g`**: Added grammar rules for AI functions (e.g., AI_ANALYZE_SENTIMENT, AI_CLASSIFY, AI_EXTRACT, AI_GENERATE_RESPONSE, AI_SUMMARIZE, AI_TRANSLATE).
- **`Ast.xml`**: Introduced new AST classes to represent the AI function calls.
- **Script Generator Files**: Created new files in `SqlScriptDom/ScriptDom/SqlServer/ScriptGenerator/` to define visitors for the AI functions.
- **`CodeGenerationSupporter.cs`**: Added new constants to support the AI function tokens.
- **Test Files**: Included multiple test scripts and negative tests under `/Test/SqlDom/` to validate the syntax and error handling for the newly added functions.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->

Related work items: #4924682
…esis.

# Pull Request Template for ScriptDom
## Description
Fixes: #28
The TSql160Parser.ParseExpression() was failing to parse valid T-SQL expressions where IIF with boolean operators was wrapped in parentheses:

```sql
SELECT 1 WHERE (IIF(1 > 0 AND 2 > 1, 1, 0)) = 1
```

Customers reported this issue when using IIF expressions with multiple boolean operators (AND, OR, >, <, etc.) wrapped in parentheses.

The original code used a simple counter (insideIIf) to track when inside an IIF call. The counter was decremented on the first boolean operator inside the IIF (e.g., >). When a second operator like AND was encountered, insideIIf was already 0, causing it to be misidentified as a top-level boolean operator - which incorrectly signaled that the outer parentheses contained a boolean expression instead of a scalar expression.

Replaced the simple counter with stack-based parenthesis depth tracking.
This properly tracks when we're inside an IIF by remembering the parenthesis depth where each IIF started, rather than incorrectly decrementing on boolean operators. This also correctly handles:

Nested IIF expressions: `(IIF(IIF(a > 1, b, c) > 2, 1, 0))`
Deeply nested parentheses: `((((IIF(1 > 0 AND 2 > 1, 1, 0)))) = 1`
Multiple IIF expressions: `(IIF(...)) = 1 AND (IIF(...)) = 1`

## 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

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix to correct the parsing of IIF expressions when they occur inside parentheses.

#### PR Summary
This pull request fixes the incorrect handling of nested IIF expressions by replacing a simple counter with a stack-based approach and a pending flag, ensuring accurate tracking of IIF parentheses. The update enhances the SQL parser and adds regression tests to validate various scenarios.
- `SqlScriptDom/Parser/TSql/TSql80ParserBaseInternal.cs`: Refactor...
# Pull Request Template for ScriptDom
## Description
Adding release notes for 170.157.0

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

Adding release notes for 170.157.0

----
#### AI description  (iteration 1)
#### PR Classification
Documentation update providing the release notes for version 170.157.0.

#### PR Summary
This pull request adds a new release notes file for Microsoft.SqlServer.TransactSql.ScriptDom 170.157.0, detailing supported platforms, dependency updates, new AI function support, and fixes for specific issues.
- `release-notes/170/170.157.0.md`: New file containing the release information including target platform support, updated .NET SDK dependency (8.0.415), addition of Fabric DW-specific AI functions, and fixes for issues #161 and #28.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
@llali llali merged commit c152271 into main Jan 23, 2026
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.

3 participants