Skip to content

Commit 092a97c

Browse files
authored
fixing a bug with parsing json value with multi name columns (#164)
1 parent 44e6100 commit 092a97c

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

SqlScriptDom/Parser/TSql/TSql170.g

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32520,33 +32520,36 @@ jsonKeyValueExpression returns [JsonKeyValue vResult = FragmentFactory.CreateFra
3252032520
{
3252132521
ScalarExpression vKey;
3252232522
ScalarExpression vValue;
32523+
MultiPartIdentifier vMultiPartIdentifier = null;
3252332524
}
3252432525
:
3252532526
(
32526-
vKey=expression
32527-
{
32528-
vResult.JsonKeyName=vKey;
32529-
}
32530-
Colon vValue=expression
32531-
{
32532-
vResult.JsonValue=vValue;
32533-
}
32534-
32535-
|
32536-
32537-
label:Label
32527+
(vMultiPartIdentifier=multiPartIdentifier[2] Dot)? label:Label
3253832528
{
3253932529
var identifier = this.FragmentFactory.CreateFragment<Identifier>();
32540-
var multiPartIdentifier = this.FragmentFactory.CreateFragment<MultiPartIdentifier>();
32530+
if (vMultiPartIdentifier == null)
32531+
{
32532+
vMultiPartIdentifier = this.FragmentFactory.CreateFragment<MultiPartIdentifier>();
32533+
}
3254132534
var columnRef = this.FragmentFactory.CreateFragment<ColumnReferenceExpression>();
32542-
CreateIdentifierFromLabel(label, identifier, multiPartIdentifier);
32543-
columnRef.MultiPartIdentifier = multiPartIdentifier;
32535+
CreateIdentifierFromLabel(label, identifier, vMultiPartIdentifier);
32536+
32537+
columnRef.MultiPartIdentifier = vMultiPartIdentifier;
3254432538
vResult.JsonKeyName=columnRef;
3254532539
}
3254632540
vValue=expression
3254732541
{
3254832542
vResult.JsonValue=vValue;
3254932543
}
32544+
|
32545+
vKey=expression
32546+
{
32547+
vResult.JsonKeyName=vKey;
32548+
}
32549+
Colon vValue=expression
32550+
{
32551+
vResult.JsonValue=vValue;
32552+
}
3255032553
)
3255132554
;
3255232555

Test/SqlDom/Baselines170/JsonFunctionTests170.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,10 @@ GO
132132
CREATE VIEW dbo.jsonfunctest
133133
AS
134134
SELECT JSON_OBJECTAGG(c1:c2) AS jsoncontents
135-
FROM (VALUES ('key1', 'c'), ('key2', 'b'), ('key3', 'a')) AS t(c1, c2);
135+
FROM (VALUES ('key1', 'c'), ('key2', 'b'), ('key3', 'a')) AS t(c1, c2);
136+
137+
GO
138+
SELECT TOP (5) c.object_id,
139+
JSON_OBJECTAGG(c.name:c.column_id) AS columns
140+
FROM sys.columns AS c
141+
GROUP BY c.object_id;

Test/SqlDom/Only170SyntaxTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using Microsoft.SqlServer.TransactSql.ScriptDom;
22
using Microsoft.VisualStudio.TestTools.UnitTesting;
33
using SqlStudio.Tests.AssemblyTools.TestCategory;
4+
using System;
45
using System.Collections.Generic;
6+
using System.IO;
57

68
namespace SqlStudio.Tests.UTSqlScriptDom
79
{
@@ -17,7 +19,7 @@ public partial class SqlDomTests
1719
new ParserTest170("CreateColumnStoreIndexTests170.sql", nErrors80: 3, nErrors90: 3, nErrors100: 3, nErrors110: 3, nErrors120: 3, nErrors130: 0, nErrors140: 0, nErrors150: 0, nErrors160: 0),
1820
new ParserTest170("RegexpTests170.sql", nErrors80: 0, nErrors90: 0, nErrors100: 0, nErrors110: 0, nErrors120: 0, nErrors130: 0, nErrors140: 0, nErrors150: 0, nErrors160: 0),
1921
new ParserTest170("AiGenerateChunksTests170.sql", nErrors80: 19, nErrors90: 16, nErrors100: 15, nErrors110: 15, nErrors120: 15, nErrors130: 15, nErrors140: 15, nErrors150: 15, nErrors160: 15),
20-
new ParserTest170("JsonFunctionTests170.sql", nErrors80: 10, nErrors90: 8, nErrors100: 35, nErrors110: 35, nErrors120: 35, nErrors130: 35, nErrors140: 35, nErrors150: 35, nErrors160: 35),
22+
new ParserTest170("JsonFunctionTests170.sql", nErrors80: 11, nErrors90: 8, nErrors100: 36, nErrors110: 36, nErrors120: 36, nErrors130: 36, nErrors140: 36, nErrors150: 36, nErrors160: 36),
2123
new ParserTest170("AiGenerateEmbeddingsTests170.sql", nErrors80: 12, nErrors90: 9, nErrors100: 9, nErrors110: 9, nErrors120: 9, nErrors130: 9, nErrors140: 9, nErrors150: 9, nErrors160: 9),
2224
new ParserTest170("CreateExternalModelStatementTests170.sql", nErrors80: 2, nErrors90: 2, nErrors100: 2, nErrors110: 2, nErrors120: 2, nErrors130: 4, nErrors140: 4, nErrors150: 4, nErrors160: 4),
2325
new ParserTest170("AlterExternalModelStatementTests170.sql", nErrors80: 2, nErrors90: 2, nErrors100: 2, nErrors110: 2, nErrors120: 2, nErrors130: 5, nErrors140: 5, nErrors150: 5, nErrors160: 5),

Test/SqlDom/TestScripts/JsonFunctionTests170.sql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,9 @@ CREATE VIEW dbo.jsonfunctest AS
127127
SELECT JSON_OBJECTAGG( c1:c2 ) as jsoncontents
128128
FROM (
129129
VALUES('key1', 'c'), ('key2', 'b'), ('key3','a')
130-
) AS t(c1, c2);
130+
) AS t(c1, c2);
131+
132+
GO
133+
SELECT TOP(5) c.object_id, JSON_OBJECTAGG(c.name:c.column_id) AS columns
134+
FROM sys.columns AS c
135+
GROUP BY c.object_id;

0 commit comments

Comments
 (0)