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

Fix(enrichment): Add dataset columns to initial visited nodes #2313

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 6 additions & 3 deletions src/api/controller/api/enrichment.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
import { cancelJob, getActiveJob } from '../../workers/tools';
import { getLocale } from 'redux-polyglot/dist/selectors';
import { orderEnrichmentsByDependencies } from '../../services/orderEnrichmentsByDependencies';
import enrichment from '../../../app/js/admin/enrichment';

export const setup = async (ctx, next) => {
try {
Expand Down Expand Up @@ -168,10 +167,14 @@ export const enrichmentDataPreview = async (ctx) => {
};

export const launchAllEnrichment = async (ctx) => {
const datasetColumns = await ctx.dataset.getColumns();
const enrichments = await ctx.enrichment.findAll();
const orderedEnrichments = orderEnrichmentsByDependencies(enrichments);
const orderedEnrichments = orderEnrichmentsByDependencies(
datasetColumns.map((column) => column.key),
enrichments,
);

for (const [i, enrichment] of orderedEnrichments.entries()) {
for (const enrichment of orderedEnrichments) {
if (enrichment.status === 'FINISHED') {
await ctx.dataset.removeAttribute(enrichment.name);
}
Expand Down
3 changes: 3 additions & 0 deletions src/api/controller/api/enrichment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ describe('Enrichment controller', () => {
updateStatus: jest.fn(async () => {}),
},
dataset: {
getColumns: jest.fn().mockResolvedValue([]),
removeAttribute: jest.fn(async () => {}),
},
tenant: 'test',
Expand Down Expand Up @@ -230,6 +231,7 @@ describe('Enrichment controller', () => {
updateStatus: jest.fn(async () => {}),
},
dataset: {
getColumns: jest.fn().mockResolvedValue([]),
removeAttribute: jest.fn(async () => {}),
},
tenant: 'test',
Expand Down Expand Up @@ -267,6 +269,7 @@ describe('Enrichment controller', () => {
updateStatus: jest.fn(async () => {}),
},
dataset: {
getColumns: jest.fn().mockResolvedValue([]),
removeAttribute: jest.fn(async () => {}),
},
tenant: 'test',
Expand Down
4 changes: 2 additions & 2 deletions src/api/services/orderEnrichmentsByDependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @param {Enrichment[]} enrichments
* @returns {Enrichment[]}
*/
export function orderEnrichmentsByDependencies(enrichments) {
export function orderEnrichmentsByDependencies(datasetColumns, enrichments) {
/**
* @type {Enrichment[]}
*/
Expand All @@ -17,7 +17,7 @@ export function orderEnrichmentsByDependencies(enrichments) {
/**
* @type {Set<string>}
*/
const visitedEnrichments = new Set();
const visitedEnrichments = new Set(datasetColumns);

/**
* @type {Enrichment[]}
Expand Down
20 changes: 13 additions & 7 deletions src/api/services/orderEnrichmentsByDependencies.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { orderEnrichmentsByDependencies } from './orderEnrichmentsByDependencies

describe('orderEnrichmentsByDependencies', () => {
it('should return empty array if no enrichments', () => {
expect(orderEnrichmentsByDependencies([])).toStrictEqual([]);
expect(orderEnrichmentsByDependencies([], [])).toStrictEqual([]);
});

it('should not change order if no dependencies between enrichments', () => {
const A = { name: 'A' };
const A = { name: 'A', sourceColumn: '1' };
const B = { name: 'B' };
const C = { name: 'C' };
expect(orderEnrichmentsByDependencies([C, A, B])).toStrictEqual([
expect(orderEnrichmentsByDependencies(['1'], [C, A, B])).toStrictEqual([
C,
A,
B,
Expand All @@ -21,7 +21,7 @@ describe('orderEnrichmentsByDependencies', () => {
const B = { name: 'B' };
const C = { name: 'C', sourceColumn: 'B' };
const D = { name: 'D', sourceColumn: 'A' };
expect(orderEnrichmentsByDependencies([D, A, B, C])).toStrictEqual([
expect(orderEnrichmentsByDependencies([], [D, A, B, C])).toStrictEqual([
A,
B,
C,
Expand All @@ -33,7 +33,9 @@ describe('orderEnrichmentsByDependencies', () => {
const A = { name: 'A' };
const B = { name: 'B' };
const C = { name: 'C', sourceColumn: 'D' };
expect(() => orderEnrichmentsByDependencies([A, B, C, D])).toThrow();
expect(() =>
orderEnrichmentsByDependencies([], [A, B, C, D]),
).toThrow();
});

it('should throw an error if there is a circular dependency', () => {
Expand All @@ -42,7 +44,11 @@ describe('orderEnrichmentsByDependencies', () => {
const C = { name: 'C', sourceColumn: 'D' };
const D = { name: 'D', sourceColumn: 'C' };
const E = { name: 'E' };
expect(() => orderEnrichmentsByDependencies([A, B, C, D])).toThrow();
expect(() => orderEnrichmentsByDependencies([A, B, C, D, E])).toThrow();
expect(() =>
orderEnrichmentsByDependencies([], [A, B, C, D]),
).toThrow();
expect(() =>
orderEnrichmentsByDependencies([], [A, B, C, D, E]),
).toThrow();
});
});
Loading