@@ -41,17 +41,17 @@ const data = [
41
41
table . delete ( ) ;
42
42
} ) ;
43
43
44
- test ( "Default aggregates are omitted " , async function ( ) {
44
+ test ( "Non-default aggregates are provided " , async function ( ) {
45
45
const table = await perspective . table ( data ) ;
46
46
const view = await table . view ( {
47
47
group_by : [ "y" ] ,
48
48
columns : [ "x" , "z" ] ,
49
- aggregates : { x : "sum " , z : "count " } ,
49
+ aggregates : { x : "count " , z : "sum " } ,
50
50
} ) ;
51
51
52
52
const config = await view . get_config ( ) ;
53
53
expect ( config ) . toEqual ( {
54
- aggregates : { } ,
54
+ aggregates : { x : "count" , z : "sum" } ,
55
55
columns : [ "x" , "z" ] ,
56
56
expressions : { } ,
57
57
filter : [ ] ,
@@ -64,18 +64,18 @@ const data = [
64
64
table . delete ( ) ;
65
65
} ) ;
66
66
67
- test ( "Non-default aggregates are provided" , async function ( ) {
67
+ test ( "Compound aggregates are provided" , async function ( ) {
68
68
const table = await perspective . table ( data ) ;
69
69
const view = await table . view ( {
70
70
group_by : [ "y" ] ,
71
- columns : [ "x" , "z" ] ,
72
- aggregates : { x : "count ", z : "sum" } ,
71
+ columns : [ "x" ] ,
72
+ aggregates : { x : [ "weighted mean ", [ "y" ] ] } ,
73
73
} ) ;
74
74
75
75
const config = await view . get_config ( ) ;
76
76
expect ( config ) . toEqual ( {
77
- aggregates : { x : "count ", z : "sum" } ,
78
- columns : [ "x" , "z" ] ,
77
+ aggregates : { x : [ "weighted mean ", [ "y" ] ] } ,
78
+ columns : [ "x" ] ,
79
79
expressions : { } ,
80
80
filter : [ ] ,
81
81
group_by : [ "y" ] ,
@@ -87,17 +87,55 @@ const data = [
87
87
table . delete ( ) ;
88
88
} ) ;
89
89
90
- test ( "Mixed aggregates are provided and omitted" , async function ( ) {
90
+ test ( "Expression aggregates are provided" , async function ( ) {
91
+ const table = await perspective . table ( data ) ;
92
+ const view = await table . view ( {
93
+ group_by : [ "y" ] ,
94
+ columns : [ "x" , "z" , "new" ] ,
95
+ expressions : { new : `"x" + 1` } ,
96
+ aggregates : { x : [ "weighted mean" , [ "y" ] ] } ,
97
+ } ) ;
98
+
99
+ const config = await view . get_config ( ) ;
100
+ expect ( config ) . toEqual ( {
101
+ aggregates : {
102
+ new : "sum" ,
103
+ z : "count" ,
104
+ x : [ "weighted mean" , [ "y" ] ] ,
105
+ } ,
106
+ columns : [ "x" , "z" , "new" ] ,
107
+ expressions : { new : `"x" + 1` } ,
108
+ filter : [ ] ,
109
+ group_by : [ "y" ] ,
110
+ sort : [ ] ,
111
+ split_by : [ ] ,
112
+ } ) ;
113
+
114
+ view . delete ( ) ;
115
+ table . delete ( ) ;
116
+ } ) ;
117
+
118
+ // The `aggregates` field was omitted entirely in `3.0.0` until `3.9.0`
119
+ // (due to a bug introduced by an inebriated office drone). Prior to
120
+ // this, columns were sleectively omitted from the result if they were
121
+ // _non-default_ (to shorten JSON encoding). For example if a `"flaot"`
122
+ // column was anything other than `"sum"`.
123
+ //
124
+ // In revisiting this broken feature, I've updated the behavior to
125
+ // reflect a less certain view of what is "default", and output all
126
+ // columns which need aggregates. These tests preserve the `2.x`
127
+ // behavior.
128
+ test . skip ( "Default aggregates are omitted" , async function ( ) {
91
129
const table = await perspective . table ( data ) ;
92
130
const view = await table . view ( {
93
131
group_by : [ "y" ] ,
94
132
columns : [ "x" , "z" ] ,
95
- aggregates : { x : "sum" , z : "mean " } ,
133
+ aggregates : { x : "sum" , z : "count " } ,
96
134
} ) ;
97
135
98
136
const config = await view . get_config ( ) ;
99
137
expect ( config ) . toEqual ( {
100
- aggregates : { z : "mean" } ,
138
+ aggregates : { } ,
101
139
columns : [ "x" , "z" ] ,
102
140
expressions : { } ,
103
141
filter : [ ] ,
@@ -110,17 +148,17 @@ const data = [
110
148
table . delete ( ) ;
111
149
} ) ;
112
150
113
- test ( "Compound aggregates are provided", async function ( ) {
151
+ test . skip ( "Mixed aggregates are provided and omitted ", async function ( ) {
114
152
const table = await perspective . table ( data ) ;
115
153
const view = await table . view ( {
116
154
group_by : [ "y" ] ,
117
155
columns : [ "x" , "z" ] ,
118
- aggregates : { x : [ "weighted mean ", [ "y" ] ] } ,
156
+ aggregates : { x : "sum ", z : "mean" } ,
119
157
} ) ;
120
158
121
159
const config = await view . get_config ( ) ;
122
160
expect ( config ) . toEqual ( {
123
- aggregates : { x : [ "weighted mean", [ "y" ] ] } ,
161
+ aggregates : { z : " mean" } ,
124
162
columns : [ "x" , "z" ] ,
125
163
expressions : { } ,
126
164
filter : [ ] ,
0 commit comments