fix(Merge Node): Enrich input 2 fix (#6526)

This commit is contained in:
Michael Kret 2023-06-23 16:21:42 +03:00 committed by कारतोफ्फेलस्क्रिप्ट™
parent b6202b5585
commit 70822ce988
3 changed files with 26 additions and 30 deletions

View file

@ -278,8 +278,8 @@
{ {
"json": { "json": {
"id": 1, "id": 1,
"data": "c", "data": "a",
"input": 2, "input": 1,
"text": "foo", "text": "foo",
"tag": "second" "tag": "second"
} }
@ -287,8 +287,8 @@
{ {
"json": { "json": {
"id": 2, "id": 2,
"data": "d", "data": "b",
"input": 2, "input": 1,
"text": "foo", "text": "foo",
"tag": "second" "tag": "second"
} }

View file

@ -132,12 +132,8 @@ export function findMatches(
fieldsToMatch: PairToMatch[], fieldsToMatch: PairToMatch[],
options: MatchFieldsOptions, options: MatchFieldsOptions,
) { ) {
let data1 = [...input1]; const data1 = [...input1];
let data2 = [...input2]; const data2 = [...input2];
if (options.joinMode === 'enrichInput2') {
[data1, data2] = [data2, data1];
}
const isEntriesEqual = fuzzyCompare(options.fuzzyCompare as boolean); const isEntriesEqual = fuzzyCompare(options.fuzzyCompare as boolean);
const disableDotNotation = options.disableDotNotation || false; const disableDotNotation = options.disableDotNotation || false;
@ -263,12 +259,8 @@ export function mergeMatched(
let binary: IBinaryKeyData = {}; let binary: IBinaryKeyData = {};
if (resolveClash === 'addSuffix') { if (resolveClash === 'addSuffix') {
let suffix1 = '1'; const suffix1 = '1';
let suffix2 = '2'; const suffix2 = '2';
if (joinMode === 'enrichInput2') {
[suffix1, suffix2] = [suffix2, suffix1];
}
[entry] = addSuffixToEntriesKeys([entry], suffix1); [entry] = addSuffixToEntriesKeys([entry], suffix1);
matches = addSuffixToEntriesKeys(matches, suffix2); matches = addSuffixToEntriesKeys(matches, suffix2);
@ -279,15 +271,15 @@ export function mergeMatched(
...matches.map((item) => item.binary as IDataObject), ...matches.map((item) => item.binary as IDataObject),
); );
} else { } else {
let preferInput1 = 'preferInput1'; const preferInput1 = 'preferInput1';
let preferInput2 = 'preferInput2'; const preferInput2 = 'preferInput2';
if (joinMode === 'enrichInput2') {
[preferInput1, preferInput2] = [preferInput2, preferInput1];
}
if (resolveClash === undefined) { if (resolveClash === undefined) {
resolveClash = 'preferInput2'; if (joinMode !== 'enrichInput2') {
resolveClash = 'preferInput2';
} else {
resolveClash = 'preferInput1';
}
} }
if (resolveClash === preferInput1) { if (resolveClash === preferInput1) {

View file

@ -571,14 +571,18 @@ export class MergeV2 implements INodeType {
const mergedEntries = mergeMatched(matches.matched, clashResolveOptions, joinMode); const mergedEntries = mergeMatched(matches.matched, clashResolveOptions, joinMode);
if (clashResolveOptions.resolveClash === 'addSuffix') { if (joinMode === 'enrichInput1') {
const suffix = joinMode === 'enrichInput1' ? '1' : '2'; if (clashResolveOptions.resolveClash === 'addSuffix') {
returnData.push( returnData.push(...mergedEntries, ...addSuffixToEntriesKeys(matches.unmatched1, '1'));
...mergedEntries, } else {
...addSuffixToEntriesKeys(matches.unmatched1, suffix), returnData.push(...mergedEntries, ...matches.unmatched1);
); }
} else { } else {
returnData.push(...mergedEntries, ...matches.unmatched1); if (clashResolveOptions.resolveClash === 'addSuffix') {
returnData.push(...mergedEntries, ...addSuffixToEntriesKeys(matches.unmatched2, '2'));
} else {
returnData.push(...mergedEntries, ...matches.unmatched2);
}
} }
} }
} }