DataFrame: split DataFrameHelper into MutableDataFrame and FieldCache (#18795)

* add appending utility

* add appending utility

* update comment

* rename to mutable

* move mutable functions out of DataFrameHelper

* move mutable functions out of DataFrameHelper

* move mutable functions out of DataFrameHelper

* turn DataFrameHelper into FieldCache

* guess time from name

* graph the numbers

* return the timeField, not just the index

* just warn on duplicate field names

* only use a parser if the input is a string

* append init all fields to the same length

* typo

* only parse string if value is a string

* DataFrame: test fixes

* Switch to null for missing values

* Fixed tests
This commit is contained in:
Ryan McKinley
2019-09-01 05:44:22 -07:00
committed by Torkel Ödegaard
parent 13f55bc5e8
commit c777301535
30 changed files with 579 additions and 301 deletions

View File

@@ -2,7 +2,7 @@ import _ from 'lodash';
import flatten from 'app/core/utils/flatten';
import * as queryDef from './query_def';
import TableModel from 'app/core/table_model';
import { DataFrame, toDataFrame, FieldType, DataFrameHelper } from '@grafana/data';
import { DataFrame, toDataFrame, FieldType, MutableDataFrame } from '@grafana/data';
import { DataQueryResponse } from '@grafana/ui';
import { ElasticsearchAggregation } from './types';
@@ -464,7 +464,7 @@ export class ElasticResponse {
if (docs.length > 0) {
propNames = propNames.sort();
const series = new DataFrameHelper({ fields: [] });
const series = new MutableDataFrame({ fields: [] });
series.addField({
name: this.targets[0].timeField,
@@ -513,7 +513,7 @@ export class ElasticResponse {
// Add a row for each document
for (const doc of docs) {
series.appendRowFrom(doc);
series.add(doc);
}
dataFrame.push(series);

View File

@@ -1,5 +1,5 @@
import { DataFrameView, KeyValue, MutableDataFrame } from '@grafana/data';
import { ElasticResponse } from '../elastic_response';
import { DataFrameHelper, DataFrameView, KeyValue } from '@grafana/data';
describe('ElasticResponse', () => {
let targets;
@@ -859,7 +859,7 @@ describe('ElasticResponse', () => {
it('should return histogram aggregation and documents', () => {
expect(result.data.length).toBe(2);
const logResults = result.data[0] as DataFrameHelper;
const logResults = result.data[0] as MutableDataFrame;
const fields = logResults.fields.map(f => {
return {
name: f.name,
@@ -874,16 +874,15 @@ describe('ElasticResponse', () => {
let rows = new DataFrameView(logResults);
for (let i = 0; i < rows.length; i++) {
const r = rows.get(i);
const row = [r._id, r._type, r._index, r._source];
expect(row).toContain(response.responses[0].hits.hits[i]._id);
expect(row).toContain(response.responses[0].hits.hits[i]._type);
expect(row).toContain(response.responses[0].hits.hits[i]._index);
expect(row).toContain(JSON.stringify(response.responses[0].hits.hits[i]._source, undefined, 2));
expect(r._id).toEqual(response.responses[0].hits.hits[i]._id);
expect(r._type).toEqual(response.responses[0].hits.hits[i]._type);
expect(r._index).toEqual(response.responses[0].hits.hits[i]._index);
expect(r._source).toEqual(response.responses[0].hits.hits[i]._source);
}
// Make a map from the histogram results
const hist: KeyValue<number> = {};
const histogramResults = new DataFrameHelper(result.data[1]);
const histogramResults = new MutableDataFrame(result.data[1]);
rows = new DataFrameView(histogramResults);
for (let i = 0; i < rows.length; i++) {
const row = rows.get(i);