You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -19,10 +19,12 @@ If we need to group variables according to some criteria, we can create an aggre
19
19
20
20
A group by is composed of a _focus_, a _template_, and a _group_ together with a query.
21
21
22
-
We will demonstrate this with the following query:
22
+
### Single Variable Template (Flat Array)
23
+
24
+
When grouping a single variable, the template produces a **flat array** of values:
23
25
24
26
```javascript
25
-
let v =Vars("person", "label", "eyes", "group");
27
+
let v =Vars("person", "label", "eyes", "group", "member");
26
28
limit(1)
27
29
.group_by(
28
30
"eyes",
@@ -35,7 +37,7 @@ limit(1)
35
37
36
38
The first argument, here `"eyes"` refers to the eyes variable, and is the variable around which to form the group, the _focus_.
37
39
38
-
The second `["label"]` is the _template_, which refers to the variable `"label"`. The template will be those things grouped under the first variable.
40
+
The second `["label"]` is the _template_, which refers to the variable `"label"`. Since the template contains only one variable, the results will be collected as a **flat array**.
39
41
40
42
The third variable `v.group`, is the _group_ variable, which will include groups of templates for each set of solutions which shares a _focus_.
41
43
@@ -48,48 +50,133 @@ This raw query output will be:
48
50
"@value": "black"
49
51
},
50
52
"group": [
51
-
[{
53
+
{
52
54
"@type": "xsd:string",
53
55
"@value": "Greedo"
54
-
}],
55
-
[{
56
+
},
57
+
{
56
58
"@type": "xsd:string",
57
59
"@value": "Nien Nunb"
58
-
}],
59
-
[{
60
+
},
61
+
{
60
62
"@type": "xsd:string",
61
63
"@value": "Gasgano"
62
-
}],
63
-
[{
64
+
},
65
+
{
64
66
"@type": "xsd:string",
65
67
"@value": "Kit Fisto"
66
-
}],
67
-
[{
68
+
},
69
+
{
68
70
"@type": "xsd:string",
69
71
"@value": "Plo Koon"
70
-
}],
71
-
[{
72
+
},
73
+
{
72
74
"@type": "xsd:string",
73
75
"@value": "Lama Su"
74
-
}],
75
-
[{
76
+
},
77
+
{
76
78
"@type": "xsd:string",
77
79
"@value": "Taun We"
78
-
}],
79
-
[{
80
+
},
81
+
{
80
82
"@type": "xsd:string",
81
83
"@value": "Shaak Ti"
82
-
}],
83
-
[{
84
+
},
85
+
{
84
86
"@type": "xsd:string",
85
87
"@value": "Tion Medon"
86
-
}],
87
-
[{
88
+
},
89
+
{
88
90
"@type": "xsd:string",
89
91
"@value": "BB8"
90
-
}]
92
+
}
93
+
],
94
+
"label": null,
95
+
"person": null
96
+
}
97
+
```
98
+
99
+
Notice how each result is a flat array of values, not nested arrays. To make this into individual solutions, use the `member` operator: `member(v.member, v.group)`, which will expand the `group` array into individual elements in the v.member variable.
100
+
101
+
### Multiple Variable Template (Array of Tuples)
102
+
103
+
When grouping multiple variables, the template produces an **array of tuples**:
0 commit comments