Skip to content

Commit 49cb90e

Browse files
flatten-json-results (#548)
Summary: - Flatten `json` result sets. - Obviate `json_each` table-valued functions. - Added robot test `Select Paginated Star From Flattened Transformed JSON Response Body`. - Added robot test `Select Paginated Projection From Flattened Transformed JSON Response Body`. - Added robot test `Select Join of Flattened Paginated Projection From Transformed JSON and XML Response Bodies`. - Added robot test `Select View of Join of Flattened Paginated Projection From Transformed JSON and XML Response Bodies`. - Added robot test `Select Materialized View of Join of Flattened Paginated Projection From Transformed JSON and XML Response Bodies`.
1 parent a9cc164 commit 49cb90e

File tree

5 files changed

+633
-0
lines changed

5 files changed

+633
-0
lines changed

test/python/stackql_test_tooling/flask/azure/expectations.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,41 @@
11
[
2+
{
3+
"httpRequest": {
4+
"headers": {
5+
"Accept": [ "application/json" ]
6+
},
7+
"method": "GET",
8+
"path": "/subscriptions/1111/providers/Microsoft.Network/virtualNetworks/",
9+
"queryStringParameters" : {
10+
"api-version" : [ "2023-11-01" ],
11+
"$skiptoken": [ "0011" ]
12+
}
13+
},
14+
"httpResponse": {
15+
"template": "virtual-networks-list-all-02-paginated-02.json",
16+
"headers": {
17+
"Content-Type": "application/json; charset=utf-8"
18+
}
19+
}
20+
},
21+
{
22+
"httpRequest": {
23+
"headers": {
24+
"Accept": [ "application/json" ]
25+
},
26+
"method": "GET",
27+
"path": "/subscriptions/1111/providers/Microsoft.Network/virtualNetworks/",
28+
"queryStringParameters" : {
29+
"api-version" : [ "2023-11-01" ]
30+
}
31+
},
32+
"httpResponse": {
33+
"template": "virtual-networks-list-all-02-paginated-01.json",
34+
"headers": {
35+
"Content-Type": "application/json; charset=utf-8"
36+
}
37+
}
38+
},
239
{
340
"httpRequest": {
441
"headers": {
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"value": [
3+
{
4+
"id": "/subscriptions/1111/resourceGroups/rg1/providers/Microsoft.Network/virtualNetworks/vnet1",
5+
"name": "vnet1",
6+
"type": "Microsoft.Network/virtualNetworks",
7+
"location": "westus",
8+
"properties": {
9+
"addressSpace": {
10+
"addressPrefixes": [
11+
"10.0.0.0/8"
12+
]
13+
},
14+
"dhcpOptions": {
15+
"dnsServers": []
16+
},
17+
"subnets": [
18+
{
19+
"id": "/subscriptions/1111/resourceGroups/rg1/providers/Microsoft.Network/virtualNetworks/vnet1/subnets/test-1",
20+
"name": "test-1",
21+
"properties": {
22+
"addressPrefix": "10.0.0.0/24",
23+
"provisioningState": "Succeeded"
24+
}
25+
},
26+
{
27+
"id": "/subscriptions/1111/resourceGroups/rg1/providers/Microsoft.Network/virtualNetworks/vnet1/subnets/test-2",
28+
"name": "test-2",
29+
"properties": {
30+
"addressPrefix": "10.0.1.0/24",
31+
"provisioningState": "Succeeded"
32+
}
33+
}
34+
],
35+
"virtualNetworkPeerings": [],
36+
"provisioningState": "Succeeded"
37+
}
38+
},
39+
{
40+
"id": "/subscriptions/1111/resourceGroups/rg2/providers/Microsoft.Network/virtualNetworks/vnet2",
41+
"name": "vnet2",
42+
"type": "Microsoft.Network/virtualNetworks",
43+
"location": "westus",
44+
"properties": {
45+
"addressSpace": {
46+
"addressPrefixes": [
47+
"10.0.0.0/16"
48+
]
49+
},
50+
"dhcpOptions": {
51+
"dnsServers": [
52+
"8.8.8.8"
53+
]
54+
},
55+
"subnets": [],
56+
"virtualNetworkPeerings": [],
57+
"provisioningState": "Succeeded"
58+
}
59+
}
60+
],
61+
"nextLink": "{{ scheme }}://{{ host_name }}{% if port is defined %}:{{ port }}{% endif %}/subscriptions/1111/providers/Microsoft.Network/virtualNetworks/?api-version=2023-11-01&$skiptoken=0011"
62+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"value": [
3+
{
4+
"id": "/subscriptions/1111/resourceGroups/rg1/providers/Microsoft.Network/virtualNetworks/vnet1",
5+
"name": "vnet3",
6+
"type": "Microsoft.Network/virtualNetworks",
7+
"location": "australiasoutheast",
8+
"properties": {
9+
"addressSpace": {
10+
"addressPrefixes": [
11+
"10.0.0.0/8"
12+
]
13+
},
14+
"dhcpOptions": {
15+
"dnsServers": []
16+
},
17+
"subnets": [
18+
{
19+
"id": "/subscriptions/1111/resourceGroups/rg1/providers/Microsoft.Network/virtualNetworks/vnet3/subnets/test-1",
20+
"name": "test-1",
21+
"properties": {
22+
"addressPrefix": "10.0.0.0/24",
23+
"provisioningState": "Succeeded"
24+
}
25+
},
26+
27+
{
28+
"id": "/subscriptions/1111/resourceGroups/rg1/providers/Microsoft.Network/virtualNetworks/vnet3/subnets/test-2",
29+
"name": "test-2",
30+
"properties": {
31+
"addressPrefix": "10.0.1.0/24",
32+
"provisioningState": "Succeeded"
33+
}
34+
}
35+
],
36+
"virtualNetworkPeerings": [],
37+
"provisioningState": "Succeeded"
38+
}
39+
},
40+
{
41+
"id": "/subscriptions/1111/resourceGroups/rg2/providers/Microsoft.Network/virtualNetworks/vnet2",
42+
"name": "vnet4",
43+
"type": "Microsoft.Network/virtualNetworks",
44+
"location": "australiasoutheast",
45+
"properties": {
46+
"addressSpace": {
47+
"addressPrefixes": [
48+
"10.0.0.0/16"
49+
]
50+
},
51+
"dhcpOptions": {
52+
"dnsServers": [
53+
"8.8.8.8"
54+
]
55+
},
56+
"subnets": [],
57+
"virtualNetworkPeerings": [],
58+
"provisioningState": "Succeeded"
59+
}
60+
}
61+
]
62+
}

test/registry/src/azure/v0.1.0/services/network.yaml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,31 @@ components:
197197
schema:
198198
type: string
199199
schemas:
200+
VNetListingFlattened:
201+
type: object
202+
properties:
203+
id:
204+
type: string
205+
description: Resource ID.
206+
name:
207+
type: string
208+
description: Resource name.
209+
type:
210+
type: string
211+
description: Resource type.
212+
location:
213+
type: string
214+
description: Resource location.
215+
provisioning_state:
216+
type: string
217+
subnet_id:
218+
type: string
219+
subnet_name:
220+
type: string
221+
subnet_address_prefix:
222+
type: string
223+
subnet_provisioning_state:
224+
type: string
200225
VNetListingTransformed:
201226
type: object
202227
properties:
@@ -245,6 +270,18 @@ components:
245270
type: string
246271
description: The URL to get the next set of results.
247272
description: Response for ListVNet API service call.
273+
VNetListingsFlattened:
274+
type: object
275+
properties:
276+
line_items:
277+
type: array
278+
items:
279+
$ref: '#/components/schemas/VNetListingFlattened'
280+
description: List of virtual networks.
281+
next_link:
282+
type: string
283+
description: The URL to get the next set of results.
284+
description: Response for ListVNet API service call.
248285
NetworkManagerConnection:
249286
description: The Network Manager Connection resource
250287
properties:
@@ -25342,6 +25379,99 @@ components:
2534225379
insert: []
2534325380
update: []
2534425381
delete: []
25382+
virtual_networks_flattened:
25383+
id: azure.network.virtual_networks
25384+
name: virtual_networks
25385+
title: virtual_networks
25386+
methods:
25387+
list_all_flattened:
25388+
config:
25389+
pagination:
25390+
requestToken:
25391+
key: ''
25392+
location: request
25393+
responseToken:
25394+
key: $.next_link
25395+
location: body
25396+
operation:
25397+
$ref: '#/paths/~1subscriptions~1{subscriptionId}~1providers~1Microsoft.Network~1virtualNetworks~1?api-version=2023-11-01/get'
25398+
response:
25399+
mediaType: application/json
25400+
openAPIDocKey: '200'
25401+
overrideMediaType: application/json
25402+
objectKey: $.line_items
25403+
schema_override:
25404+
$ref: '#/components/schemas/VNetListingsFlattened'
25405+
transform:
25406+
body: >
25407+
{
25408+
{{- with index . "nextLink" }}
25409+
"next_link": {{printf "%q" .}},
25410+
{{- end }}
25411+
"line_items": [
25412+
{{- $items := index . "value" -}}
25413+
{{- $first := true -}}
25414+
{{- if eq (printf "%T" $items) "map[string]interface {}" }}
25415+
{{template "rows" $items}}
25416+
{{- else }}
25417+
{{- range $vnet := $items }}
25418+
{{- if not $first}},{{end}}
25419+
{{template "rows" $vnet}}
25420+
{{- $first = false }}
25421+
{{- end }}
25422+
{{- end }}
25423+
]
25424+
}
25425+
{{define "rows"}}
25426+
{{- $vnet := . }}
25427+
{{- $subnets := index $vnet "properties" "subnets" }}
25428+
{{- if eq (printf "%T" $subnets) "map[string]interface {}" }}
25429+
{{template "row" $vnet}}
25430+
{{- else if eq (printf "%T" $subnets) "[]interface {}" }}
25431+
{{- if eq (len $subnets) 0 }}
25432+
{{template "row" $vnet}}
25433+
{{- else }}
25434+
{{- range $i, $s := $subnets }}
25435+
{{- if $i}},{{end}}
25436+
{
25437+
"id": {{printf "%q" (index $vnet "id")}},
25438+
"name": {{printf "%q" (index $vnet "name")}},
25439+
"type": {{with index $vnet "type"}}{{printf "%q" .}}{{else}}null{{end}},
25440+
"location": {{printf "%q" (index $vnet "location")}},
25441+
"address_prefixes": {{with index $vnet "properties" "addressSpace" "addressPrefixes"}}{{printf "%q" .}}{{else}}[]{{end}},
25442+
"provisioning_state": {{with index $vnet "properties" "provisioningState"}}{{printf "%q" .}}{{else}}null{{end}},
25443+
"subnet_id": {{with $s}}{{printf "%q" (index . "id")}}{{else}}null{{end}},
25444+
"subnet_name": {{with $s}}{{printf "%q" (index . "name")}}{{else}}null{{end}},
25445+
"subnet_address_prefix": {{with $s}}{{with index . "properties" "addressPrefix"}}{{printf "%q" .}}{{else}}null{{end}}{{else}}null{{end}},
25446+
"subnet_provisioning_state": {{with $s}}{{with index . "properties" "provisioningState"}}{{printf "%q" .}}{{else}}null{{end}}{{else}}null{{end}}
25447+
}
25448+
{{- end }}
25449+
{{- end }}
25450+
{{- else }}
25451+
{{template "row" $vnet}}
25452+
{{- end }}
25453+
{{end}}
25454+
{{define "row"}}
25455+
{
25456+
"id": {{printf "%q" (index . "id")}},
25457+
"name": {{printf "%q" (index . "name")}},
25458+
"type": {{with index . "type"}}{{printf "%q" .}}{{else}}null{{end}},
25459+
"location": {{printf "%q" (index . "location")}},
25460+
"address_prefixes": {{with index . "properties" "addressSpace" "addressPrefixes"}}{{printf "%q" .}}{{else}}[]{{end}},
25461+
"provisioning_state": {{with index . "properties" "provisioningState"}}{{printf "%q" .}}{{else}}null{{end}},
25462+
"subnet_id": null,
25463+
"subnet_name": null,
25464+
"subnet_address_prefix": null,
25465+
"subnet_provisioning_state": null
25466+
}
25467+
{{end}}
25468+
type: 'golang_template_json_v0.1.0'
25469+
sqlVerbs:
25470+
select:
25471+
- $ref: '#/components/x-stackQL-resources/virtual_networks_flattened/methods/list_all_flattened'
25472+
insert: []
25473+
update: []
25474+
delete: []
2534525475
virtual_networks:
2534625476
id: azure.network.virtual_networks
2534725477
name: virtual_networks

0 commit comments

Comments
 (0)