Skip to content

Commit

Permalink
fix issue #183: float aggregates now have correct type on schema
Browse files Browse the repository at this point in the history
  • Loading branch information
sc1f committed Aug 8, 2018
1 parent 5f1c254 commit 7c9e992
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions packages/perspective/src/js/perspective.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,18 +483,27 @@ view.prototype.schema = async function() {
new_schema[col_name] = "date";
}
if (this.sides() > 0) {
for (let agg in this.config.aggregate) {
agg = this.config.aggregate[agg];
if (agg.column.join(',') === col_name) {
if (["distinct count", "distinctcount", "distinct", "count"].indexOf(agg.op) > -1) {
new_schema[col_name] = "integer";
}
new_schema[col_name] = map_aggregate_types(col_name, new_schema[col_name], this.config.aggregate);
}
}
return new_schema;
}

}
const map_aggregate_types = function(col_name, orig_type, aggregate) {
const INTEGER_AGGS = ["distinct count", "distinctcount", "distinct", "count"];
const FLOAT_AGGS = ["avg", "mean", "mean by count", "weighted_mean", "pct sum parent", "pct sum grand total"];

for (let agg in aggregate) {
let found_agg = aggregate[agg];
if (found_agg.column.join(',') === col_name) {
if (INTEGER_AGGS.includes(found_agg.op)) {
return "integer";
} else if (FLOAT_AGGS.includes(found_agg.op)) {
return "float";
}
}
}
return new_schema;
return orig_type;
}

const to_format = async function (options, formatter) {
Expand Down

0 comments on commit 7c9e992

Please sign in to comment.