@@ -170,6 +170,66 @@ join "jaffle"."main"."stg_customers" c on c.customer_id = o.customer_id`)
170170 )
171171 } )
172172
173+ // Parents whose name, alias and schema name overlap across parents.
174+ const withParents = ( sql : string , parents : [ string , string ] [ ] ) => {
175+ const manifest = lineageManifest ( sql ) as ReturnType < typeof lineageManifest > & { nodes : Record < string , any > }
176+ for ( const [ name , alias ] of parents ) {
177+ manifest . nodes [ `model.jaffle_shop.${ name } ` ] = {
178+ unique_id : `model.jaffle_shop.${ name } ` ,
179+ resource_type : "model" ,
180+ name,
181+ alias,
182+ config : { materialized : "table" } ,
183+ depends_on : { nodes : [ ] } ,
184+ columns : { id : { name : "id" } } ,
185+ }
186+ }
187+ manifest . nodes [ CUSTOMERS ] . depends_on . nodes = parents . map ( ( [ name ] ) => `model.jaffle_shop.${ name } ` )
188+ return manifest
189+ }
190+
191+ test ( "maps a table name to the parent whose schema name it is before another's plain name" , async ( ) => {
192+ const manifest = withParents ( `select b.id from "jaffle"."main"."orders" b` , [
193+ [ "orders" , "historical_orders" ] ,
194+ [ "current_orders" , "orders" ] ,
195+ ] )
196+ const result = dbtModelLineage ( { manifest_path : await manifestFile ( "precedence" , manifest ) , model : "customers" } )
197+ expect ( result . columnLineage . map ( ( e ) => e . source ) ) . toEqual ( [ [ "model.jaffle_shop.current_orders" , "id" ] ] )
198+ expect ( result . errors ) . toEqual ( [ ] )
199+ } )
200+
201+ test ( "keeps the edges of a parent whose schema name another parent's shared name shadows" , async ( ) => {
202+ const manifest = withParents (
203+ `select o.id as clean_id, d.id as dup_id from "jaffle"."main"."orders" o join "jaffle"."main"."dup" d on d.id = o.id` ,
204+ [
205+ [ "orders" , "dup" ] ,
206+ [ "other_orders" , "dup" ] ,
207+ [ "clean_orders" , "orders" ] ,
208+ ] ,
209+ )
210+ const result = dbtModelLineage ( { manifest_path : await manifestFile ( "shadowed" , manifest ) , model : "customers" } )
211+ expect ( result . errors ) . toEqual ( [
212+ "customers reads model.jaffle_shop.orders, model.jaffle_shop.other_orders, which share a table name in altimate-core's schema, so their column edges into it were left out" ,
213+ ] )
214+ expect ( result . columnLineage . map ( ( e ) => e . source ) ) . toEqual ( [ [ "model.jaffle_shop.clean_orders" , "id" ] ] )
215+ } )
216+
217+ test ( "keeps a dotted output column's name whole" , async ( ) => {
218+ const sql = `select c.customer_id as "customer.id" from "jaffle"."main"."stg_customers" c`
219+ const result = dbtModelLineage ( {
220+ manifest_path : await manifestFile ( "dotted" , lineageManifest ( sql ) ) ,
221+ model : "customers" ,
222+ column : "customer.id" ,
223+ } )
224+ expect ( result . nodes [ 0 ] . columns . map ( ( c ) => c . name ) ) . toEqual ( [ "customer.id" ] )
225+ expect ( result . columnLineage . map ( ( e ) => [ e . source , e . target ] ) ) . toEqual ( [
226+ [
227+ [ STG_CUSTOMERS , "customer_id" ] ,
228+ [ CUSTOMERS , "customer.id" ] ,
229+ ] ,
230+ ] )
231+ } )
232+
173233 test ( "lists the model without columns when the manifest has no compiled SQL" , async ( ) => {
174234 const result = dbtModelLineage ( {
175235 manifest_path : await manifestFile ( "uncompiled" , lineageManifest ( null ) ) ,
0 commit comments