Skip to content

Commit 003271e

Browse files
zijchenmohitagarwal-sqlMay WenDhruv Relwani
authored
Sync repos: Release 170.64.0 (#141)
* Merged PR 1696252: Changes to support Manual-cutover and Perform-cutover in ScriptDOM ## Description The changes are done to support new parameters in TSQL ALTER DATABASE command to add new parameters MANUAL_CUTOVER and PERFORM_CUTOVER. **Functional spec** of feature FMv2: https://microsoft-my.sharepoint-df.com/:w:/p/blakhani/ERKCMOUx59ZIjfSJ_eIyLfQB--YQbcRDPoSNiiUtWvS1bg?e=vWg0vP **Design doc** of feature FMv2: https://microsoft.sharepoint.com/:w:/t/sqlstormr/Eb0o3p3MNB1CmdS7NByqHkQB11bGrU9PNVg5GE98Z6yhhg?e=reyHi3 ## 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 Newly added tests are passing successfully: ![image.png](https://msdata.visualstudio.com/c6789c20-b819-4bfd-9917-11471655156e/_apis/git/repositories/2247f543-55d8-45df-a9fe-23820ae656af/pullRequests/1696252/attachments/image.png) Ran all tests which are passing successfully: ![image.png](https://msdata.visualstudio.com/c6789c20-b819-4bfd-9917-11471655156e/_apis/git/repositories/2247f543-55d8-45df-a9fe-23820ae656af/pullRequests/1696252/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 ---- #### AI description (iteration 1) #### PR Classification New feature implementation to support manual and perform cutover options in ScriptDOM. #### PR Summary This pull request extends ScriptDOM to accommodate the MANUAL_CUTOVER and PERFORM_CUTOVER options as required for the Forward Migration v2 feature. The enhancements include grammar updates, AST modifications, option kind extensions, code generation adjustments, and new SQL tests. - **`TSql170.g`**: Added production rules for `alterDbManualCutover` and `alterDbPerformCutover` to parse the new options. - **`Ast.xml`**: Introduced new classes (`ManualCutoverDatabaseOption` and `PerformCutoverDatabaseOption`) to represent the cutover options. - **`DatabaseOptionKind.cs` & Helpers**: Extended the enum and updated mappings in `DatabaseOptionKindHelper.cs` and `OnOffSimpleDbOptionsHelper.cs` with the new option kinds. - **`CodeGenerationSupporter.cs` & `SqlVersionFlags.cs`**: Incorporate... * Merged PR 1704129: support ORDER clause for NonClustered ColumnStore Index ## Description Support Order clause on NONClustered ColumnStore Index. CREATE NONCLUSTERED COLUMNSTORE INDEX NCCI ON T(A, B, C) ORDER(A, B); CREATE COLUMNSTORE INDEX idx_ntccitrim_prim2 ON dbo.nttrim_prim (i1, c1, nvc1) ORDER (i1, c1); We already support CLUSTERED COLUMNSTORE INDEX Order clause, we need add support for NonClustered right now. ## 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 ![image.png](https://msdata.visualstudio.com/c6789c20-b819-4bfd-9917-11471655156e/_apis/git/repositories/2247f543-55d8-45df-a9fe-23820ae656af/pullRequests/1704129/attachments/image.png) ## Documentation - [x] 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 support ORDER clause for NonClustered ColumnStore Index ---- #### AI description (iteration 1) #### PR Classification New feature enabling the ORDER clause for both clustered and non-clustered columnstore indexes. #### PR Summary This pull request enhances the SQL script generator to support the ORDER clause for columnstore indexes and adds tests to verify the new syntax. - `SqlScriptGeneratorVisitor.CreateColumnStoreIndexStatement.cs`: Modified condition to generate ordered columns for both clustered and non-clustered indexes. - `Only170SyntaxTests.cs`: Updated test suite to include a new parser test for the CreateColumnStoreIndex syntax. - `Baselines170/CreateColumnStoreIndexTests170.sql` & `TestScripts/CreateColumnStoreIndexTests170.sql`: Added new test files to validate the ORDER clause support. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> Related work items: #3876240 * Merged PR 1702087: Identity Column - Fabric DW In this PR we delete options for Identity Columns in TSqlFabricDW.g since they are not supported by the Fabric SQL engine. i.e. Fabric warehouse does not support seed and increment.. Hence the supported TSQL syntax would change from: `IDENTITY [ (seed , increment) ]` to the new syntax: `CREATE TABLE table1 ( ID BIGINT IDENTITY );` Related work items: #4314344 * [Security] Update .NET SDK to latest patch version * Fix test on Linux --------- Co-authored-by: Mohit Agarwal <[email protected]> Co-authored-by: May Wen <[email protected]> Co-authored-by: Dhruv Relwani <[email protected]> Co-authored-by: MerlinBot <MerlinBot>
1 parent e0a6eb2 commit 003271e

21 files changed

+218
-35
lines changed

SqlScriptDom/Parser/TSql/Ast.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,6 +2404,7 @@
24042404
<InheritedClass Name="AlterDatabaseStatement" />
24052405
<Member Name="Termination" Type="AlterDatabaseTermination" Summary="Optional termination options"/>
24062406
<Member Name="Options" Type="DatabaseOption" Collection="true" Summary="Options specified in this statement"/>
2407+
<Member Name="WithManualCutover" Type="bool" Summary="True if WITH MANUAL_CUTOVER is specified in the ALTER DATABASE MODIFY statement."/>
24072408
</Class>
24082409
<Class Name="DatabaseOption" Summary="Single option in ALTER DATABASE statement, SET case">
24092410
<Member Name="OptionKind" Type="DatabaseOptionKind" GenerateUpdatePositionInfoCall="false" Summary="The option kind."/>
@@ -2576,6 +2577,9 @@
25762577
<Member Name="MaxSize" Type="Literal" Summary="The maximum size."/>
25772578
<Member Name="Units" Type="MemoryUnit" GenerateUpdatePositionInfoCall="false" Summary="Measurement units for size. Only GB is valid."/>
25782579
</Class>
2580+
<Class Name="AlterDatabasePerformCutoverStatement" Base="AlterDatabaseStatement" Summary="Represents ALTER DATABASE ... PERFORM_CUTOVER statement for Azure.">
2581+
<InheritedClass Name="AlterDatabaseStatement"/>
2582+
</Class>
25792583
<Interface Name="ICollationSetter">
25802584
<Member Name="Collation" Type="Identifier" Summary="Collation identifier" />
25812585
</Interface>

SqlScriptDom/Parser/TSql/CodeGenerationSupporter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ internal static class CodeGenerationSupporter
564564
internal const string LSquareParen = "[";
565565
internal const string MaintainIndex = "MAINTAIN_INDEX";
566566
internal const string Manual = "MANUAL";
567+
internal const string ManualCutover = "MANUAL_CUTOVER";
567568
internal const string Mark = "MARK";
568569
internal const string MarkInUseForRemoval = "MARK_IN_USE_FOR_REMOVAL";
569570
internal const string Masked = "MASKED";
@@ -728,6 +729,7 @@ internal static class CodeGenerationSupporter
728729
internal const string Paused = "PAUSED";
729730
internal const string Percentage = "PERCENTAGE";
730731
internal const string PerCpu = "PER_CPU";
732+
internal const string PerformCutover = "PERFORM_CUTOVER";
731733
internal const string Period = "PERIOD";
732734
internal const string PermissionSet = "PERMISSION_SET";
733735
internal const string PerNode = "PER_NODE";

SqlScriptDom/Parser/TSql/DatabaseOptionKind.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ public enum DatabaseOptionKind
9595

9696
// T-SQL 150 On/Off options
9797
DataRetention = 67,
98-
Ledger = 68
98+
Ledger = 68,
99+
100+
ManualCutover = 69,
101+
PerformCutover = 70
99102
}
100103

101104
#pragma warning restore 1591

SqlScriptDom/Parser/TSql/DatabaseOptionKindHelper.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ private DatabaseOptionKindHelper()
3232

3333
// 140 Options
3434
AddOptionMapping(DatabaseOptionKind.AutomaticTuning, CodeGenerationSupporter.AutomaticTuning, SqlVersionFlags.TSql140AndAbove);
35+
36+
// 170 Options
37+
AddOptionMapping(DatabaseOptionKind.ManualCutover, CodeGenerationSupporter.ManualCutover, SqlVersionFlags.TSql170AndAbove);
38+
AddOptionMapping(DatabaseOptionKind.PerformCutover, CodeGenerationSupporter.PerformCutover, SqlVersionFlags.TSql170AndAbove);
3539
}
3640

3741
internal static readonly DatabaseOptionKindHelper Instance = new DatabaseOptionKindHelper();

SqlScriptDom/Parser/TSql/SqlVersionFlags.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ internal enum SqlVersionFlags
3535
TSql140AndAbove = TSql140 | TSql150 | TSql160 | TSqlFabricDW | TSql170,
3636
TSql150AndAbove = TSql150 | TSql160 | TSqlFabricDW | TSql170,
3737
TSql160AndAbove = TSql160 | TSqlFabricDW | TSql170,
38+
TSql170AndAbove = TSql170,
3839
TSqlFabricDWAndAbove = TSql160 | TSqlFabricDW | TSql170,
3940
TSqlUnder110 = TSql80 | TSql90 | TSql100,
4041
TSqlUnder120 = TSql80 | TSql90 | TSql100 | TSql110,

SqlScriptDom/Parser/TSql/TSql170.g

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2896,6 +2896,7 @@ alterDatabase [IToken tAlter] returns [AlterDatabaseStatement vResult = null]
28962896
| vResult = alterDbSet
28972897
| vResult = alterDbCollate
28982898
| vResult = alterDbRebuild // Undocumented - for PSS only
2899+
| vResult = alterDbPerformCutover
28992900
)
29002901
{
29012902
if(vUseCurrent)
@@ -3057,8 +3058,19 @@ alterDbModify returns [AlterDatabaseStatement vResult = null]
30573058
;
30583059

30593060
alterDbModifyAzureOptions returns [AlterDatabaseSetStatement vResult = FragmentFactory.CreateFragment<AlterDatabaseSetStatement>()]
3061+
{
3062+
bool hasManualCutover = false;
3063+
}
30603064
:
30613065
azureOptions[vResult, vResult.Options]
3066+
(
3067+
With tManualCutover:Identifier
3068+
{
3069+
Match(tManualCutover, CodeGenerationSupporter.ManualCutover);
3070+
hasManualCutover = true;
3071+
vResult.WithManualCutover = true;
3072+
}
3073+
)?
30623074
;
30633075

30643076
// MODIFY File syntax
@@ -3143,6 +3155,14 @@ toFilegroup returns [Identifier vResult]
31433155
}
31443156
;
31453157

3158+
alterDbPerformCutover returns [AlterDatabasePerformCutoverStatement vResult = FragmentFactory.CreateFragment<AlterDatabasePerformCutoverStatement>()]
3159+
: tPerformCutover:Identifier
3160+
{
3161+
Match(tPerformCutover, CodeGenerationSupporter.PerformCutover);
3162+
UpdateTokenInfo(vResult, tPerformCutover);
3163+
}
3164+
;
3165+
31463166
xactTermination returns [AlterDatabaseTermination vResult = FragmentFactory.CreateFragment<AlterDatabaseTermination>()]
31473167
{
31483168
Literal vInteger;

SqlScriptDom/Parser/TSql/TSqlFabricDW.g

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29587,33 +29587,10 @@ rowguidcolConstraint [ColumnDefinition vParent]
2958729587
;
2958829588

2958929589
identityConstraint [IndexAffectingStatement statementType] returns [IdentityOptions vResult = FragmentFactory.CreateFragment<IdentityOptions>()]
29590-
{
29591-
ScalarExpression vExpression;
29592-
bool vNotForReplication;
29593-
}
2959429590
: tIdentity:Identity
2959529591
{
2959629592
UpdateTokenInfo(vResult,tIdentity);
2959729593
}
29598-
(
29599-
(LeftParenthesis seedIncrement)=> // necessary because select statement can start with LeftParenthesis
29600-
LeftParenthesis vExpression=seedIncrement
29601-
{
29602-
vResult.IdentitySeed = vExpression;
29603-
}
29604-
Comma vExpression=seedIncrement
29605-
{
29606-
vResult.IdentityIncrement = vExpression;
29607-
}
29608-
tRParen:RightParenthesis
29609-
{
29610-
UpdateTokenInfo(vResult,tRParen);
29611-
}
29612-
)?
29613-
vNotForReplication = replicationClauseOpt[statementType, vResult]
29614-
{
29615-
vResult.IsIdentityNotForReplication = vNotForReplication;
29616-
}
2961729594
;
2961829595

2961929596
// Same as column_definition in SQL YACC grammar
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//------------------------------------------------------------------------------
2+
// <copyright file="SqlScriptGeneratorVisitor.AlterDbPerformCutoverStatement.cs" company="Microsoft">
3+
// Copyright (c) Microsoft Corporation. All rights reserved.
4+
// </copyright>
5+
//------------------------------------------------------------------------------
6+
using System;
7+
8+
using Microsoft.SqlServer.TransactSql.ScriptDom;
9+
10+
namespace Microsoft.SqlServer.TransactSql.ScriptDom.ScriptGenerator
11+
{
12+
partial class SqlScriptGeneratorVisitor
13+
{
14+
public override void ExplicitVisit(AlterDatabasePerformCutoverStatement node)
15+
{
16+
GenerateAlterDbStatementHead(node);
17+
18+
GenerateSpaceAndIdentifier(CodeGenerationSupporter.PerformCutover);
19+
}
20+
}
21+
}

SqlScriptDom/ScriptDom/SqlServer/ScriptGenerator/SqlScriptGeneratorVisitor.AlterDbSetStatement.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ public override void ExplicitVisit(AlterDatabaseSetStatement node)
1515

1616
NewLineAndIndent();
1717
bool azureOnlyOption = true;
18-
foreach(DatabaseOption option in node.Options)
18+
foreach (DatabaseOption option in node.Options)
1919
{
20-
if (option.OptionKind != DatabaseOptionKind.MaxSize && option.OptionKind != DatabaseOptionKind.Edition && option.OptionKind != DatabaseOptionKind.ServiceObjective)
20+
if (option.OptionKind != DatabaseOptionKind.MaxSize &&
21+
option.OptionKind != DatabaseOptionKind.Edition &&
22+
option.OptionKind != DatabaseOptionKind.ServiceObjective)
2123
{
2224
azureOnlyOption = false;
2325
break;
@@ -31,6 +33,13 @@ public override void ExplicitVisit(AlterDatabaseSetStatement node)
3133
MarkAndPushAlignmentPoint(items);
3234
GenerateParenthesisedCommaSeparatedList(node.Options, true);
3335
PopAlignmentPoint();
36+
37+
// Emit "WITH MANUAL_CUTOVER" if the statement includes the optional manual cutover clause
38+
if (node.WithManualCutover)
39+
{
40+
GenerateSpaceAndKeyword(TSqlTokenType.With);
41+
GenerateSpaceAndIdentifier(CodeGenerationSupporter.ManualCutover);
42+
}
3443
}
3544
else
3645
{

SqlScriptDom/ScriptDom/SqlServer/ScriptGenerator/SqlScriptGeneratorVisitor.CreateColumnStoreIndexStatement.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ public override void ExplicitVisit(CreateColumnStoreIndexStatement node)
3636
GenerateParenthesisedCommaSeparatedList(node.Columns);
3737
}
3838

39-
// If clustered columstore index, generate ordered columns if any
40-
if(node.Clustered.GetValueOrDefault() && node.OrderedColumns != null && node.OrderedColumns.Count > 0)
39+
// Generate ordered columns if any, for both clustered and non-clustered indexes
40+
// If node.Clustered is null or false, it indicates index type is non-clustered.
41+
// If node.Clustered is true, it indicates index type is clustered.
42+
if (node.OrderedColumns != null && node.OrderedColumns.Count > 0)
4143
{
4244
GenerateSpaceAndKeyword(TSqlTokenType.Order);
4345
GenerateParenthesisedCommaSeparatedList(node.OrderedColumns);

0 commit comments

Comments
 (0)