Skip to content

Commit

Permalink
marking correct candidates
Browse files Browse the repository at this point in the history
  • Loading branch information
AdiGajbhiye committed Dec 19, 2023
1 parent 2015697 commit 1e5fe93
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion new_lineage_panel/src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,54 @@ export const markLastSecondNode = (
}

console.log("dfsTraversal:result:", right, nodeHeights);
return Object.entries(nodeHeights)
const lastSecondLeafNodes = Object.entries(nodeHeights)
.filter(([, v]) => v === 2).map(([k]) => k);
const calculateAncestors = (lastSecondLeafNodes: string[]) => {
const ancestors: Record<string, string[]> = {};
const visited: Record<string, boolean> = {};
for (const n of lastSecondLeafNodes) ancestors[n] = [];
for (const candidate of lastSecondLeafNodes) {
const queue = [candidate];
while (queue.length > 0) {
const curr = queue.shift()!;
if (visited[curr]) continue; // maybe cycle, should ignore candidate??
visited[curr] = true;
for (const e of prevEdges) {
if (isColumn(e)) continue;
if (e[src] !== curr) continue;
const target = e[dst];
ancestors[target] = ancestors[target] || [];
ancestors[target].push(curr);
ancestors[target].push(...(ancestors[curr] || []));
queue.push(target);
}
}
}
return ancestors;
};
const calculateCandidates = (
lastSecondLeafNodes: string[],
ancestors: Record<string, string[]>,
) => {
const potentialCandidates: Record<string, boolean> = {};
for (const n of lastSecondLeafNodes) potentialCandidates[n] = true;
for (const k in ancestors) {
if (lastSecondLeafNodes.includes(k)) continue;
let count = 0;
for (const a of ancestors[k]) {
if (lastSecondLeafNodes.includes(a)) count++;
if (count > 1) {
for (const v of ancestors[k]) potentialCandidates[v] = false;
}
}
}
return Object.entries(potentialCandidates).filter(([, v]) => v).map((
[k],
) => k);
};
const ancestors = calculateAncestors(lastSecondLeafNodes);
const candidates = calculateCandidates(lastSecondLeafNodes, ancestors);
return candidates;
};

export const processColumnLineage = async (
Expand Down

0 comments on commit 1e5fe93

Please sign in to comment.