StreamingDataFrame: skip empty labels (#36047)

This commit is contained in:
Ryan McKinley 2021-06-28 13:00:32 -07:00 committed by GitHub
parent d42d874240
commit 429e2d0ab2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 5 deletions

View File

@ -1,4 +1,5 @@
import { reduceField, ReducerID } from '..';
import { getFieldDisplayName } from '../field';
import { DataFrame, FieldType } from '../types/dataFrame';
import { DataFrameJSON } from './DataFrameJSON';
import { StreamingDataFrame } from './StreamingDataFrame';
@ -352,6 +353,27 @@ describe('Streaming JSON', () => {
},
]
`);
// Push value with empty labels
stream.push({
data: {
values: [[''], [500], [50], [7]],
},
});
expect(stream.fields.map((f) => getFieldDisplayName(f, stream, [stream]))).toMatchInlineSnapshot(`
Array [
"time",
"speed A",
"light A",
"speed B",
"light B",
"speed C",
"light C",
"speed 4",
"light 4",
]
`); // speed+light 4 ¯\_(ツ)_/¯ better than undefined labels
});
/*

View File

@ -186,11 +186,12 @@ export class StreamingDataFrame implements DataFrame {
// parse labels
const parsedLabels: Labels = {};
label.split(',').forEach((kv) => {
const [key, val] = kv.trim().split('=');
parsedLabels[key] = val;
});
if (label.length) {
label.split(',').forEach((kv) => {
const [key, val] = kv.trim().split('=');
parsedLabels[key] = val;
});
}
if (labelCount === 0) {
// mutate existing fields and add labels