Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove 'aggregate' syntax in engine #552

Merged
merged 7 commits into from
Apr 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add backwards compatibility for aggregate
  • Loading branch information
sc1f committed Apr 23, 2019
commit e1e800a9b85b95d094641ecb2e936d6feb98af9e
1 change: 0 additions & 1 deletion packages/perspective/bench/js/browser_runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const wait_for_perspective = () => new Promise(resolve => window.addEventListene

function to_name({aggregate, row_pivot, column_pivot}) {
return {
// FIXME: remove "aggregate" and replace with new syntax
aggregate: COLUMN_TYPES[aggregate[0].column],
row_pivots: row_pivot.join("/") || "-",
column_pivots: column_pivot.join("/") || "-"
Expand Down
13 changes: 9 additions & 4 deletions packages/perspective/src/js/perspective.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,7 @@ export default function(Module) {
formatter.addRow(data, row);
}

/* if (this.column_only) {
data = formatter.slice(data, 1);
} */
slice.delete();

return formatter.formatData(data, options.config);
};
Expand Down Expand Up @@ -971,7 +969,14 @@ export default function(Module) {
throw new Error(`Duplicate configuration parameter "${key}"`);
}
} else if (key === "aggregate") {
throw new Error(`Deprecated: "aggregate" config parameter has been replaced by "aggregates" and "columns"`);
console.warn(`Deprecated: "aggregate" config parameter has been replaced by "aggregates" and "columns"`);
// backwards compatibility: deconstruct `aggregate` into `aggregates` and `columns`
config["aggregates"] = {};
config["columns"] = [];
for (const agg of _config["aggregate"]) {
config["aggregates"][agg["column"]] = agg["op"];
config["columns"].push(agg["column"]);
}
} else if (defaults.CONFIG_VALID_KEYS.indexOf(key) > -1) {
config[key] = _config[key];
} else {
Expand Down
13 changes: 13 additions & 0 deletions packages/perspective/test/js/pivots.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ var data_8 = {

module.exports = perspective => {
describe("Aggregate", function() {
it("old `aggregate` syntax is backwards compatible", async function() {
var table = perspective.table(data);
var view = table.view({
aggregate: [{column: "x", op: "sum"}],
row_pivots: ["z"]
});
var answer = [{__ROW_PATH__: [], x: 10}, {__ROW_PATH__: [false], x: 6}, {__ROW_PATH__: [true], x: 4}];
let result = await view.to_json();
expect(result).toEqual(answer);
view.delete();
table.delete();
});

it("['z'], sum", async function() {
var table = perspective.table(data);
var view = table.view({
Expand Down