Skip to content

Sync repos: Release 170.64.0 #141

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions SqlScriptDom/Parser/TSql/Ast.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2404,6 +2404,7 @@
<InheritedClass Name="AlterDatabaseStatement" />
<Member Name="Termination" Type="AlterDatabaseTermination" Summary="Optional termination options"/>
<Member Name="Options" Type="DatabaseOption" Collection="true" Summary="Options specified in this statement"/>
<Member Name="WithManualCutover" Type="bool" Summary="True if WITH MANUAL_CUTOVER is specified in the ALTER DATABASE MODIFY statement."/>
</Class>
<Class Name="DatabaseOption" Summary="Single option in ALTER DATABASE statement, SET case">
<Member Name="OptionKind" Type="DatabaseOptionKind" GenerateUpdatePositionInfoCall="false" Summary="The option kind."/>
Expand Down Expand Up @@ -2576,6 +2577,9 @@
<Member Name="MaxSize" Type="Literal" Summary="The maximum size."/>
<Member Name="Units" Type="MemoryUnit" GenerateUpdatePositionInfoCall="false" Summary="Measurement units for size. Only GB is valid."/>
</Class>
<Class Name="AlterDatabasePerformCutoverStatement" Base="AlterDatabaseStatement" Summary="Represents ALTER DATABASE ... PERFORM_CUTOVER statement for Azure.">
<InheritedClass Name="AlterDatabaseStatement"/>
</Class>
<Interface Name="ICollationSetter">
<Member Name="Collation" Type="Identifier" Summary="Collation identifier" />
</Interface>
Expand Down
2 changes: 2 additions & 0 deletions SqlScriptDom/Parser/TSql/CodeGenerationSupporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ internal static class CodeGenerationSupporter
internal const string LSquareParen = "[";
internal const string MaintainIndex = "MAINTAIN_INDEX";
internal const string Manual = "MANUAL";
internal const string ManualCutover = "MANUAL_CUTOVER";
internal const string Mark = "MARK";
internal const string MarkInUseForRemoval = "MARK_IN_USE_FOR_REMOVAL";
internal const string Masked = "MASKED";
Expand Down Expand Up @@ -728,6 +729,7 @@ internal static class CodeGenerationSupporter
internal const string Paused = "PAUSED";
internal const string Percentage = "PERCENTAGE";
internal const string PerCpu = "PER_CPU";
internal const string PerformCutover = "PERFORM_CUTOVER";
internal const string Period = "PERIOD";
internal const string PermissionSet = "PERMISSION_SET";
internal const string PerNode = "PER_NODE";
Expand Down
5 changes: 4 additions & 1 deletion SqlScriptDom/Parser/TSql/DatabaseOptionKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ public enum DatabaseOptionKind

// T-SQL 150 On/Off options
DataRetention = 67,
Ledger = 68
Ledger = 68,

ManualCutover = 69,
PerformCutover = 70
}

#pragma warning restore 1591
Expand Down
4 changes: 4 additions & 0 deletions SqlScriptDom/Parser/TSql/DatabaseOptionKindHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ private DatabaseOptionKindHelper()

// 140 Options
AddOptionMapping(DatabaseOptionKind.AutomaticTuning, CodeGenerationSupporter.AutomaticTuning, SqlVersionFlags.TSql140AndAbove);

// 170 Options
AddOptionMapping(DatabaseOptionKind.ManualCutover, CodeGenerationSupporter.ManualCutover, SqlVersionFlags.TSql170AndAbove);
AddOptionMapping(DatabaseOptionKind.PerformCutover, CodeGenerationSupporter.PerformCutover, SqlVersionFlags.TSql170AndAbove);
}

internal static readonly DatabaseOptionKindHelper Instance = new DatabaseOptionKindHelper();
Expand Down
1 change: 1 addition & 0 deletions SqlScriptDom/Parser/TSql/SqlVersionFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ internal enum SqlVersionFlags
TSql140AndAbove = TSql140 | TSql150 | TSql160 | TSqlFabricDW | TSql170,
TSql150AndAbove = TSql150 | TSql160 | TSqlFabricDW | TSql170,
TSql160AndAbove = TSql160 | TSqlFabricDW | TSql170,
TSql170AndAbove = TSql170,
TSqlFabricDWAndAbove = TSql160 | TSqlFabricDW | TSql170,
TSqlUnder110 = TSql80 | TSql90 | TSql100,
TSqlUnder120 = TSql80 | TSql90 | TSql100 | TSql110,
Expand Down
20 changes: 20 additions & 0 deletions SqlScriptDom/Parser/TSql/TSql170.g
Original file line number Diff line number Diff line change
Expand Up @@ -2896,6 +2896,7 @@ alterDatabase [IToken tAlter] returns [AlterDatabaseStatement vResult = null]
| vResult = alterDbSet
| vResult = alterDbCollate
| vResult = alterDbRebuild // Undocumented - for PSS only
| vResult = alterDbPerformCutover
)
{
if(vUseCurrent)
Expand Down Expand Up @@ -3057,8 +3058,19 @@ alterDbModify returns [AlterDatabaseStatement vResult = null]
;

alterDbModifyAzureOptions returns [AlterDatabaseSetStatement vResult = FragmentFactory.CreateFragment<AlterDatabaseSetStatement>()]
{
bool hasManualCutover = false;
}
:
azureOptions[vResult, vResult.Options]
(
With tManualCutover:Identifier
{
Match(tManualCutover, CodeGenerationSupporter.ManualCutover);
hasManualCutover = true;
vResult.WithManualCutover = true;
}
)?
;

// MODIFY File syntax
Expand Down Expand Up @@ -3143,6 +3155,14 @@ toFilegroup returns [Identifier vResult]
}
;

alterDbPerformCutover returns [AlterDatabasePerformCutoverStatement vResult = FragmentFactory.CreateFragment<AlterDatabasePerformCutoverStatement>()]
: tPerformCutover:Identifier
{
Match(tPerformCutover, CodeGenerationSupporter.PerformCutover);
UpdateTokenInfo(vResult, tPerformCutover);
}
;

xactTermination returns [AlterDatabaseTermination vResult = FragmentFactory.CreateFragment<AlterDatabaseTermination>()]
{
Literal vInteger;
Expand Down
23 changes: 0 additions & 23 deletions SqlScriptDom/Parser/TSql/TSqlFabricDW.g
Original file line number Diff line number Diff line change
Expand Up @@ -29587,33 +29587,10 @@ rowguidcolConstraint [ColumnDefinition vParent]
;

identityConstraint [IndexAffectingStatement statementType] returns [IdentityOptions vResult = FragmentFactory.CreateFragment<IdentityOptions>()]
{
ScalarExpression vExpression;
bool vNotForReplication;
}
: tIdentity:Identity
{
UpdateTokenInfo(vResult,tIdentity);
}
(
(LeftParenthesis seedIncrement)=> // necessary because select statement can start with LeftParenthesis
LeftParenthesis vExpression=seedIncrement
{
vResult.IdentitySeed = vExpression;
}
Comma vExpression=seedIncrement
{
vResult.IdentityIncrement = vExpression;
}
tRParen:RightParenthesis
{
UpdateTokenInfo(vResult,tRParen);
}
)?
vNotForReplication = replicationClauseOpt[statementType, vResult]
{
vResult.IsIdentityNotForReplication = vNotForReplication;
}
;

// Same as column_definition in SQL YACC grammar
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//------------------------------------------------------------------------------
// <copyright file="SqlScriptGeneratorVisitor.AlterDbPerformCutoverStatement.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;

using Microsoft.SqlServer.TransactSql.ScriptDom;

namespace Microsoft.SqlServer.TransactSql.ScriptDom.ScriptGenerator
{
partial class SqlScriptGeneratorVisitor
{
public override void ExplicitVisit(AlterDatabasePerformCutoverStatement node)
{
GenerateAlterDbStatementHead(node);

GenerateSpaceAndIdentifier(CodeGenerationSupporter.PerformCutover);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ public override void ExplicitVisit(AlterDatabaseSetStatement node)

NewLineAndIndent();
bool azureOnlyOption = true;
foreach(DatabaseOption option in node.Options)
foreach (DatabaseOption option in node.Options)
{
if (option.OptionKind != DatabaseOptionKind.MaxSize && option.OptionKind != DatabaseOptionKind.Edition && option.OptionKind != DatabaseOptionKind.ServiceObjective)
if (option.OptionKind != DatabaseOptionKind.MaxSize &&
option.OptionKind != DatabaseOptionKind.Edition &&
option.OptionKind != DatabaseOptionKind.ServiceObjective)
{
azureOnlyOption = false;
break;
Expand All @@ -31,6 +33,13 @@ public override void ExplicitVisit(AlterDatabaseSetStatement node)
MarkAndPushAlignmentPoint(items);
GenerateParenthesisedCommaSeparatedList(node.Options, true);
PopAlignmentPoint();

// Emit "WITH MANUAL_CUTOVER" if the statement includes the optional manual cutover clause
if (node.WithManualCutover)
{
GenerateSpaceAndKeyword(TSqlTokenType.With);
GenerateSpaceAndIdentifier(CodeGenerationSupporter.ManualCutover);
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public override void ExplicitVisit(CreateColumnStoreIndexStatement node)
GenerateParenthesisedCommaSeparatedList(node.Columns);
}

// If clustered columstore index, generate ordered columns if any
if(node.Clustered.GetValueOrDefault() && node.OrderedColumns != null && node.OrderedColumns.Count > 0)
// Generate ordered columns if any, for both clustered and non-clustered indexes
// If node.Clustered is null or false, it indicates index type is non-clustered.
// If node.Clustered is true, it indicates index type is clustered.
if (node.OrderedColumns != null && node.OrderedColumns.Count > 0)
{
GenerateSpaceAndKeyword(TSqlTokenType.Order);
GenerateParenthesisedCommaSeparatedList(node.OrderedColumns);
Expand Down
10 changes: 10 additions & 0 deletions Test/SqlDom/Baselines170/AlterDatabaseManualCutoverTests170.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ALTER DATABASE db
MODIFY (SERVICE_OBJECTIVE = 'HS_Gen5_16') WITH MANUAL_CUTOVER;

ALTER DATABASE db
MODIFY (EDITION = 'Hyperscale') WITH MANUAL_CUTOVER;

ALTER DATABASE db
MODIFY (SERVICE_OBJECTIVE = ELASTIC_POOL (NAME = [hspool])) WITH MANUAL_CUTOVER;

ALTER DATABASE db PERFORM_CUTOVER;
8 changes: 8 additions & 0 deletions Test/SqlDom/Baselines170/CreateColumnStoreIndexTests170.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE NONCLUSTERED COLUMNSTORE INDEX NCCI
ON T(A, B, C) ORDER(A, B);

CREATE COLUMNSTORE INDEX NCCI
ON T(A, B, C) ORDER(A, B);

CREATE CLUSTERED COLUMNSTORE INDEX CCI
ON T ORDER(A, B);
27 changes: 27 additions & 0 deletions Test/SqlDom/BaselinesFabricDW/IdentityColumnTestsFabricDW.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CREATE TABLE table1 (
ID BIGINT IDENTITY
);


GO
CREATE TABLE Employees (
EmployeeID BIGINT IDENTITY,
FirstName NVARCHAR (50),
LastName NVARCHAR (50)
);


GO
CREATE TABLE Orders (
OrderID INT IDENTITY,
CustomerName VARCHAR (100) ,
OrderDate DATETIME ,
TotalAmount DECIMAL (10, 2)
);


GO
CREATE TABLE Products (
ProductID BIGINT IDENTITY,
ProductName NVARCHAR (100)
);
17 changes: 17 additions & 0 deletions Test/SqlDom/CommonSyntaxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using Microsoft.SqlServer.TransactSql.ScriptDom;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SqlStudio.Tests.AssemblyTools.TestCategory;
using System;
using System.Collections.Generic;

namespace SqlStudio.Tests.UTSqlScriptDom
{
Expand Down Expand Up @@ -238,8 +240,23 @@ public void CommonSyntaxInFabricDWParserTest()
TSqlFabricDWParser parser = new TSqlFabricDWParser(true);
SqlScriptGenerator scriptGen = ParserTestUtils.CreateScriptGen(SqlVersion.SqlFabricDW);

// Some syntaxes that are not supported in Fabric DW
var skippedTests = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"ColumnDefinitionTests.sql",
"IntegerTests.sql",
"TSqlParserTestScript1.sql",
"TSqlParserTestScript2.sql",
"ExpressionTests.sql"
};

foreach (ParserTest ti in CommonTestInfos)
{
if (skippedTests.Contains(ti._scriptFilename))
{
continue; // Skip tests that are not applicable to Fabric DW
}

ParserTest.ParseAndVerify(parser, scriptGen, ti._scriptFilename, ti._resultFabricDW);
}
}
Expand Down
4 changes: 3 additions & 1 deletion Test/SqlDom/Only170SyntaxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ public partial class SqlDomTests
// Note: These filenames are case sensitive, make sure they match the checked-in file exactly
private static readonly ParserTest[] Only170TestInfos =
{
new ParserTest170("RegexpTVFTests170.sql", nErrors80: 1, nErrors90: 1, nErrors100: 0, nErrors110: 0, nErrors120: 0, nErrors130: 0, nErrors140: 0, nErrors150: 0, nErrors160: 0)
new ParserTest170("RegexpTVFTests170.sql", nErrors80: 1, nErrors90: 1, nErrors100: 0, nErrors110: 0, nErrors120: 0, nErrors130: 0, nErrors140: 0, nErrors150: 0, nErrors160: 0),
new ParserTest170("AlterDatabaseManualCutoverTests170.sql", nErrors80: 4, nErrors90: 4, nErrors100: 4, nErrors110: 4, nErrors120: 4, nErrors130: 4, nErrors140: 4, nErrors150: 4, nErrors160: 4),
new ParserTest170("CreateColumnStoreIndexTests170.sql", nErrors80: 3, nErrors90: 3, nErrors100: 3, nErrors110: 3, nErrors120: 3, nErrors130: 0, nErrors140: 0, nErrors150: 0, nErrors160: 0)
};

private static readonly ParserTest[] SqlAzure170_TestInfos =
Expand Down
5 changes: 3 additions & 2 deletions Test/SqlDom/OnlyFabricDWSyntaxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ public partial class SqlDomTests
private static readonly ParserTest[] OnlyFabricDWTestInfos =
{
new ParserTestFabricDW("CloneTableTestsFabricDW.sql", nErrors80: 4, nErrors90: 4, nErrors100: 4, nErrors110: 4, nErrors120: 4, nErrors130: 4, nErrors140: 4, nErrors150: 4, nErrors160: 4, nErrors170: 4),
new ParserTestFabricDW("CreateProcedureCloneTableTestsFabricDW.sql", nErrors80: 4, nErrors90: 4, nErrors100: 4, nErrors110: 4, nErrors120: 4, nErrors130: 4, nErrors140: 4, nErrors150: 4, nErrors160: 4, nErrors170: 4),
new ParserTestFabricDW("ScalarFunctionTestsFabricDW.sql", nErrors80: 3, nErrors90: 2, nErrors100: 2, nErrors110: 2, nErrors120: 2, nErrors130: 0, nErrors140: 0, nErrors150: 0, nErrors160: 0, nErrors170: 0),
new ParserTestFabricDW("CreateAlterTableClusterByTestsFabricDW.sql", nErrors80: 6, nErrors90: 6, nErrors100: 6, nErrors110: 6, nErrors120: 6, nErrors130: 6, nErrors140: 6, nErrors150: 6, nErrors160: 6, nErrors170: 6),
new ParserTestFabricDW("CreateExternalTableStatementTestsFabricDW.sql", nErrors80: 2, nErrors90: 2, nErrors100: 2, nErrors110: 2, nErrors120: 2, nErrors130: 2, nErrors140: 2, nErrors150: 2, nErrors160: 0, nErrors170: 0),
new ParserTestFabricDW("CreateProcedureCloneTableTestsFabricDW.sql", nErrors80: 4, nErrors90: 4, nErrors100: 4, nErrors110: 4, nErrors120: 4, nErrors130: 4, nErrors140: 4, nErrors150: 4, nErrors160: 4, nErrors170: 4),
new ParserTestFabricDW("IdentityColumnTestsFabricDW.sql", nErrors80: 0, nErrors90: 0, nErrors100: 0, nErrors110: 0, nErrors120: 0, nErrors130: 0, nErrors140: 0, nErrors150: 0, nErrors160: 0, nErrors170: 0),
new ParserTestFabricDW("ScalarFunctionTestsFabricDW.sql", nErrors80: 3, nErrors90: 2, nErrors100: 2, nErrors110: 2, nErrors120: 2, nErrors130: 0, nErrors140: 0, nErrors150: 0, nErrors160: 0, nErrors170: 0)
};

[TestMethod]
Expand Down
36 changes: 33 additions & 3 deletions Test/SqlDom/ParserErrorsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3524,9 +3524,17 @@ public void NotForReplicationNotAllowedInTableVariablesFunctionsTypesErrorTest()
new ParserErrorInfo(39, "SQL46010", "not"));

// Column identity constraint
ParserTestUtils.ErrorTestAllParsers("declare @v1 table (c1 int identity(1,1) not for replication)",
ParserTestUtils.ErrorTestAllParsersUntil150("declare @v1 table (c1 int identity(1,1) not for replication)",
new ParserErrorInfo(40, "SQL46010", "not"));
ParserTestUtils.ErrorTestAllParsers("create function f1() returns @v1 table (c1 int identity(1,1) not for replication) begin return end",
ParserTestUtils.ErrorTest160("declare @v1 table (c1 int identity(1,1) not for replication)",
new ParserErrorInfo(40, "SQL46010", "not"));
ParserTestUtils.ErrorTest170("declare @v1 table (c1 int identity(1,1) not for replication)",
new ParserErrorInfo(40, "SQL46010", "not"));
ParserTestUtils.ErrorTestAllParsersUntil150("create function f1() returns @v1 table (c1 int identity(1,1) not for replication) begin return end",
new ParserErrorInfo(61, "SQL46010", "not"));
ParserTestUtils.ErrorTest160("create function f1() returns @v1 table (c1 int identity(1,1) not for replication) begin return end",
new ParserErrorInfo(61, "SQL46010", "not"));
ParserTestUtils.ErrorTest170("create function f1() returns @v1 table (c1 int identity(1,1) not for replication) begin return end",
new ParserErrorInfo(61, "SQL46010", "not"));
ParserTestUtils.ErrorTest100("create type t1 as table (c1 int identity(1,1) not for replication)",
new ParserErrorInfo(46, "SQL46010", "not"));
Expand Down Expand Up @@ -6838,7 +6846,6 @@ RETURNS NVARCHAR(101)
RETURN @first + ' ' + @last
END;";
ParserTestUtils.ErrorTestFabricDW(scalarFunctionSyntax2, new ParserErrorInfo(scalarFunctionSyntax2.IndexOf("INLINE"), "SQL46010", "INLINE"));

string scalarFunctionSyntax3 = @"CREATE OR ALTER FUNCTION dbo.CountProducts
(
@ProductTable AS dbo.ProductType READONLY
Expand Down Expand Up @@ -6868,5 +6875,28 @@ FROM @SalesData
END;";
ParserTestUtils.ErrorTestFabricDW(scalarFunctionSyntax4, new ParserErrorInfo(scalarFunctionSyntax4.IndexOf("NULL"), "SQL46010", "NULL"));
}

/// <summary>
/// Negative tests for Scalar Functions in Fabric DW.
/// </summary>
[TestMethod]
[Priority(0)]
[SqlStudioTestCategory(Category.UnitTest)]
public void IdentityColumnNegativeTestsFabricDW()
{
string identityColumnSyntax = @"CREATE TABLE TestTable1 (
ID INT IDENTITY(1,1),
Name VARCHAR(50)
);
";
ParserTestUtils.ErrorTestFabricDW(identityColumnSyntax, new ParserErrorInfo(identityColumnSyntax.IndexOf("IDENTITY(") + 8, "SQL46010", "("));

string identityColumnSyntax2 = @"CREATE TABLE TestTable2 (
RecordID BIGINT IDENTITY(100,5),
Description NVARCHAR(200)
);
";
ParserTestUtils.ErrorTestFabricDW(identityColumnSyntax2, new ParserErrorInfo(identityColumnSyntax2.IndexOf("IDENTITY(") + 8, "SQL46010", "("));
}
}
}
10 changes: 10 additions & 0 deletions Test/SqlDom/TestScripts/AlterDatabaseManualCutoverTests170.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ALTER DATABASE db
MODIFY (SERVICE_OBJECTIVE = 'HS_Gen5_16') WITH MANUAL_CUTOVER;

ALTER DATABASE db
MODIFY (EDITION = 'Hyperscale') WITH MANUAL_CUTOVER;

ALTER DATABASE db
MODIFY (SERVICE_OBJECTIVE = ELASTIC_POOL (NAME = [hspool])) WITH MANUAL_CUTOVER;

ALTER DATABASE db PERFORM_CUTOVER;
8 changes: 8 additions & 0 deletions Test/SqlDom/TestScripts/CreateColumnStoreIndexTests170.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE NONCLUSTERED COLUMNSTORE INDEX NCCI
ON T(A, B, C) ORDER(A, B);

CREATE COLUMNSTORE INDEX NCCI
ON T(A, B, C) ORDER(A, B);

CREATE CLUSTERED COLUMNSTORE INDEX CCI
ON T ORDER(A, B);
Loading
Loading