Commit 96924d1
committed
JSON_OBJECTAGG support for OVER clause
## Description
JSON_OBJECTAGG supports windowed aggregate usage via the OVER (PARTITION BY ...) clause in SQL Server, but ScriptDOM was missing support for parsing and generating it. This PR adds OVER clause support for JSON_OBJECTAGG in the TSql170 parser and script generator.
SQL syntax now supported:
`sql
SELECT JSON_OBJECTAGG(CustomerName:OrderDate) OVER (PARTITION BY OrderDate) FROM Customers;
SELECT JSON_OBJECTAGG(CustomerName:OrderDate ABSENT ON NULL) OVER (PARTITION BY OrderDate) FROM Customers;
SELECT JSON_OBJECTAGG(CustomerName:OrderDate NULL ON NULL) OVER (PARTITION BY OrderDate) FROM Customers;
SELECT JSON_OBJECTAGG(CustomerName:OrderDate NULL ON NULL RETURNING JSON) OVER (PARTITION BY OrderDate) FROM Customers;
`
## Changes
- Updated JSON_OBJECTAGG production in TSql170.g to optionally parse an OVER clause
- Enhanced SqlScriptGeneratorVisitor.FunctionCall.cs to generate the OVER clause in the output
- Added new baseline and test scripts (JsonObjectAggOverClause170.sql in both Baselines170 and TestScripts)
## Additional Information
No AST changes were needed -- FunctionCall.OverClause already exists in Ast.xml.
The grammar uses overClauseNoOrderBy (not overClause) since, like regular aggregates (e.g., SUM() OVER (...)), the ORDER BY within the OVER clause is not applicable for JSON_OBJECTAGG as a windowed aggregate.
All older parsers (80-160) produce 4 errors each (one per test statement) since the JSON_OBJECTAGG key:value syntax is not recognized pre-TSql170.1 parent c6e10b2 commit 96924d1
File tree
5 files changed
+32
-0
lines changed- SqlScriptDom
- Parser/TSql
- ScriptDom/SqlServer/ScriptGenerator
- Test/SqlDom
- Baselines170
- TestScripts
5 files changed
+32
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33167 | 33167 | | |
33168 | 33168 | | |
33169 | 33169 | | |
| 33170 | + | |
33170 | 33171 | | |
33171 | 33172 | | |
33172 | 33173 | | |
| |||
33177 | 33178 | | |
33178 | 33179 | | |
33179 | 33180 | | |
| 33181 | + | |
| 33182 | + | |
| 33183 | + | |
| 33184 | + | |
| 33185 | + | |
| 33186 | + | |
33180 | 33187 | | |
33181 | 33188 | | |
33182 | 33189 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
| 74 | + | |
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
0 commit comments