Skip to content

Commit 9a74808

Browse files
committed
Update behavior to not omit non-default aggregates
Signed-off-by: Andrew Stein <[email protected]>
1 parent dd2edde commit 9a74808

File tree

2 files changed

+53
-27
lines changed

2 files changed

+53
-27
lines changed

rust/perspective-js/test/js/view_config.spec.js

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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: [],

rust/perspective-server/cpp/perspective/src/cpp/server.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,17 +2245,9 @@ ProtoServer::_handle_request(std::uint32_t client_id, Request&& req) {
22452245
}
22462246

22472247
if (!view_config->get_row_pivots().empty()) {
2248-
const auto& schema =
2249-
m_resources.get_table_for_view(req.entity_id())
2250-
->get_schema();
22512248
for (const auto& aggspec : view_config->get_aggspecs()) {
22522249
auto* proto_exprs = view_config_proto->mutable_aggregates();
22532250
const auto agg = aggspec;
2254-
const auto table_type = schema.get_dtype(aggspec.name());
2255-
2256-
// TODO(texodus): This behavior is arbitrary, I nominate we
2257-
// we kill it but it is anothe rbreaking change.
2258-
22592251
if (aggspec.agg() == AGGTYPE_WEIGHTED_MEAN
22602252
|| aggspec.agg() == AGGTYPE_MAX_BY
22612253
|| aggspec.agg() == AGGTYPE_MIN_BY) {
@@ -2264,11 +2256,7 @@ ProtoServer::_handle_request(std::uint32_t client_id, Request&& req) {
22642256
agglist.add_aggregations(agg.agg_str());
22652257
agglist.add_aggregations(agg.get_input_depnames()[1]);
22662258
(*proto_exprs)[aggspec.name()] = agglist;
2267-
} else if ((is_numeric_type(table_type)
2268-
&& aggspec.agg() != AGGTYPE_SUM)
2269-
|| (!is_numeric_type(table_type)
2270-
&& aggspec.agg() != AGGTYPE_COUNT)) {
2271-
2259+
} else {
22722260
proto::ViewConfig_AggList agglist;
22732261
agglist.add_aggregations(agg.agg_str());
22742262
(*proto_exprs)[aggspec.name()] = agglist;

0 commit comments

Comments
 (0)