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?:
}
const displayName = calculateFieldDisplayName(field, frame, allFrames);
field.state = {
...field.state,
displayName,
};
field.state = field.state || {};
field.state.displayName = displayName;
return displayName;
}
......
......@@ -68,9 +68,7 @@ describe('ensureColumns transformer', () => {
"config": Object {},
"labels": Object {},
"name": "A",
"state": Object {
"displayName": "A",
},
"state": Object {},
"type": "number",
"values": Array [
1,
......@@ -81,9 +79,7 @@ describe('ensureColumns transformer', () => {
"config": Object {},
"labels": Object {},
"name": "B",
"state": Object {
"displayName": "B",
},
"state": Object {},
"type": "number",
"values": Array [
2,
......@@ -94,9 +90,7 @@ describe('ensureColumns transformer', () => {
"config": Object {},
"labels": Object {},
"name": "C",
"state": Object {
"displayName": "C",
},
"state": Object {},
"type": "number",
"values": Array [
3,
......@@ -107,9 +101,7 @@ describe('ensureColumns transformer', () => {
"config": Object {},
"labels": Object {},
"name": "D",
"state": Object {
"displayName": "D",
},
"state": Object {},
"type": "string",
"values": Array [
"first",
......
......@@ -107,7 +107,6 @@ describe('align frames', () => {
Object {
"name": "TheTime",
"state": Object {
"displayName": "TheTime",
"origin": Object {
"fieldIndex": 0,
"frameIndex": 0,
......@@ -122,7 +121,6 @@ describe('align frames', () => {
Object {
"name": "A1",
"state": Object {
"displayName": "A1",
"origin": Object {
"fieldIndex": 1,
"frameIndex": 0,
......@@ -137,7 +135,6 @@ describe('align frames', () => {
Object {
"name": "A2",
"state": Object {
"displayName": "A2",
"origin": Object {
"fieldIndex": 1,
"frameIndex": 1,
......@@ -164,7 +161,6 @@ describe('align frames', () => {
Object {
"name": "TheTime",
"state": Object {
"displayName": "TheTime",
"origin": Object {
"fieldIndex": 0,
"frameIndex": 0,
......@@ -174,7 +170,6 @@ describe('align frames', () => {
Object {
"name": "A1",
"state": Object {
"displayName": "A1",
"origin": Object {
"fieldIndex": 1,
"frameIndex": 0,
......
......@@ -3,7 +3,6 @@ import { ArrayVector } from '../../vector';
import { fieldMatchers } from '../matchers';
import { FieldMatcherID } from '../matchers/ids';
import { getTimeField, sortDataFrame } from '../../dataframe';
import { getFieldDisplayName } from '../../field';
export function pickBestJoinField(data: DataFrame[]): FieldMatcher {
const { timeField } = getTimeField(data[0]);
......@@ -114,16 +113,18 @@ export function outerJoinDataFrames(options: JoinOptions): DataFrame | undefined
for (let frameIndex = 0; frameIndex < options.frames.length; frameIndex++) {
const frame = options.frames[frameIndex];
if (!frame || !frame.fields?.length) {
continue; // skip the frame
}
const nullModesFrame: JoinNullMode[] = [NULL_REMOVE];
const nullModesFrame: JoinNullMode[] = [NULL_REMOVE];
let join: Field | undefined = undefined;
let fields: Field[] = [];
for (let fieldIndex = 0; fieldIndex < frame.fields.length; 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)) {
join = field;
......@@ -147,7 +148,7 @@ export function outerJoinDataFrames(options: JoinOptions): DataFrame | undefined
}
if (options.keepOriginIndices) {
field.state!.origin = {
field.state.origin = {
frameIndex,
fieldIndex,
};
......@@ -161,13 +162,17 @@ export function outerJoinDataFrames(options: JoinOptions): DataFrame | undefined
if (originalFields.length === 0) {
originalFields.push(join); // first join field
}
nullModes.push(nullModesFrame);
nullModes.push(nullModesFrame);
const a: AlignedData = [join.values.toArray()]; //
for (const field of fields) {
a.push(field.values.toArray());
originalFields.push(field);
// clear field displayName state
delete field.state?.displayName;
}
allData.push(a);
}
......
......@@ -68,9 +68,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "even",
},
"name": "temperature",
"state": Object {
"displayName": "even temperature",
},
"state": Object {},
"type": "number",
"values": Array [
undefined,
......@@ -87,9 +85,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "even",
},
"name": "humidity",
"state": Object {
"displayName": "even humidity",
},
"state": Object {},
"type": "number",
"values": Array [
undefined,
......@@ -106,9 +102,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "odd",
},
"name": "temperature",
"state": Object {
"displayName": "odd temperature",
},
"state": Object {},
"type": "number",
"values": Array [
11.1,
......@@ -125,9 +119,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "odd",
},
"name": "humidity",
"state": Object {
"displayName": "odd humidity",
},
"state": Object {},
"type": "number",
"values": Array [
11000.1,
......@@ -201,9 +193,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "even",
},
"name": "temperature",
"state": Object {
"displayName": "even temperature",
},
"state": Object {},
"type": "number",
"values": Array [
undefined,
......@@ -220,9 +210,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "even",
},
"name": "humidity",
"state": Object {
"displayName": "even humidity",
},
"state": Object {},
"type": "number",
"values": Array [
undefined,
......@@ -239,9 +227,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "odd",
},
"name": "temperature",
"state": Object {
"displayName": "odd temperature",
},
"state": Object {},
"type": "number",
"values": Array [
11.1,
......@@ -258,9 +244,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "odd",
},
"name": "humidity",
"state": Object {
"displayName": "odd humidity",
},
"state": Object {},
"type": "number",
"values": Array [
11000.1,
......@@ -328,9 +312,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "temperature",
},
"name": "temperature",
"state": Object {
"displayName": "temperature temperature",
},
"state": Object {},
"type": "number",
"values": Array [
1,
......@@ -345,9 +327,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "B",
},
"name": "temperature",
"state": Object {
"displayName": "B temperature",
},
"state": Object {},
"type": "number",
"values": Array [
2,
......@@ -416,9 +396,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "A",
},
"name": "temperature",
"state": Object {
"displayName": "A temperature",
},
"state": Object {},
"type": "number",
"values": Array [
10,
......@@ -432,9 +410,7 @@ describe('SeriesToColumns Transformer', () => {
"name": "C",
},
"name": "temperature",
"state": Object {
"displayName": "C temperature",
},
"state": Object {},
"type": "number",
"values": Array [
20,
......@@ -489,9 +465,7 @@ describe('SeriesToColumns Transformer', () => {
"config": Object {},
"labels": Object {},
"name": "temperature",
"state": Object {
"displayName": "temperature",
},
"state": Object {},
"type": "number",
"values": Array [
10,
......@@ -501,9 +475,7 @@ describe('SeriesToColumns Transformer', () => {
"config": Object {},
"labels": Object {},
"name": "temperature",
"state": Object {
"displayName": "temperature",
},
"state": Object {},
"type": "number",
"values": Array [
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