-
Notifications
You must be signed in to change notification settings - Fork 35
Add support for Vector index syntax in T-SQL parser with separate index option classes #150
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
43a5080
Initial plan
Copilot 8d6642a
Implement vector index support - add grammar, AST classes, and script…
Copilot 97a1590
Consolidate vector index options and remove duplicate Vector constant
Copilot 0c53470
Revert to original design with separate VectorMetricIndexOption and V…
Copilot 3c46555
fixing the parser
llali df44c72
Update vector index option values to uppercase in baseline test file
Copilot e0432d2
Add comprehensive vector index error test cases to ParserErrorsTests
Copilot 849df29
Remove invalid negative test case for vector index - CREATE INDEX syn…
Copilot ab0b17b
fixing the test
llali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| //------------------------------------------------------------------------------ | ||
| // <copyright file="VectorIndexType.cs" company="Microsoft"> | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // </copyright> | ||
| //------------------------------------------------------------------------------ | ||
|
|
||
|
|
||
|
|
||
| namespace Microsoft.SqlServer.TransactSql.ScriptDom | ||
| { | ||
| #pragma warning disable 1591 | ||
|
|
||
| /// <summary> | ||
| /// The possible values for vector index type | ||
| /// </summary> | ||
| public enum VectorIndexType | ||
| { | ||
| DiskANN = 0 | ||
| } | ||
|
|
||
| #pragma warning restore 1591 | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| //------------------------------------------------------------------------------ | ||
| // <copyright file="VectorIndexTypeHelper.cs" company="Microsoft"> | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // </copyright> | ||
| //------------------------------------------------------------------------------ | ||
|
|
||
|
|
||
|
|
||
| namespace Microsoft.SqlServer.TransactSql.ScriptDom | ||
| { | ||
|
|
||
| internal class VectorIndexTypeHelper : OptionsHelper<VectorIndexType> | ||
| { | ||
| private VectorIndexTypeHelper() | ||
| { | ||
| AddOptionMapping(VectorIndexType.DiskANN, "'" + CodeGenerationSupporter.DiskANN + "'"); | ||
| } | ||
|
|
||
| public static readonly VectorIndexTypeHelper Instance = new VectorIndexTypeHelper(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| //------------------------------------------------------------------------------ | ||
| // <copyright file="VectorMetricType.cs" company="Microsoft"> | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // </copyright> | ||
| //------------------------------------------------------------------------------ | ||
|
|
||
|
|
||
|
|
||
| namespace Microsoft.SqlServer.TransactSql.ScriptDom | ||
| { | ||
| #pragma warning disable 1591 | ||
|
|
||
| /// <summary> | ||
| /// The possible values for vector index metric | ||
| /// </summary> | ||
| public enum VectorMetricType | ||
| { | ||
| Cosine = 0, | ||
| Dot = 1, | ||
| Euclidean = 2 | ||
| } | ||
|
|
||
| #pragma warning restore 1591 | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| //------------------------------------------------------------------------------ | ||
| // <copyright file="VectorMetricTypeHelper.cs" company="Microsoft"> | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // </copyright> | ||
| //------------------------------------------------------------------------------ | ||
|
|
||
|
|
||
|
|
||
| using static Microsoft.SqlServer.TransactSql.ScriptDom.SensitivityClassification; | ||
|
|
||
| namespace Microsoft.SqlServer.TransactSql.ScriptDom | ||
| { | ||
|
|
||
| internal class VectorMetricTypeHelper : OptionsHelper<VectorMetricType> | ||
| { | ||
| private VectorMetricTypeHelper() | ||
| { | ||
| AddOptionMapping(VectorMetricType.Cosine, "'" + CodeGenerationSupporter.Cosine + "'"); | ||
| AddOptionMapping(VectorMetricType.Dot, "'" + CodeGenerationSupporter.Dot + "'"); | ||
| AddOptionMapping(VectorMetricType.Euclidean, "'" + CodeGenerationSupporter.Euclidean + "'"); | ||
| } | ||
|
|
||
| public static readonly VectorMetricTypeHelper Instance = new VectorMetricTypeHelper(); | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
...riptDom/SqlServer/ScriptGenerator/SqlScriptGeneratorVisitor.CreateVectorIndexStatement.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| //------------------------------------------------------------------------------ | ||
| // <copyright file="SqlScriptGeneratorVisitor.CreateVectorIndexStatement.cs" company="Microsoft"> | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // </copyright> | ||
| //------------------------------------------------------------------------------ | ||
| using System.Collections.Generic; | ||
| using Microsoft.SqlServer.TransactSql.ScriptDom; | ||
|
|
||
| namespace Microsoft.SqlServer.TransactSql.ScriptDom.ScriptGenerator | ||
| { | ||
| partial class SqlScriptGeneratorVisitor | ||
| { | ||
| public override void ExplicitVisit(CreateVectorIndexStatement node) | ||
| { | ||
| GenerateKeyword(TSqlTokenType.Create); | ||
|
|
||
| GenerateSpaceAndIdentifier(CodeGenerationSupporter.Vector); | ||
|
|
||
| GenerateSpaceAndKeyword(TSqlTokenType.Index); | ||
|
|
||
| // name | ||
| GenerateSpaceAndFragmentIfNotNull(node.Name); | ||
|
|
||
| NewLineAndIndent(); | ||
| GenerateKeyword(TSqlTokenType.On); | ||
| GenerateSpaceAndFragmentIfNotNull(node.OnName); | ||
|
|
||
| // Vector column | ||
| if (node.VectorColumn != null) | ||
| { | ||
| GenerateSpace(); | ||
| GenerateSymbol(TSqlTokenType.LeftParenthesis); | ||
| GenerateFragmentIfNotNull(node.VectorColumn); | ||
| GenerateSymbol(TSqlTokenType.RightParenthesis); | ||
| } | ||
|
|
||
| GenerateIndexOptions(node.IndexOptions); | ||
|
|
||
| if (node.OnFileGroupOrPartitionScheme != null) | ||
| { | ||
| NewLineAndIndent(); | ||
| GenerateKeyword(TSqlTokenType.On); | ||
|
|
||
| GenerateSpaceAndFragmentIfNotNull(node.OnFileGroupOrPartitionScheme); | ||
| } | ||
| } | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
.../ScriptDom/SqlServer/ScriptGenerator/SqlScriptGeneratorVisitor.VectorMetricIndexOption.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| //------------------------------------------------------------------------------ | ||
| // <copyright file="SqlScriptGeneratorVisitor.VectorMetricIndexOption.cs" company="Microsoft"> | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // </copyright> | ||
| //------------------------------------------------------------------------------ | ||
|
|
||
| namespace Microsoft.SqlServer.TransactSql.ScriptDom.ScriptGenerator | ||
| { | ||
| partial class SqlScriptGeneratorVisitor | ||
| { | ||
| public override void ExplicitVisit(VectorMetricIndexOption node) | ||
| { | ||
| IndexOptionHelper.Instance.GenerateSourceForOption(_writer, node.OptionKind); | ||
| GenerateSpaceAndSymbol(TSqlTokenType.EqualsSign); | ||
| GenerateSpace(); | ||
| VectorMetricTypeHelper.Instance.GenerateSourceForOption(_writer, node.MetricType); | ||
| } | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
...om/ScriptDom/SqlServer/ScriptGenerator/SqlScriptGeneratorVisitor.VectorTypeIndexOption.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| //------------------------------------------------------------------------------ | ||
| // <copyright file="SqlScriptGeneratorVisitor.VectorTypeIndexOption.cs" company="Microsoft"> | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // </copyright> | ||
| //------------------------------------------------------------------------------ | ||
|
|
||
| namespace Microsoft.SqlServer.TransactSql.ScriptDom.ScriptGenerator | ||
| { | ||
| partial class SqlScriptGeneratorVisitor | ||
| { | ||
| public override void ExplicitVisit(VectorTypeIndexOption node) | ||
| { | ||
| IndexOptionHelper.Instance.GenerateSourceForOption(_writer, node.OptionKind); | ||
| GenerateSpaceAndSymbol(TSqlTokenType.EqualsSign); | ||
| GenerateSpace(); | ||
| VectorIndexTypeHelper.Instance.GenerateSourceForOption(_writer, node.VectorType); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create one VectorIndexOption class that includes both MetricType and VectorType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 97a1590. Consolidated VectorMetricIndexOption and VectorTypeIndexOption into a single VectorIndexOption class that includes both MetricType and VectorType properties, along with updated grammar and script generator.