From 261e8041de3101ebdcbb5275ffbd2eff508f0134 Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Fri, 14 Nov 2014 23:59:47 -0700 Subject: [PATCH] [tabify] write metrics for partial & hierarchical rows --- .../agg_response/tabify/_get_columns.js | 8 +++-- .../agg_response/tabify/_response_writer.js | 9 +++-- .../components/agg_response/tabify/tabify.js | 33 +++++++++++++++++-- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/kibana/components/agg_response/tabify/_get_columns.js b/src/kibana/components/agg_response/tabify/_get_columns.js index c31f819b71130..0abbdcf451af1 100644 --- a/src/kibana/components/agg_response/tabify/_get_columns.js +++ b/src/kibana/components/agg_response/tabify/_get_columns.js @@ -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, { @@ -14,7 +18,7 @@ define(function (require) { } // pick the columns - if (!vis.isHierarchical()) { + if (minimalMetrics) { return aggs.map(function (agg) { return { aggConfig: agg }; }); diff --git a/src/kibana/components/agg_response/tabify/_response_writer.js b/src/kibana/components/agg_response/tabify/_response_writer.js index b1d3fa2ee88a1..e28903b2bff16 100644 --- a/src/kibana/components/agg_response/tabify/_response_writer.js +++ b/src/kibana/components/agg_response/tabify/_response_writer.js @@ -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]; diff --git a/src/kibana/components/agg_response/tabify/tabify.js b/src/kibana/components/agg_response/tabify/tabify.js index b1702da396b2e..237c2a6f4cd44 100644 --- a/src/kibana/components/agg_response/tabify/tabify.js +++ b/src/kibana/components/agg_response/tabify/tabify.js @@ -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; @@ -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); }; });