Commit 69972458 by Torkel Ödegaard Committed by GitHub

Transforms: Fixes Outer join issue with duplicate field names not getting the…

Transforms: Fixes Outer join issue with duplicate field names not getting the same unique field names as before  (#31121)

* Transformations: Fixed duplicate name issue in outer join transform

* Think this is working

* Updated tests

* Updated snapshot

* Fix broken tests (#31123)

* Fix broken tests

* Fix remaining faling tests

Co-authored-by: Giordano Ricci <gio.ricci@grafana.com>
parent 7394c98d
...@@ -38,10 +38,8 @@ export function getFieldDisplayName(field: Field, frame?: DataFrame, allFrames?: ...@@ -38,10 +38,8 @@ export function getFieldDisplayName(field: Field, frame?: DataFrame, allFrames?:
} }
const displayName = calculateFieldDisplayName(field, frame, allFrames); const displayName = calculateFieldDisplayName(field, frame, allFrames);
field.state = { field.state = field.state || {};
...field.state, field.state.displayName = displayName;
displayName,
};
return displayName; return displayName;
} }
......
...@@ -68,9 +68,7 @@ describe('ensureColumns transformer', () => { ...@@ -68,9 +68,7 @@ describe('ensureColumns transformer', () => {
"config": Object {}, "config": Object {},
"labels": Object {}, "labels": Object {},
"name": "A", "name": "A",
"state": Object { "state": Object {},
"displayName": "A",
},
"type": "number", "type": "number",
"values": Array [ "values": Array [
1, 1,
...@@ -81,9 +79,7 @@ describe('ensureColumns transformer', () => { ...@@ -81,9 +79,7 @@ describe('ensureColumns transformer', () => {
"config": Object {}, "config": Object {},
"labels": Object {}, "labels": Object {},
"name": "B", "name": "B",
"state": Object { "state": Object {},
"displayName": "B",
},
"type": "number", "type": "number",
"values": Array [ "values": Array [
2, 2,
...@@ -94,9 +90,7 @@ describe('ensureColumns transformer', () => { ...@@ -94,9 +90,7 @@ describe('ensureColumns transformer', () => {
"config": Object {}, "config": Object {},
"labels": Object {}, "labels": Object {},
"name": "C", "name": "C",
"state": Object { "state": Object {},
"displayName": "C",
},
"type": "number", "type": "number",
"values": Array [ "values": Array [
3, 3,
...@@ -107,9 +101,7 @@ describe('ensureColumns transformer', () => { ...@@ -107,9 +101,7 @@ describe('ensureColumns transformer', () => {
"config": Object {}, "config": Object {},
"labels": Object {}, "labels": Object {},
"name": "D", "name": "D",
"state": Object { "state": Object {},
"displayName": "D",
},
"type": "string", "type": "string",
"values": Array [ "values": Array [
"first", "first",
......
...@@ -107,7 +107,6 @@ describe('align frames', () => { ...@@ -107,7 +107,6 @@ describe('align frames', () => {
Object { Object {
"name": "TheTime", "name": "TheTime",
"state": Object { "state": Object {
"displayName": "TheTime",
"origin": Object { "origin": Object {
"fieldIndex": 0, "fieldIndex": 0,
"frameIndex": 0, "frameIndex": 0,
...@@ -122,7 +121,6 @@ describe('align frames', () => { ...@@ -122,7 +121,6 @@ describe('align frames', () => {
Object { Object {
"name": "A1", "name": "A1",
"state": Object { "state": Object {
"displayName": "A1",
"origin": Object { "origin": Object {
"fieldIndex": 1, "fieldIndex": 1,
"frameIndex": 0, "frameIndex": 0,
...@@ -137,7 +135,6 @@ describe('align frames', () => { ...@@ -137,7 +135,6 @@ describe('align frames', () => {
Object { Object {
"name": "A2", "name": "A2",
"state": Object { "state": Object {
"displayName": "A2",
"origin": Object { "origin": Object {
"fieldIndex": 1, "fieldIndex": 1,
"frameIndex": 1, "frameIndex": 1,
...@@ -164,7 +161,6 @@ describe('align frames', () => { ...@@ -164,7 +161,6 @@ describe('align frames', () => {
Object { Object {
"name": "TheTime", "name": "TheTime",
"state": Object { "state": Object {
"displayName": "TheTime",
"origin": Object { "origin": Object {
"fieldIndex": 0, "fieldIndex": 0,
"frameIndex": 0, "frameIndex": 0,
...@@ -174,7 +170,6 @@ describe('align frames', () => { ...@@ -174,7 +170,6 @@ describe('align frames', () => {
Object { Object {
"name": "A1", "name": "A1",
"state": Object { "state": Object {
"displayName": "A1",
"origin": Object { "origin": Object {
"fieldIndex": 1, "fieldIndex": 1,
"frameIndex": 0, "frameIndex": 0,
......
...@@ -3,7 +3,6 @@ import { ArrayVector } from '../../vector'; ...@@ -3,7 +3,6 @@ import { ArrayVector } from '../../vector';
import { fieldMatchers } from '../matchers'; import { fieldMatchers } from '../matchers';
import { FieldMatcherID } from '../matchers/ids'; import { FieldMatcherID } from '../matchers/ids';
import { getTimeField, sortDataFrame } from '../../dataframe'; import { getTimeField, sortDataFrame } from '../../dataframe';
import { getFieldDisplayName } from '../../field';
export function pickBestJoinField(data: DataFrame[]): FieldMatcher { export function pickBestJoinField(data: DataFrame[]): FieldMatcher {
const { timeField } = getTimeField(data[0]); const { timeField } = getTimeField(data[0]);
...@@ -114,16 +113,18 @@ export function outerJoinDataFrames(options: JoinOptions): DataFrame | undefined ...@@ -114,16 +113,18 @@ export function outerJoinDataFrames(options: JoinOptions): DataFrame | undefined
for (let frameIndex = 0; frameIndex < options.frames.length; frameIndex++) { for (let frameIndex = 0; frameIndex < options.frames.length; frameIndex++) {
const frame = options.frames[frameIndex]; const frame = options.frames[frameIndex];
if (!frame || !frame.fields?.length) { if (!frame || !frame.fields?.length) {
continue; // skip the frame continue; // skip the frame
} }
const nullModesFrame: JoinNullMode[] = [NULL_REMOVE];
const nullModesFrame: JoinNullMode[] = [NULL_REMOVE];
let join: Field | undefined = undefined; let join: Field | undefined = undefined;
let fields: Field[] = []; let fields: Field[] = [];
for (let fieldIndex = 0; fieldIndex < frame.fields.length; fieldIndex++) { for (let fieldIndex = 0; fieldIndex < frame.fields.length; fieldIndex++) {
const field = frame.fields[fieldIndex]; const field = frame.fields[fieldIndex];
getFieldDisplayName(field, frame, options.frames); // cache displayName in state field.state = field.state || {};
if (!join && joinFieldMatcher(field, frame, options.frames)) { if (!join && joinFieldMatcher(field, frame, options.frames)) {
join = field; join = field;
...@@ -147,7 +148,7 @@ export function outerJoinDataFrames(options: JoinOptions): DataFrame | undefined ...@@ -147,7 +148,7 @@ export function outerJoinDataFrames(options: JoinOptions): DataFrame | undefined
} }
if (options.keepOriginIndices) { if (options.keepOriginIndices) {
field.state!.origin = { field.state.origin = {
frameIndex, frameIndex,
fieldIndex, fieldIndex,
}; };
...@@ -161,13 +162,17 @@ export function outerJoinDataFrames(options: JoinOptions): DataFrame | undefined ...@@ -161,13 +162,17 @@ export function outerJoinDataFrames(options: JoinOptions): DataFrame | undefined
if (originalFields.length === 0) { if (originalFields.length === 0) {
originalFields.push(join); // first join field originalFields.push(join); // first join field
} }
nullModes.push(nullModesFrame);
nullModes.push(nullModesFrame);
const a: AlignedData = [join.values.toArray()]; // const a: AlignedData = [join.values.toArray()]; //
for (const field of fields) { for (const field of fields) {
a.push(field.values.toArray()); a.push(field.values.toArray());
originalFields.push(field); originalFields.push(field);
// clear field displayName state
delete field.state?.displayName;
} }
allData.push(a); allData.push(a);
} }
......
...@@ -68,9 +68,7 @@ describe('SeriesToColumns Transformer', () => { ...@@ -68,9 +68,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "even", "name": "even",
}, },
"name": "temperature", "name": "temperature",
"state": Object { "state": Object {},
"displayName": "even temperature",
},
"type": "number", "type": "number",
"values": Array [ "values": Array [
undefined, undefined,
...@@ -87,9 +85,7 @@ describe('SeriesToColumns Transformer', () => { ...@@ -87,9 +85,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "even", "name": "even",
}, },
"name": "humidity", "name": "humidity",
"state": Object { "state": Object {},
"displayName": "even humidity",
},
"type": "number", "type": "number",
"values": Array [ "values": Array [
undefined, undefined,
...@@ -106,9 +102,7 @@ describe('SeriesToColumns Transformer', () => { ...@@ -106,9 +102,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "odd", "name": "odd",
}, },
"name": "temperature", "name": "temperature",
"state": Object { "state": Object {},
"displayName": "odd temperature",
},
"type": "number", "type": "number",
"values": Array [ "values": Array [
11.1, 11.1,
...@@ -125,9 +119,7 @@ describe('SeriesToColumns Transformer', () => { ...@@ -125,9 +119,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "odd", "name": "odd",
}, },
"name": "humidity", "name": "humidity",
"state": Object { "state": Object {},
"displayName": "odd humidity",
},
"type": "number", "type": "number",
"values": Array [ "values": Array [
11000.1, 11000.1,
...@@ -201,9 +193,7 @@ describe('SeriesToColumns Transformer', () => { ...@@ -201,9 +193,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "even", "name": "even",
}, },
"name": "temperature", "name": "temperature",
"state": Object { "state": Object {},
"displayName": "even temperature",
},
"type": "number", "type": "number",
"values": Array [ "values": Array [
undefined, undefined,
...@@ -220,9 +210,7 @@ describe('SeriesToColumns Transformer', () => { ...@@ -220,9 +210,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "even", "name": "even",
}, },
"name": "humidity", "name": "humidity",
"state": Object { "state": Object {},
"displayName": "even humidity",
},
"type": "number", "type": "number",
"values": Array [ "values": Array [
undefined, undefined,
...@@ -239,9 +227,7 @@ describe('SeriesToColumns Transformer', () => { ...@@ -239,9 +227,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "odd", "name": "odd",
}, },
"name": "temperature", "name": "temperature",
"state": Object { "state": Object {},
"displayName": "odd temperature",
},
"type": "number", "type": "number",
"values": Array [ "values": Array [
11.1, 11.1,
...@@ -258,9 +244,7 @@ describe('SeriesToColumns Transformer', () => { ...@@ -258,9 +244,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "odd", "name": "odd",
}, },
"name": "humidity", "name": "humidity",
"state": Object { "state": Object {},
"displayName": "odd humidity",
},
"type": "number", "type": "number",
"values": Array [ "values": Array [
11000.1, 11000.1,
...@@ -328,9 +312,7 @@ describe('SeriesToColumns Transformer', () => { ...@@ -328,9 +312,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "temperature", "name": "temperature",
}, },
"name": "temperature", "name": "temperature",
"state": Object { "state": Object {},
"displayName": "temperature temperature",
},
"type": "number", "type": "number",
"values": Array [ "values": Array [
1, 1,
...@@ -345,9 +327,7 @@ describe('SeriesToColumns Transformer', () => { ...@@ -345,9 +327,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "B", "name": "B",
}, },
"name": "temperature", "name": "temperature",
"state": Object { "state": Object {},
"displayName": "B temperature",
},
"type": "number", "type": "number",
"values": Array [ "values": Array [
2, 2,
...@@ -416,9 +396,7 @@ describe('SeriesToColumns Transformer', () => { ...@@ -416,9 +396,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "A", "name": "A",
}, },
"name": "temperature", "name": "temperature",
"state": Object { "state": Object {},
"displayName": "A temperature",
},
"type": "number", "type": "number",
"values": Array [ "values": Array [
10, 10,
...@@ -432,9 +410,7 @@ describe('SeriesToColumns Transformer', () => { ...@@ -432,9 +410,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "C", "name": "C",
}, },
"name": "temperature", "name": "temperature",
"state": Object { "state": Object {},
"displayName": "C temperature",
},
"type": "number", "type": "number",
"values": Array [ "values": Array [
20, 20,
...@@ -489,9 +465,7 @@ describe('SeriesToColumns Transformer', () => { ...@@ -489,9 +465,7 @@ describe('SeriesToColumns Transformer', () => {
"config": Object {}, "config": Object {},
"labels": Object {}, "labels": Object {},
"name": "temperature", "name": "temperature",
"state": Object { "state": Object {},
"displayName": "temperature",
},
"type": "number", "type": "number",
"values": Array [ "values": Array [
10, 10,
...@@ -501,9 +475,7 @@ describe('SeriesToColumns Transformer', () => { ...@@ -501,9 +475,7 @@ describe('SeriesToColumns Transformer', () => {
"config": Object {}, "config": Object {},
"labels": Object {}, "labels": Object {},
"name": "temperature", "name": "temperature",
"state": Object { "state": Object {},
"displayName": "temperature",
},
"type": "number", "type": "number",
"values": Array [ "values": Array [
20, 20,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment