Skip to content

Commit 42f5cad

Browse files
authored
Sync repos: Release170.53.0 (#135)
Sync repos: Release170.53.0 (#135)
1 parent 0422e73 commit 42f5cad

26 files changed

+1350
-542
lines changed

SqlScriptDom/Parser/TSql/Ast.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,10 @@
14591459
<InheritedMember Name="SchemaObjectName" ContainerClass="AlterTableStatement"/>
14601460
<Member Name="Options" Type="TableOption" Collection="true" Summary="Options to be set."/>
14611461
</Class>
1462+
<Class Name="AlterTableAddClusterByStatement" Base="AlterTableStatement" Summary="Alters a table by adding a CLUSTER BY specification.">
1463+
<InheritedMember Name="SchemaObjectName" ContainerClass="AlterTableStatement"/>
1464+
<Member Name="ClusterByOption" Type="ClusterByTableOption" Summary="The CLUSTER BY option to be added to the table."/>
1465+
</Class>
14621466
<Class Name="TableOption" Abstract="true" Summary="A single table option.">
14631467
<Member Name="OptionKind" Type="TableOptionKind" GenerateUpdatePositionInfoCall="false" Summary="The option kind."/>
14641468
</Class>
@@ -2674,6 +2678,9 @@
26742678
<!-- CTAS additions for SQL Dw-->
26752679
<Member Name="SelectStatement" Type="SelectStatement" Summary="Represents the query part of a CTAS statement."/>
26762680
<Member Name="CtasColumns" Type="Identifier" Collection="true" Summary="The columns for the view. This is optionally supported with CTAS statements."/>
2681+
<!-- CTAC additions for Fabric DW SQL-->
2682+
<Member Name="CloneSource" Type="SchemaObjectName" Summary="Source table for CLONE syntax."/>
2683+
<Member Name="ClonePointInTime" Type="ScalarExpression" Summary="Optional point in time for CLONE statement."/>
26772684
</Class>
26782685
<Class Name="FederationScheme" Summary="This class stores the federation scheme for a table">
26792686
<Member Name="DistributionName" Type="Identifier" Summary="The name of the distribution."/>
@@ -2706,6 +2713,11 @@
27062713
<Member Name="DistributionColumns" Type="Identifier" Collection="true" GenerateUpdatePositionInfoCall="false" Summary="The column reference in the HASH option for a table distribution policy."/>
27072714
</Class>
27082715

2716+
<!-- CLUSTER BY additions for Fabric DW SQL-->
2717+
<Class Name="ClusterByTableOption" Base="TableOption" Summary="Represents the CLUSTER BY option for tables.">
2718+
<InheritedClass Name="TableOption"/>
2719+
<Member Name="Columns" Type="ColumnReferenceExpression" Collection="true" Summary="The columns for clustering the table."/>
2720+
</Class>
27092721
<Class Name="TableIndexOption" Base="TableOption" Summary="Represents the table INDEX option for SQL DW tables.">
27102722
<InheritedClass Name="TableOption"/>
27112723
<Member Name="Value" Type="TableIndexType" GenerateUpdatePositionInfoCall="false" Summary="The table index types could be clustered or non-clustered (heap)."/>

SqlScriptDom/Parser/TSql/CodeGenerationSupporter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ internal static class CodeGenerationSupporter
208208
internal const string Cluster = "CLUSTER";
209209
internal const string Clustered = "CLUSTERED";
210210
internal const string ClearPort = "CLEAR_PORT";
211+
internal const string Clone = "CLONE";
211212
internal const string CodePage = "CODEPAGE";
212213
internal const string Collection = "COLLECTION";
213214
internal const string Column = "COLUMN";

SqlScriptDom/Parser/TSql/TSqlFabricDW.g

Lines changed: 132 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13006,6 +13006,93 @@ functionParameterList[FunctionStatementBody vResult]
1300613006
)*
1300713007
;
1300813008

13009+
scalarFunctionParameter[ProcedureParameter vParent]
13010+
{
13011+
DataTypeReference vDataType;
13012+
ScalarExpression vDefault;
13013+
}
13014+
: vDataType=scalarDataType
13015+
{
13016+
vParent.DataType = vDataType;
13017+
}
13018+
(
13019+
EqualsSign
13020+
(
13021+
vDefault=possibleNegativeConstantOrIdentifierWithDefault
13022+
{
13023+
vParent.Value = vDefault;
13024+
}
13025+
)
13026+
)?
13027+
(
13028+
tId2:Identifier
13029+
{
13030+
if (TryMatch(tId2, CodeGenerationSupporter.Output) || TryMatch(tId2, CodeGenerationSupporter.Out))
13031+
{
13032+
ThrowParseErrorException("SQL46039", tId2, TSqlParserResource.SQL46039Message);
13033+
}
13034+
else
13035+
{
13036+
ThrowParseErrorException("SQL46026", tId2, TSqlParserResource.SQL46026Message, tId2.getText());
13037+
}
13038+
}
13039+
)?
13040+
;
13041+
13042+
scalarFunctionAttributeNoExecuteAs returns [FunctionOption vResult = FragmentFactory.CreateFragment<FunctionOption>()]
13043+
: tOption:Identifier
13044+
{
13045+
if (TryMatch(tOption, CodeGenerationSupporter.SchemaBinding))
13046+
{
13047+
vResult.OptionKind = FunctionOptionKind.SchemaBinding;
13048+
}
13049+
else
13050+
{
13051+
ThrowParseErrorException("SQL46026", tOption, TSqlParserResource.SQL46026Message, tOption.getText());
13052+
}
13053+
UpdateTokenInfo(vResult, tOption);
13054+
}
13055+
| tReturns:Identifier Null On Null tInput:Identifier
13056+
{
13057+
Match(tReturns,CodeGenerationSupporter.Returns);
13058+
Match(tInput,CodeGenerationSupporter.Input);
13059+
vResult.OptionKind = FunctionOptionKind.ReturnsNullOnNullInput;
13060+
UpdateTokenInfo(vResult, tInput);
13061+
}
13062+
| tCalled:Identifier On Null tInput2:Identifier
13063+
{
13064+
Match(tCalled,CodeGenerationSupporter.Called);
13065+
Match(tInput2,CodeGenerationSupporter.Input);
13066+
vResult.OptionKind = FunctionOptionKind.CalledOnNullInput;
13067+
UpdateTokenInfo(vResult, tInput2);
13068+
}
13069+
;
13070+
13071+
13072+
scalarFunctionAttribute returns [FunctionOption vResult]
13073+
: vResult=scalarFunctionAttributeNoExecuteAs
13074+
| vResult=functionExecuteAsOption
13075+
;
13076+
13077+
scalarFunctionAttributes [FunctionStatementBody vParent]
13078+
{
13079+
FunctionOption vOption;
13080+
long encounteredOptions = 0;
13081+
}
13082+
: With vOption=scalarFunctionAttribute
13083+
{
13084+
CheckOptionDuplication(ref encounteredOptions, (int)vOption.OptionKind, vOption);
13085+
AddAndUpdateTokenInfo(vParent, vParent.Options, vOption);
13086+
}
13087+
(
13088+
Comma vOption=scalarFunctionAttribute
13089+
{
13090+
CheckOptionDuplication(ref encounteredOptions, (int)vOption.OptionKind, vOption);
13091+
AddAndUpdateTokenInfo(vParent, vParent.Options, vOption);
13092+
}
13093+
)*
13094+
;
13095+
1300913096
functionParameter returns[ProcedureParameter vResult = FragmentFactory.CreateFragment<ProcedureParameter>()]
1301013097
{
1301113098
Identifier vIdentifier;
@@ -13014,7 +13101,7 @@ functionParameter returns[ProcedureParameter vResult = FragmentFactory.CreateFra
1301413101
{
1301513102
vResult.VariableName = vIdentifier;
1301613103
}
13017-
scalarProcedureParameter[vResult, false, true]
13104+
scalarFunctionParameter[vResult]
1301813105
;
1301913106

1302013107
functionReturnTypeAndBody [FunctionStatementBody vParent, out bool vParseErrorOccurred]
@@ -13034,7 +13121,7 @@ functionReturnTypeAndBody [FunctionStatementBody vParent, out bool vParseErrorOc
1303413121
vScalarResult.DataType = vDataType;
1303513122
vParent.ReturnType = vScalarResult;
1303613123
}
13037-
(functionAttributes[vParent])? (As)?
13124+
(scalarFunctionAttributes[vParent])? (As)?
1303813125
(
1303913126
vCompoundStatement = beginEndBlockStatement
1304013127
{
@@ -26504,6 +26591,8 @@ createTableStatement returns [CreateTableStatement vResult = this.FragmentFactor
2650426591
TableDefinition vTableDefinition;
2650526592
FederationScheme vFederationScheme;
2650626593
FileGroupOrPartitionScheme vFileGroupOrPartitionScheme;
26594+
SchemaObjectName vCloneSource;
26595+
ScalarExpression vCloneTime;
2650726596
}
2650826597
: tCreate:Create Table vSchemaObjectName=schemaObjectThreePartName
2650926598
{
@@ -26534,6 +26623,19 @@ createTableStatement returns [CreateTableStatement vResult = this.FragmentFactor
2653426623
)
2653526624
|
2653626625
ctasCreateTableStatement[vResult]
26626+
|
26627+
As tClone:Identifier Of vCloneSource=schemaObjectThreePartName
26628+
{
26629+
Match(tClone, CodeGenerationSupporter.Clone);
26630+
vResult.CloneSource = vCloneSource;
26631+
}
26632+
(
26633+
tAt:Identifier vCloneTime=stringLiteral
26634+
{
26635+
Match(tAt, CodeGenerationSupporter.At);
26636+
vResult.ClonePointInTime = vCloneTime;
26637+
}
26638+
)?
2653726639
|
2653826640
As tFileTableOrGraphEdge:Identifier
2653926641
{
@@ -26735,6 +26837,9 @@ createTableOption returns [TableOption vResult]
2673526837
|
2673626838
{NextTokenMatches(CodeGenerationSupporter.Distribution)}?
2673726839
vResult = tableDistributionOption
26840+
|
26841+
{NextTokenMatches(CodeGenerationSupporter.Cluster)}?
26842+
vResult = clusterByTableOption
2673826843
|
2673926844
vResult = tableIndexOption
2674026845
|
@@ -26961,6 +27066,15 @@ tableRoundRobinDistributionPolicy returns [TableRoundRobinDistributionPolicy vRe
2696127066
}
2696227067
;
2696327068

27069+
clusterByTableOption returns [ClusterByTableOption vResult = this.FragmentFactory.CreateFragment<ClusterByTableOption>()]
27070+
: tCluster:Identifier By
27071+
{
27072+
Match(tCluster, CodeGenerationSupporter.Cluster);
27073+
UpdateTokenInfo(vResult, tCluster);
27074+
}
27075+
identifierColumnList[vResult, vResult.Columns]
27076+
;
27077+
2696427078
tableIndexOption returns [TableIndexOption vResult = FragmentFactory.CreateFragment<TableIndexOption>()]
2696527079
{
2696627080
TableIndexType vTableIndexType;
@@ -27898,6 +28012,7 @@ alterTableStatement returns [AlterTableStatement vResult = null]
2789828012
{NextTokenMatches(CodeGenerationSupporter.FileTableNamespace, 2)}?
2789928013
vResult=alterTableFileTableNamespaceStatement
2790028014
| vResult=alterTableSetStatement
28015+
| vResult=alterTableAddClusterByStatement
2790128016
)
2790228017
{
2790328018
// Update position later, because instantiation is lazy
@@ -28040,6 +28155,21 @@ alterTableSetStatement returns [AlterTableSetStatement vResult = FragmentFactory
2804028155
}
2804128156
;
2804228157

28158+
alterTableAddClusterByStatement returns [AlterTableAddClusterByStatement vResult = FragmentFactory.CreateFragment<AlterTableAddClusterByStatement>()]
28159+
{
28160+
ClusterByTableOption vClusterByOption;
28161+
}
28162+
: tAdd:Add LeftParenthesis vClusterByOption = clusterByTableOption
28163+
{
28164+
vResult.ClusterByOption = vClusterByOption;
28165+
UpdateTokenInfo(vResult, tAdd);
28166+
}
28167+
tRParen:RightParenthesis
28168+
{
28169+
UpdateTokenInfo(vResult, tRParen);
28170+
}
28171+
;
28172+
2804328173
tableOption returns [TableOption vResult = null]
2804428174
:
2804528175
{NextTokenMatches(CodeGenerationSupporter.LockEscalation)}?
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//------------------------------------------------------------------------------
2+
// <copyright file="SqlScriptGeneratorVisitor.AlterTableAddClusterByStatement.cs" company="Microsoft">
3+
// Copyright (c) Microsoft Corporation. All rights reserved.
4+
// </copyright>
5+
//------------------------------------------------------------------------------
6+
using Microsoft.SqlServer.TransactSql.ScriptDom;
7+
8+
namespace Microsoft.SqlServer.TransactSql.ScriptDom.ScriptGenerator
9+
{
10+
partial class SqlScriptGeneratorVisitor
11+
{
12+
public override void ExplicitVisit(AlterTableAddClusterByStatement node)
13+
{
14+
AlignmentPoint start = new AlignmentPoint();
15+
MarkAndPushAlignmentPoint(start);
16+
17+
GenerateAlterTableHead(node);
18+
19+
NewLineAndIndent();
20+
21+
GenerateKeyword(TSqlTokenType.Add);
22+
GenerateSpace();
23+
if (node.ClusterByOption != null)
24+
{
25+
GenerateSymbol(TSqlTokenType.LeftParenthesis);
26+
GenerateFragmentIfNotNull(node.ClusterByOption);
27+
GenerateSymbol(TSqlTokenType.RightParenthesis);
28+
}
29+
30+
PopAlignmentPoint();
31+
}
32+
}
33+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//------------------------------------------------------------------------------
2+
// <copyright file="SqlScriptGeneratorVisitor.ClusterByTableOption.cs" company="Microsoft">
3+
// Copyright (c) Microsoft Corporation. All rights reserved.
4+
// </copyright>
5+
//------------------------------------------------------------------------------
6+
using Microsoft.SqlServer.TransactSql.ScriptDom;
7+
8+
namespace Microsoft.SqlServer.TransactSql.ScriptDom.ScriptGenerator
9+
{
10+
partial class SqlScriptGeneratorVisitor
11+
{
12+
public override void ExplicitVisit(ClusterByTableOption node)
13+
{
14+
GenerateIdentifier(CodeGenerationSupporter.Cluster);
15+
GenerateSpaceAndKeyword(TSqlTokenType.By);
16+
GenerateSpace();
17+
GenerateParenthesisedCommaSeparatedList(node.Columns);
18+
}
19+
}
20+
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ public override void ExplicitVisit(CreateTableStatement node)
2020

2121
GenerateSpaceAndFragmentIfNotNull(node.SchemaObjectName);
2222

23+
if (node.CloneSource != null)
24+
{
25+
GenerateSpaceAndKeyword(TSqlTokenType.As);
26+
GenerateSpaceAndIdentifier(CodeGenerationSupporter.Clone);
27+
GenerateSpaceAndKeyword(TSqlTokenType.Of);
28+
GenerateSpaceAndFragmentIfNotNull(node.CloneSource);
29+
30+
if (node.ClonePointInTime != null)
31+
{
32+
GenerateSpaceAndIdentifier(CodeGenerationSupporter.At);
33+
GenerateSpaceAndFragmentIfNotNull(node.ClonePointInTime);
34+
}
35+
}
36+
2337
if (node.Definition != null)
2438
{
2539
List<TSqlFragment> columnsAndConstraintsAndIndexesAndPeriods = new List<TSqlFragment>();
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE TABLE dbo.Employee AS CLONE OF dbo.EmployeeUSA;
2+
3+
CREATE TABLE dbo.Employee AS CLONE OF dbo1.EmployeeUSA;
4+
5+
CREATE TABLE dbo.Employee AS CLONE OF dbo.EmployeeUSA AT '2023-05-23T14:24:10.325';
6+
7+
CREATE TABLE dbo.Employee AS CLONE OF dbo1.EmployeeUSA AT '2023-05-23T14:24:10';
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
CREATE TABLE Customers (
2+
CustomerID INT ,
3+
Name NVARCHAR (100)
4+
)
5+
WITH (CLUSTER BY (CustomerID));
6+
7+
8+
GO
9+
CREATE TABLE sales.Orders (
10+
OrderID INT ,
11+
CustomerID INT ,
12+
OrderDate DATE
13+
)
14+
WITH (CLUSTER BY (CustomerID, OrderDate), DISTRIBUTION = HASH(CustomerID));
15+
16+
17+
GO
18+
CREATE TABLE Inventory (
19+
ProductID INT ,
20+
ProductName VARCHAR (255),
21+
InStock BIT
22+
)
23+
WITH (CLUSTER BY (ProductID));
24+
25+
26+
GO
27+
ALTER TABLE Customers
28+
ADD (CLUSTER BY (CustomerID));
29+
30+
31+
GO
32+
ALTER TABLE sales.Orders
33+
ADD (CLUSTER BY (CustomerID, OrderDate));
34+
35+
36+
GO
37+
ALTER TABLE Inventory
38+
ADD (CLUSTER BY (ProductID));

0 commit comments

Comments
 (0)