@@ -5,11 +5,12 @@ import {
5
5
type ILineageResponse ,
6
6
type ILogicalNode ,
7
7
type INodeKey ,
8
+ type ISource ,
8
9
type NodeGraph
9
10
} from '../types/codegen' ;
10
11
11
12
/** Convert Join to LineageResponse by walking joinParts */
12
- export function joinToLineage ( join : IJoin ) : ILineageResponse {
13
+ export function joinToLineage ( join : IJoin , excludeLeft = false ) : ILineageResponse {
13
14
// Use `InternMap` insteaad of `Map` to support object keys (instances will be different once serialized/fetched from API) - https://d3js.org/d3-array/intern
14
15
// @ts -expect-error: Bad typing
15
16
const connections : NodeGraph [ 'connections' ] = new InternMap ( [ ] , JSON . stringify ) ;
@@ -26,6 +27,10 @@ export function joinToLineage(join: IJoin): ILineageResponse {
26
27
const joinParents : INodeKey [ ] = [ ] ;
27
28
connections . set ( joinNodeKey , { parents : joinParents } ) ;
28
29
30
+ if ( join . left && ! excludeLeft ) {
31
+ processSource ( join . left , infoMap , connections , joinParents ) ;
32
+ }
33
+
29
34
for ( const jp of join . joinParts ?? [ ] ) {
30
35
if ( jp . groupBy ) {
31
36
const groupByNodeKey : INodeKey = {
@@ -41,52 +46,7 @@ export function joinToLineage(join: IJoin): ILineageResponse {
41
46
connections . set ( groupByNodeKey , { parents : groupByParents } ) ;
42
47
43
48
for ( const source of jp . groupBy ?. sources ?? [ ] ) {
44
- if ( source . entities ) {
45
- const entityNodeKey : INodeKey = {
46
- name : source . entities . snapshotTable ,
47
- logicalType : LogicalType . TABULAR_DATA // TODO: Are all sources tabular data?
48
- } ;
49
- infoMap . set ( entityNodeKey , {
50
- conf : source . entities as ILogicalNode
51
- } ) ;
52
- groupByParents . push ( entityNodeKey ) ;
53
- }
54
-
55
- if ( source . events ) {
56
- const eventNodeKey : INodeKey = {
57
- name : source . events . table ,
58
- logicalType : LogicalType . TABULAR_DATA // TODO: Are all sources tabular data?
59
- } ;
60
- infoMap . set ( eventNodeKey , {
61
- conf : source . events as ILogicalNode
62
- } ) ;
63
- groupByParents . push ( eventNodeKey ) ;
64
- }
65
-
66
- if ( source . joinSource ) {
67
- const joinNodeKey : INodeKey = {
68
- name : source . joinSource . join ?. metaData ?. name ,
69
- logicalType : LogicalType . TABULAR_DATA // TODO: Are all sources tabular data?
70
- } ;
71
- infoMap . set ( joinNodeKey , {
72
- conf : source . joinSource as ILogicalNode
73
- } ) ;
74
- groupByParents . push ( joinNodeKey ) ;
75
-
76
- // Transfer connections and infoMap from joinSource join to root join graph
77
- const joinSourceLineage = joinToLineage ( source . joinSource . join as IJoin ) ;
78
-
79
- for ( const [ key , nodeConnections ] of joinSourceLineage . nodeGraph ?. connections ?? [ ] ) {
80
- connections . set (
81
- key === joinSourceLineage . mainNode ? joinNodeKey : key ,
82
- nodeConnections
83
- ) ;
84
- }
85
-
86
- for ( const [ key , info ] of joinSourceLineage . nodeGraph ?. infoMap ?? [ ] ) {
87
- infoMap . set ( key , info ) ;
88
- }
89
- }
49
+ processSource ( source , infoMap , connections , groupByParents ) ;
90
50
}
91
51
}
92
52
}
@@ -99,3 +59,54 @@ export function joinToLineage(join: IJoin): ILineageResponse {
99
59
mainNode : joinNodeKey
100
60
} ;
101
61
}
62
+
63
+ function processSource (
64
+ source : ISource ,
65
+ infoMap : NonNullable < NodeGraph [ 'infoMap' ] > ,
66
+ connections : NonNullable < NodeGraph [ 'connections' ] > ,
67
+ parents : INodeKey [ ]
68
+ ) {
69
+ if ( source . entities ) {
70
+ const entityNodeKey : INodeKey = {
71
+ name : source . entities . snapshotTable ,
72
+ logicalType : LogicalType . TABULAR_DATA // TODO: Are all sources tabular data?
73
+ } ;
74
+ infoMap . set ( entityNodeKey , {
75
+ conf : source . entities as ILogicalNode
76
+ } ) ;
77
+ parents . push ( entityNodeKey ) ;
78
+ }
79
+
80
+ if ( source . events ) {
81
+ const eventNodeKey : INodeKey = {
82
+ name : source . events . table ,
83
+ logicalType : LogicalType . TABULAR_DATA // TODO: Are all sources tabular data?
84
+ } ;
85
+ infoMap . set ( eventNodeKey , {
86
+ conf : source . events as ILogicalNode
87
+ } ) ;
88
+ parents . push ( eventNodeKey ) ;
89
+ }
90
+
91
+ if ( source . joinSource ) {
92
+ const joinNodeKey : INodeKey = {
93
+ name : source . joinSource . join ?. metaData ?. name ,
94
+ logicalType : LogicalType . TABULAR_DATA // TODO: Are all sources tabular data?
95
+ } ;
96
+ infoMap . set ( joinNodeKey , {
97
+ conf : source . joinSource as ILogicalNode
98
+ } ) ;
99
+ parents . push ( joinNodeKey ) ;
100
+
101
+ // Transfer connections and infoMap from joinSource join to root join graph
102
+ const joinSourceLineage = joinToLineage ( source . joinSource . join as IJoin ) ;
103
+
104
+ for ( const [ key , nodeConnections ] of joinSourceLineage . nodeGraph ?. connections ?? [ ] ) {
105
+ connections . set ( key === joinSourceLineage . mainNode ? joinNodeKey : key , nodeConnections ) ;
106
+ }
107
+
108
+ for ( const [ key , info ] of joinSourceLineage . nodeGraph ?. infoMap ?? [ ] ) {
109
+ infoMap . set ( key , info ) ;
110
+ }
111
+ }
112
+ }
0 commit comments