Skip to content

Commit e0432d2

Browse files
Copilotzijchen
andcommitted
Add comprehensive vector index error test cases to ParserErrorsTests
Co-authored-by: zijchen <13544267+zijchen@users.noreply.github.com>
1 parent df44c72 commit e0432d2

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

Test/SqlDom/ParserErrorsTests.cs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6950,5 +6950,98 @@ Description NVARCHAR(200)
69506950
";
69516951
ParserTestUtils.ErrorTestFabricDW(identityColumnSyntax2, new ParserErrorInfo(identityColumnSyntax2.IndexOf("IDENTITY(") + 8, "SQL46010", "("));
69526952
}
6953+
6954+
/// <summary>
6955+
/// Negative tests for VECTOR INDEX syntax
6956+
/// </summary>
6957+
[TestMethod]
6958+
[Priority(0)]
6959+
[SqlStudioTestCategory(Category.UnitTest)]
6960+
public void VectorIndexNegativeTests()
6961+
{
6962+
// Missing VECTOR keyword
6963+
ParserTestUtils.ErrorTest170("CREATE INDEX IX_Test ON dbo.Documents (VectorData)",
6964+
new ParserErrorInfo(7, "SQL46010", "INDEX"));
6965+
6966+
// Missing INDEX keyword
6967+
ParserTestUtils.ErrorTest170("CREATE VECTOR IX_Test ON dbo.Documents (VectorData)",
6968+
new ParserErrorInfo(14, "SQL46010", "IX_Test"));
6969+
6970+
// Missing table name
6971+
ParserTestUtils.ErrorTest170("CREATE VECTOR INDEX IX_Test ON (VectorData)",
6972+
new ParserErrorInfo(35, "SQL46010", "("));
6973+
6974+
// Missing column specification
6975+
ParserTestUtils.ErrorTest170("CREATE VECTOR INDEX IX_Test ON dbo.Documents",
6976+
new ParserErrorInfo(45, "SQL46029", ""));
6977+
6978+
// Empty column list
6979+
ParserTestUtils.ErrorTest170("CREATE VECTOR INDEX IX_Test ON dbo.Documents ()",
6980+
new ParserErrorInfo(46, "SQL46010", ")"));
6981+
6982+
// Multiple columns (not supported for vector indexes)
6983+
ParserTestUtils.ErrorTest170("CREATE VECTOR INDEX IX_Test ON dbo.Documents (VectorData, OtherColumn)",
6984+
new ParserErrorInfo(57, "SQL46010", ","));
6985+
6986+
// Invalid metric value
6987+
ParserTestUtils.ErrorTest170("CREATE VECTOR INDEX IX_Test ON dbo.Documents (VectorData) WITH (METRIC = 'invalid')",
6988+
new ParserErrorInfo(76, "SQL46010", "'invalid'"));
6989+
6990+
// Invalid type value
6991+
ParserTestUtils.ErrorTest170("CREATE VECTOR INDEX IX_Test ON dbo.Documents (VectorData) WITH (TYPE = 'invalid')",
6992+
new ParserErrorInfo(74, "SQL46010", "'invalid'"));
6993+
6994+
// Missing option value
6995+
ParserTestUtils.ErrorTest170("CREATE VECTOR INDEX IX_Test ON dbo.Documents (VectorData) WITH (METRIC = )",
6996+
new ParserErrorInfo(76, "SQL46010", ")"));
6997+
6998+
// Empty option value
6999+
ParserTestUtils.ErrorTest170("CREATE VECTOR INDEX IX_Test ON dbo.Documents (VectorData) WITH (METRIC = '')",
7000+
new ParserErrorInfo(76, "SQL46063", "METRIC"));
7001+
7002+
// Duplicate METRIC options
7003+
ParserTestUtils.ErrorTest170("CREATE VECTOR INDEX IX_Test ON dbo.Documents (VectorData) WITH (METRIC = 'cosine', METRIC = 'dot')",
7004+
new ParserErrorInfo(80, "SQL46049", "METRIC"));
7005+
7006+
// Duplicate TYPE options
7007+
ParserTestUtils.ErrorTest170("CREATE VECTOR INDEX IX_Test ON dbo.Documents (VectorData) WITH (TYPE = 'DiskANN', TYPE = 'DiskANN')",
7008+
new ParserErrorInfo(78, "SQL46049", "TYPE"));
7009+
7010+
// Missing WITH keyword when options are present
7011+
ParserTestUtils.ErrorTest170("CREATE VECTOR INDEX IX_Test ON dbo.Documents (VectorData) (METRIC = 'cosine')",
7012+
new ParserErrorInfo(63, "SQL46010", "("));
7013+
7014+
// Missing parentheses around options
7015+
ParserTestUtils.ErrorTest170("CREATE VECTOR INDEX IX_Test ON dbo.Documents (VectorData) WITH METRIC = 'cosine'",
7016+
new ParserErrorInfo(68, "SQL46010", "METRIC"));
7017+
7018+
// Invalid option name
7019+
ParserTestUtils.ErrorTest170("CREATE VECTOR INDEX IX_Test ON dbo.Documents (VectorData) WITH (INVALID_OPTION = 'value')",
7020+
new ParserErrorInfo(68, "SQL46010", "INVALID_OPTION"));
7021+
7022+
// Metric value without quotes
7023+
ParserTestUtils.ErrorTest170("CREATE VECTOR INDEX IX_Test ON dbo.Documents (VectorData) WITH (METRIC = cosine)",
7024+
new ParserErrorInfo(76, "SQL46010", "cosine"));
7025+
7026+
// Type value without quotes
7027+
ParserTestUtils.ErrorTest170("CREATE VECTOR INDEX IX_Test ON dbo.Documents (VectorData) WITH (TYPE = DiskANN)",
7028+
new ParserErrorInfo(74, "SQL46010", "DiskANN"));
7029+
7030+
// MAXDOP with invalid value
7031+
ParserTestUtils.ErrorTest170("CREATE VECTOR INDEX IX_Test ON dbo.Documents (VectorData) WITH (MAXDOP = 'invalid')",
7032+
new ParserErrorInfo(76, "SQL46010", "'invalid'"));
7033+
7034+
// MAXDOP with negative value
7035+
ParserTestUtils.ErrorTest170("CREATE VECTOR INDEX IX_Test ON dbo.Documents (VectorData) WITH (MAXDOP = -1)",
7036+
new ParserErrorInfo(76, "SQL46010", "-"));
7037+
7038+
// Missing equals sign in option
7039+
ParserTestUtils.ErrorTest170("CREATE VECTOR INDEX IX_Test ON dbo.Documents (VectorData) WITH (METRIC 'cosine')",
7040+
new ParserErrorInfo(74, "SQL46010", "'cosine'"));
7041+
7042+
// Incomplete WITH clause
7043+
ParserTestUtils.ErrorTest170("CREATE VECTOR INDEX IX_Test ON dbo.Documents (VectorData) WITH",
7044+
new ParserErrorInfo(63, "SQL46029", "WITH"));
7045+
}
69537046
}
69547047
}

0 commit comments

Comments
 (0)