Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🪟 🎉 Disable deselection of cursor field/primary key in the UI #20844

Merged
merged 17 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ describe(`${mergeFieldPathArrays.name}`, () => {
{ fieldPath: FIELD_THREE },
]);
});

it("merges two arrays of complex fieldPaths without duplicates", () => {
const arr1 = [{ fieldPath: [...FIELD_ONE, ...FIELD_TWO] }, { fieldPath: [...FIELD_TWO, ...FIELD_THREE] }];
const arr2 = [
{ fieldPath: [...FIELD_ONE, ...FIELD_TWO] },
{ fieldPath: [...FIELD_TWO, ...FIELD_THREE] },
{ fieldPath: [...FIELD_ONE, ...FIELD_THREE] },
];

expect(mergeFieldPathArrays(arr1, arr2)).toEqual([
{ fieldPath: [...FIELD_ONE, ...FIELD_TWO] },
{ fieldPath: [...FIELD_TWO, ...FIELD_THREE] },
{ fieldPath: [...FIELD_ONE, ...FIELD_THREE] },
]);
});
});

describe(`${updateCursorField.name}`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import { AirbyteStreamConfiguration, SelectedFieldInfo } from "core/request/Airb
* Merges arrays of SelectedFieldInfo, ensuring there are no duplicates
*/
export function mergeFieldPathArrays(...args: SelectedFieldInfo[][]): SelectedFieldInfo[] {
const set = new Set<string[]>();
const set = new Set<string>();

args.forEach((array) =>
array.forEach((selectedFieldInfo) => {
if (selectedFieldInfo.fieldPath) {
set.add(selectedFieldInfo.fieldPath);
const key = JSON.stringify(selectedFieldInfo.fieldPath);
set.add(key);
Comment on lines +14 to +15
Copy link
Contributor Author

@josephkmh josephkmh Jan 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This converts the fieldPath (e.g. ['path', 'to', 'field']) into a string (e.g. "[\"path\",\"to\",\"field\"]") so that we can add it as a unique value to the set. It gets converted back into an array before returning.

This conversion between String[] > String > String[] might seem expensive, but it allows us use a Set to avoid duplicates when merging, which avoids a lot of nested comparisons of arrays.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a reasonable tradeoff. It sounds like it would still be more efficient for a large sync catalog or a sync catalog with a lot of changes than what this was doing before, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, at least as efficient, and in the best case more efficient 👍

}
})
);

return Array.from(set).map((fieldPath) => ({ fieldPath }));
return Array.from(set).map((key) => ({ fieldPath: JSON.parse(key) }));
}

/**
Expand Down