Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
[tabify] write metrics for partial & hierarchical rows
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer Alger committed Nov 15, 2014
1 parent cf3b6e3 commit 261e804
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/kibana/components/agg_response/tabify/_get_columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ define(function (require) {
var _ = require('lodash');
var AggConfig = Private(require('components/vis/_agg_config'));

return function getColumns(vis) {
return function getColumns(vis, opts) {
if (!opts) opts = {};

var aggs = vis.aggs.getSorted();
var isHierarchical = vis.isHierarchical();
var minimalMetrics = isHierarchical ? opts.minimalMetrics : true;

if (!vis.aggs.bySchemaGroup.metrics) {
aggs.push(new AggConfig(vis, {
Expand All @@ -14,7 +18,7 @@ define(function (require) {
}

// pick the columns
if (!vis.isHierarchical()) {
if (minimalMetrics) {
return aggs.map(function (agg) {
return { aggConfig: agg };
});
Expand Down
9 changes: 6 additions & 3 deletions src/kibana/components/agg_response/tabify/_response_writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ define(function (require) {
this.opts = opts || {};
this.rowBuffer = [];

this.columns = getColumns(vis);
this.aggStack = _.pluck(this.columns, 'aggConfig');
var visIsHier = vis.isHierarchical();
this.canSplit = this.opts.canSplit !== false;
this.partialRows = this.opts.partialRows == null ? vis.isHierarchical() : this.opts.partialRows;
this.partialRows = this.opts.partialRows == null ? visIsHier : this.opts.partialRows;
this.metricsAtEachLevel = visIsHier;

this.columns = getColumns(vis, this.opts);
this.aggStack = _.pluck(this.columns, 'aggConfig');

this.root = new TableGroup();
this.splitStack = [this.root];
Expand Down
33 changes: 30 additions & 3 deletions src/kibana/components/agg_response/tabify/tabify.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,16 @@ define(function (require) {
});
});
}
} else if (write.partialRows && write.metricsAtEachLevel) {
// we don't have any buckets, but we do have metrics at this
// level, then pass all the empty buckets and jump back in for
// the metrics.
write.aggStack.unshift(agg);
passEmptyBuckets(write, bucket, key);
write.aggStack.shift();
} else {
// bucket didn't result in sub-buckets, we will try to
// write the row, but stop digging. This row.write will do nothing in
// specific scenarios known to the the Response
// we don't have any buckets, and we don't have isHierarchical
// data, so no metrics, just try to write the row
write.row();
}
break;
Expand Down Expand Up @@ -82,6 +88,27 @@ define(function (require) {
return bucket.doc_count;
}

// write empty values for each bucket agg, then write
// the metrics from the initial bucket using collectBucket()
function passEmptyBuckets(write, bucket, key) {
var agg = write.aggStack.shift();

switch (agg.schema.group) {
case 'metrics':
// pass control back to collectBucket()
write.aggStack.unshift(agg);
collectBucket(write, bucket, key);
return;

case 'buckets':
write.cell('', function () {
passEmptyBuckets(write, bucket, key);
});
}

write.aggStack.unshift(agg);
}

return notify.timed('tabify agg response', tabifyAggResponse);
};
});

0 comments on commit 261e804

Please sign in to comment.