@@ -41,17 +41,17 @@ const data = [
4141 table . delete ( ) ;
4242 } ) ;
4343
44- test ( "Default aggregates are omitted " , async function ( ) {
44+ test ( "Non-default aggregates are provided " , async function ( ) {
4545 const table = await perspective . table ( data ) ;
4646 const view = await table . view ( {
4747 group_by : [ "y" ] ,
4848 columns : [ "x" , "z" ] ,
49- aggregates : { x : "sum " , z : "count " } ,
49+ aggregates : { x : "count " , z : "sum " } ,
5050 } ) ;
5151
5252 const config = await view . get_config ( ) ;
5353 expect ( config ) . toEqual ( {
54- aggregates : { } ,
54+ aggregates : { x : "count" , z : "sum" } ,
5555 columns : [ "x" , "z" ] ,
5656 expressions : { } ,
5757 filter : [ ] ,
@@ -64,18 +64,18 @@ const data = [
6464 table . delete ( ) ;
6565 } ) ;
6666
67- test ( "Non-default aggregates are provided" , async function ( ) {
67+ test ( "Compound aggregates are provided" , async function ( ) {
6868 const table = await perspective . table ( data ) ;
6969 const view = await table . view ( {
7070 group_by : [ "y" ] ,
71- columns : [ "x" , "z" ] ,
72- aggregates : { x : "count ", z : "sum" } ,
71+ columns : [ "x" ] ,
72+ aggregates : { x : [ "weighted mean ", [ "y" ] ] } ,
7373 } ) ;
7474
7575 const config = await view . get_config ( ) ;
7676 expect ( config ) . toEqual ( {
77- aggregates : { x : "count ", z : "sum" } ,
78- columns : [ "x" , "z" ] ,
77+ aggregates : { x : [ "weighted mean ", [ "y" ] ] } ,
78+ columns : [ "x" ] ,
7979 expressions : { } ,
8080 filter : [ ] ,
8181 group_by : [ "y" ] ,
@@ -87,17 +87,55 @@ const data = [
8787 table . delete ( ) ;
8888 } ) ;
8989
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 ( ) {
91129 const table = await perspective . table ( data ) ;
92130 const view = await table . view ( {
93131 group_by : [ "y" ] ,
94132 columns : [ "x" , "z" ] ,
95- aggregates : { x : "sum" , z : "mean " } ,
133+ aggregates : { x : "sum" , z : "count " } ,
96134 } ) ;
97135
98136 const config = await view . get_config ( ) ;
99137 expect ( config ) . toEqual ( {
100- aggregates : { z : "mean" } ,
138+ aggregates : { } ,
101139 columns : [ "x" , "z" ] ,
102140 expressions : { } ,
103141 filter : [ ] ,
@@ -110,17 +148,17 @@ const data = [
110148 table . delete ( ) ;
111149 } ) ;
112150
113- test ( "Compound aggregates are provided", async function ( ) {
151+ test . skip ( "Mixed aggregates are provided and omitted ", async function ( ) {
114152 const table = await perspective . table ( data ) ;
115153 const view = await table . view ( {
116154 group_by : [ "y" ] ,
117155 columns : [ "x" , "z" ] ,
118- aggregates : { x : [ "weighted mean ", [ "y" ] ] } ,
156+ aggregates : { x : "sum ", z : "mean" } ,
119157 } ) ;
120158
121159 const config = await view . get_config ( ) ;
122160 expect ( config ) . toEqual ( {
123- aggregates : { x : [ "weighted mean", [ "y" ] ] } ,
161+ aggregates : { z : " mean" } ,
124162 columns : [ "x" , "z" ] ,
125163 expressions : { } ,
126164 filter : [ ] ,
0 commit comments