Skip to content

Commit 8367b6e

Browse files
authored
Sync Repos: Bringing commits for release 161.9142.1 (#92)
* Merged PR 1450917: Adding CTAS support to the 160Parser This change adds the ability to parse the CTAS statement which has the "Create Table TblName AS Select" format. So far we support "Create Table tableName With(Distribution) AS Select...) syntax only. This change fixes the syntax error at Select and allows the DW users to run the sql queries with the syntax. ---- #### AI description (iteration 1) #### PR Classification New feature: Adding support for CTAS (Create Table As Select) statements in the 160Parser. #### PR Summary This pull request introduces support for parsing CTAS statements in the TSql160Parser and includes corresponding unit tests. - Added `CreateCTASParser160Test` method in `Test/SqlDom/TSqlParserTest.cs` to validate CTAS statement parsing. - Updated `TSql160.g` to handle `As` keyword for CTAS statements. - Minor import addition in `Test/SqlDom/PhaseOneParserTest.cs`. * Merged PR 1446620: Add code coverage configuration file This is an automatically generated Pull Request which adds a code coverage configuration file - azurepipelines-coverage.yml needed to enable code coverage for this repository. For more information, please refer to the [documentation](https://learn.microsoft.com/en-us/azure/devops/pipelines/test/codecoverage-for-pullrequests?view=azure-devops#configuring-coverage-settings). If you have any questions or need support, please reach out to [email protected]. --- For feedback or questions about this PR, please find the contact information in the above description. If none exists, please contact the [Gardener team](mailto:[email protected]) to help route. --- This change was automatically generated by [1ES Gardener](https://eng.ms/docs/cloud-ai-platform/devdiv/one-engineering-system-1es/1es-docs/gardener/1es-gardener) (a [MerlinBot](https://aka.ms/MerlinBot) extension) which is an initiative by the 1ES team to help repos stay up-to-date with latest tools, features, and best practices. * [Security] Update .NET SDK to latest patch version This change updates to the latest patch version for the .NET SDK which contains the latest security fixes. Note that your global.json does configure `rollForward`, however roll forward will allow for the build to pass when using a different SDK. So, if locally you have a newer patch version installed it will pass, without the `rollforward` it will fail. CI in many cases installs exactly what is in the global.json, so making sure that your build requires the latest patch version ensures that CI is compliant with those vulnerabilities. Release notes: * [6.0.33](https://github.com/dotnet/core/blob/main/release-notes/6.0/6.0.33/6.0.33.md) --- For feedback or questions about this PR, please contact the [Gardener team](mailto:[email protected]). --- This change was automatically generated by [1ES Gardener](https://eng.ms/docs/cloud-ai-platform/devdiv/one-engineering-system-1es/1es-docs/gardener/1es-gardener) (a [MerlinBot](https://aka.ms/MerlinBot) extension) which is an initiative by the 1ES team to help repos stay up-to-date with latest tools, features, and best practices. * Merged PR 1451812: Adds release notes to 191.9142.1 Adds release notes to 191.9142.1, adds the CTAS support to 160 Parser and SDK update ---- #### AI description (iteration 1) #### PR Classification Documentation #### PR Summary This pull request adds release notes for version 161.9142.1. - `release-notes/161.91/161.9142.1.md`: Introduces release notes detailing target platform support, updated dependencies, new features, fixed issues, and known issues. --------- Co-authored-by: MerlinBot <MerlinBot>
1 parent d84cc30 commit 8367b6e

File tree

6 files changed

+100
-1
lines changed

6 files changed

+100
-1
lines changed

SqlScriptDom/Parser/TSql/TSql160.g

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26510,6 +26510,11 @@ createTableStatement returns [CreateTableStatement vResult = this.FragmentFactor
2651026510
}
2651126511
UpdateTokenInfo(vResult, tFileTableOrGraphEdge);
2651226512
}
26513+
|
26514+
As
26515+
{
26516+
vResult.SelectStatement = selectStatement(SubDmlFlags.None);
26517+
}
2651326518
)
2651426519

2651526520
// Default is not used as a keyword after on or textimage_on (even though it is a keyword)

Test/SqlDom/PhaseOneParserTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
// </copyright>
55
//------------------------------------------------------------------------------
66

7+
using System.Collections.Generic;
78
using System.IO;
89
using Microsoft.SqlServer.TransactSql.ScriptDom;
910
using Microsoft.VisualStudio.TestTools.UnitTesting;
11+
using Newtonsoft.Json.Linq;
1012
using SqlStudio.Tests.AssemblyTools.TestCategory;
1113

1214
namespace SqlStudio.Tests.UTSqlScriptDom

Test/SqlDom/TSqlParserTest.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,66 @@ COPY INTO #Test
533533
Console.WriteLine($"Error {error.Number} Message {error.Message}");
534534
}
535535
Assert.AreEqual(0, errors.Count);
536+
}
537+
538+
/// <summary>
539+
/// This test validates the generation of table and stored procedure that contains CTAS statements
540+
/// </summary>
541+
[TestMethod]
542+
[Priority(0)]
543+
[SqlStudioTestCategory(Category.UnitTest)]
544+
public void CreateCTASParser160Test()
545+
{
546+
TSql160Parser parser = new TSql160Parser(true);
547+
StringReader reader = new StringReader(@"
548+
-- CTAS
549+
CREATE TABLE TestTable AS
550+
SELECT customername, contactname
551+
FROM customers
552+
GO;
553+
554+
-- CTAS in stored procedure - 'create table As Select *'
555+
CREATE PROCEDURE test_proc_withCreateSelect
556+
AS
557+
BEGIN
558+
CREATE TABLE Test1
559+
AS
560+
SELECT * FROM Test
561+
END
562+
GO;
563+
564+
-- CTAS in stored procedure - 'create table With( ) As Select'
565+
CREATE PROCEDURE test_proc_withCreateWith
566+
AS
567+
BEGIN
568+
CREATE TABLE [dbo].[ReplicateToHash_ID]
569+
WITH(DISTRIBUTION = Hash(id))
570+
AS SELECT ID FROM [dbo].[REPLICATE_TEST_UPDATE]
571+
END
572+
GO;
573+
574+
-- CTAS in stored procedure - 'create table as Select columnsNames'
575+
CREATE PROCEDURE test_proc_withSelectColumns
576+
AS
577+
BEGIN
578+
CREATE TABLE Test1
579+
AS
580+
SELECT Id AS ID,
581+
person AS Person
582+
FROM Test
583+
END
584+
GO;");
585+
586+
var fragments = parser.Parse(reader, out IList<ParseError> errors);
587+
588+
Assert.IsTrue(errors.Count == 0);
589+
Assert.AreEqual(4, ((TSqlScript)fragments).Batches.Count);
590+
foreach(TSqlBatch batch in ((TSqlScript)fragments).Batches)
591+
{
592+
TSqlStatement statement = batch.Statements[0];
593+
Assert.IsNotNull(statement);
594+
Assert.IsTrue(statement is CreateTableStatement || statement is CreateProcedureStatement);
595+
}
536596
}
537597

538598
void VerifyTokenTypesAndOffsets(IList<TSqlParserToken> tokens, TSqlTokenType[] tokenTypes, int[] zeroBasedTokenOffsets, int offsetShift)

azurepipelines-coverage.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
coverage:
2+
status: # Code coverage status will be posted to pull requests based on targets defined below.
3+
comments: on # Off by default. When on, details about coverage for each file changed will be posted as a pull request comment.
4+
diff: # diff coverage is code coverage only for the lines changed in a pull request.
5+
target: 50% # set this to a desired %. Default is 50%

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "6.0.424",
3+
"version": "6.0.425",
44
"rollForward": "latestMajor"
55
},
66
"msbuild-sdks": {

release-notes/161.91/161.9142.1.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Release Notes
2+
3+
## Microsoft.SqlServer.TransactSql.ScriptDom 161.9142.1
4+
This update brings the below changes over the previous release:
5+
6+
### Target Platform Support
7+
8+
* .NET Framework 4.6.2 (Windows x86, Windows x64)
9+
* .NET 6 (Windows x86, Windows x64, Linux, macOS)
10+
* .NET Standard 2.0+ (Windows x86, Windows x64, Linux, macOS)
11+
12+
### Dependencies
13+
* Updates.NET SDK to latest patch version 6.0.425
14+
15+
#### .NET Framework
16+
#### .NET Core
17+
#### .NET Standard
18+
19+
### New Features
20+
21+
22+
### Fixed
23+
* Adds support for CTAS syntax to 160 TSqlParser
24+
25+
### Changes
26+
27+
### Known Issues

0 commit comments

Comments
 (0)