Home
%3CLINGO-SUB%20id%3D%22lingo-sub-918519%22%20slang%3D%22en-US%22%3ECreate%20Generic%20SCD%20Pattern%20in%20ADF%20Mapping%20Data%20Flows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-918519%22%20slang%3D%22en-US%22%3E%3CP%3EAzure%20Data%20Factory's%20Mapping%20Data%20Flows%20feature%20enables%20graphical%20ETL%20designs%20that%20are%20generic%20and%20parameterized.%20In%20this%20example%2C%20I'll%20show%20you%20how%20to%20create%20a%20reusable%20SCD%20Type%201%20pattern%20that%20could%20be%20applied%20to%20multiple%20dimension%20tables%20by%20minimizing%20the%20number%20of%20common%20columns%20required%2C%20leveraging%20parameters%20and%20ADF's%20built-in%20schema%20drift%20capability.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F138419iD3DC27A7233D1483%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22scdt1g1.png%22%20title%3D%22scdt1g1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20completed%20version%20of%20this%20data%20flow%20is%20shown%20above%20and%20is%20also%20available%20as%20a%20pipeline%20template%20that%20you%20can%20add%20to%20your%20factory%20by%20downloading%20it%20here%20and%20then%20importing%20it%20into%20your%20factory.%20Go%20to%20New%20%26gt%3B%20%22Pipeline%20from%20template%22%20and%20then%20point%20to%20this%20local%20file.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETypically%2C%20when%20building%20ETL%20for%20a%20data%20warehouse%20solution%2C%20you%20will%20need%20to%20manage%20many%20different%20dimension%20tables.%20With%20ADF%20Mapping%20Data%20Flows%2C%20you%20can%20minimize%20the%20number%20of%20different%20flows%20that%20you%20need%20to%20create%20by%20creating%20generic%2C%20reusable%20data%20flows.%20The%20key%20is%20to%20identify%20the%20commonality%20between%20each%20dimension%20table%20and%20then%20create%20parameters%20for%20the%20elements%20that%20change%20between%20executions%20and%20tables.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20753px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F138415iA0A116F43B51B332%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22scdt1g2.png%22%20title%3D%22scdt1g2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EFor%20this%20demo%20data%20flow%2C%20I%20created%20string%20parameters%20for%20these%20elements%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E1.%20dimname%3A%20can%20be%20used%20to%20create%20intermediate%20files%20with%20the%20name%20of%20the%20dimension%3C%2FP%3E%0A%3CP%3E2.%20keycol%3A%20the%20name%20of%20the%20business%20key%20column%20in%20the%20target%20dimension%20table.%20In%20this%20case%2C%20it%20is%20%22ProductID%22%3C%2FP%3E%0A%3CP%3E3.%20SurrogateKey%3A%20the%20column%20name%20for%20the%20dimension%20table's%20surrogate%20key%20(non-business%20key)%3C%2FP%3E%0A%3CP%3E4.%20tablename%3A%20the%20target%20dimension%20table%20name%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EInside%20of%20the%20logic%20in%20the%20example%2C%20you%20will%20see%20that%20I%20am%20assuming%204%20fields%20will%20be%20common%20in%20every%20dimension%20table%20in%20your%20stars%20schema%20model%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EName%3A%20the%20member%20name%20in%20the%20dimension%20table%3C%2FLI%3E%0A%3CLI%3E_Inserted%3A%20timestamp%20for%20when%20the%20new%20member%20was%20added%20to%20the%20table%3C%2FLI%3E%0A%3CLI%3E_LastUpdated%3A%20timestamp%20for%20when%20this%20member%20row%20was%20last%20updated%3C%2FLI%3E%0A%3CLI%3EDWhash%3A%20a%20SHA2%20hash%20of%20the%20row%20to%20use%20for%20comparing%20new%20vs.%20old%20properties%20in%20each%20row%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EThese%20are%20all%20very%20common%20attributes%20used%20in%20star%20schemas.%20But%20you%20can%20modify%20these%20columns%20and%20parameters%20to%20fit%20your%20model.%20The%20idea%20here%20is%20to%20provide%20a%20pattern%20that%20you%20can%20mimic%20in%20your%20business.%20I%20explain%20the%20steps%20below%2C%20but%20the%20best%20way%20to%20get%20comfortable%20with%20this%20technique%20is%20to%20download%20this%20sample%20and%20play%20around%20with%20it%20in%20your%20factory.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHere%20are%20the%20high-level%20steps%20to%20make%20this%20work%20for%20more%20than%20just%20one%20dimension%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3ESources%3A%20There%20are%20two%20sources.%20One%20is%20a%20file%20of%20updated%20members.%20In%20this%20example%2C%20we%20are%20using%20the%20products%20dimension.%20So%20the%20first%20source%20at%20the%20top%20is%20a%20CSV%20file%20of%20members%20that%20were%20changed%20that%20day.%20Because%20we%20want%20this%20data%20flow%20to%20be%20reusable%2C%20the%20dataset%20we%20use%20is%20parameterized.%20When%20you%20execute%20this%20data%20flow%20from%20a%20pipeline%2C%20you%20will%20set%20the%20source%20filename%20so%20that%20a%20different%20file%20can%20be%20processed%20on%20every%20execution.%20Set%20a%20parameter%20in%20the%20source%20dataset%20of%20type%20Delimited%20Text%20called%20%3CSTRONG%3Efilename%3C%2FSTRONG%3E.%20Set%20this%20expression%20in%20the%20filename%20property%20in%20the%20dataset%3A%26nbsp%3B%3CSTRONG%3E%40dataset().filename%3C%2FSTRONG%3E.%20The%20second%20source%20is%20a%20database%20source%20that%20points%20to%20the%20DimProducts%20table.%20But%20instead%20of%20hardcoding%20the%20table%20name%2C%20we'll%20parameterize%20it.%20In%20the%20dataset%2C%20create%20a%20parameter%20called%20%3CSTRONG%3Etablename%3C%2FSTRONG%3E%20and%20use%20this%20formula%20in%20the%20table%20name%20property%20(click%20edit)%3A%26nbsp%3B%3CSTRONG%3E%40dataset().tablename%3C%2FSTRONG%3E.%20The%203rd%20source%20is%20used%20just%20to%20grab%20the%20max%20value%20of%20the%20existing%20surrogate%20key%20in%20the%20target%20dimension%20table.%20We'll%20use%20the%20dataflow%20parameters%20in%20this%20query%20which%20needs%20to%20be%20constructed%20from%20the%20Expression%20Builder%20to%20provide%20a%20string%20value%20to%20ADF%3A%26nbsp%3B%3CSPAN%3E%3CSTRONG%3Econcat('select%20max('%2C%24SurrogateKey%2C')%20as%20maxsk%20from%20'%2C%24tablename)%3C%2FSTRONG%3E.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3EDerived%20Column%20transformations%3A%20Both%20sources%20use%20derived%20column%20transformations%20to%20define%20the%20field%20names%20that%20you%20want%20to%20extract%20from%20each%20and%20then%20subsequently%20use%20in%20your%20data%20flow.%20The%20%22PickCols%22%20transformation%20on%20the%201st%20and%202nd%20streams%20are%20using%20pattern%20matching%20to%20create%20new%20columns%20that%20will%20be%20the%20metadata%20that%20I'll%20have%20to%20work%20with.%20We%20are%20using%20%22schema%20drift%22%20options%20in%20each%20source%20and%20since%20there%20is%20no%20schema%2C%20there%20is%20no%20projection.%20So%20I'm%20using%20the%20derived%20column%20transformation%20to%20create%20projections.%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F138485i23B8BBFA33632B72%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22scdt1g6.png%22%20title%3D%22scdt1g6.png%22%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F138486i816735B6723560A5%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22scdt1g7.png%22%20title%3D%22scdt1g7.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3EThe%20first%20example%20above%20is%20used%20in%20the%20DimProduct%20source%20stream.%20To%20keep%20this%20pattern%20generic%2C%20I%20am%20looking%20for%20any%20field%20that%20has%20the%20characters%20'ID'%20in%20the%20column%20name%20by%20using%20a%20pattern%20match%20with%20%3CSTRONG%3Einstr()%3C%2FSTRONG%3E.%20Then%20I%20map%20that%20field%20to%20the%20name%20'surrogatekey2'%20so%20that%20I%20can%20use%20that%20canonical%20name%20throughout%20my%20data%20flow.%20Then%20I%20do%20the%20same%20thing%20for%20'businesskey2'.%20For%20this%20to%20work%2C%20the%20dimension%20table%20must%20have%20a%20column%20with%20'Number'%20in%20the%20column%20name%20for%20the%20business%20key.%3C%2FLI%3E%0A%3CLI%3EThe%202nd%20Derived%20Column%20uses%20the%20%3CSTRONG%3EbyPosition()%3C%2FSTRONG%3E%20function%20and%20is%20used%20by%20the%20CSV%20file%20source.%20With%20this%2C%20I%20can%20map%20ordinal%20positions%20in%20the%20file%20to%20my%20business%20key%20from%20the%20updated%20dimensions%20and%20the%20'name'%20field%2C%20which%20I'll%20use%20to%20populate%20in%20the%20dimension%20database%20later.%3C%2FLI%3E%0A%3CLI%3EOn%20the%202nd%20stream%2C%20you'll%20see%20a%20%22MapDrifted%22%20derived%20column%20transformation%20next.%20That%20is%20created%20automatically%20by%20ADF%20when%20I%20click%20%22Map%20Drifted%22%20in%20the%20data%20preview.%20With%20this%2C%20I%20now%20have%20a%20full%20set%20of%20projection%20columns%20from%20a%20drifted%20source%20to%20work%20with.%3C%2FLI%3E%0A%3CLI%3EThe%20next%20step%20in%20the%20flow%20is%20to%20perform%20a%20Lookup.%20This%20will%20match%20incoming%20business%20keys%20with%20existing%20business%20keys%20so%20that%20we%20can%20determine%20what%20action%20to%20take%20with%20the%20products%20file%3A%20update%20or%20insert.%3C%2FLI%3E%0A%3CLI%3EEven%20though%20this%20flow%20is%20generic%20and%20parameterized%2C%20because%20I%20mapped%20the%20key%20fields%20from%20the%20sources%20to%20canonical%20names%2C%20%22businesskey1%22%20and%20%22businesskey2%22%2C%20I%20can%20use%20those%20in%20the%20Lookup%20as%20%3CSTRONG%3Ebusinesskey1%20%3D%3D%20businesskey2%3C%2FSTRONG%3E.%3C%2FLI%3E%0A%3CLI%3ENext%2C%20I%20use%20the%20%3CSTRONG%3EisMatch()%3C%2FSTRONG%3E%20function%20to%20check%20for%20which%20rows%20matched%20and%20which%20ones%20didn't%20match%2C%20then%20add%20a%20Conditional%20Split%20so%20that%20I%20now%20have%20a%20branch%20for%20matches%20and%20a%20branch%20for%20no%20matches.%3C%2FLI%3E%0A%3CLI%3EThe%20matched%20branch%20is%20the%20top%20branch%20in%20the%20diagram%20and%20the%20last%20steps%20will%20be%20a%20Derived%20Column%20to%20set%20properties%20like%20Updated%20Time%20and%20an%20Alter%20Row%20set%20the%20Update%20policy%20to%20%3CSTRONG%3Etrue()%3C%2FSTRONG%3E.%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F138495iB2D35F8A0BCC223E%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_0.png%22%20title%3D%22clipboard_image_0.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3EBecause%20the%20top%20row%20is%20for%20SCD%20Type%201%20updates%2C%20I%20need%20to%20use%20both%20the%20Alter%20Row%20and%20the%20update%20method%20settings%20on%20the%20Sink.%20My%20Sink%20dataset%20will%20be%20the%20same%20dataset%20I'm%20using%20for%20the%20DimProducts%20source.%20There%20is%20no%20schema%20defined%20in%20this%20dataset%20because%20this%20is%20a%20fully%20generic%2C%20template%20pattern.%20So%20I%20will%20set%20%22schema%20drift%22%20on%20for%20the%20sink%2C%20set%20the%20Key%20column%20to%20my%20parameter%20%3CSTRONG%3E%24keycol%3C%2FSTRONG%3E%20and%20allow%20updates.%3C%2FLI%3E%0A%3CLI%3ETo%20build%20a%20proper%20mapping%20for%20the%20dimension%20table%2C%20I%20must%20remove%20all%20drifted%20columns%20from%20the%20file%20source%20and%20only%20land%20the%20appropriate%20database%20columns.%20So%2C%20I'll%20use%20a%20regular%20expression%20in%20the%20name%20matches%20field%20to%20tell%20ADF%20to%20land%20all%20incoming%20columns%20except%20for%20those%20that%20end%20in%20underscore%20because%20those%20are%20unnamed%20drifted%20columns%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F138417iAB4018D4D676A3C6%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22scdt1g4.png%22%20title%3D%22scdt1g4.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3ELastly%2C%20on%20the%20%22no%20matches%20row%22%2C%20I'm%20only%20inserting%20new%20rows%2C%20so%20I%20don't%20need%20an%20Alter%20Row%20policy.%20Instead%2C%20I%20just%20set%20my%20properties%20with%20a%20derived%20column%2C%20then%20I%20use%20a%20Select%20transformation.%3C%2FLI%3E%0A%3CLI%3ESelect%20transformations%20allow%20you%20to%20manipulate%20the%20flow's%20metadata%20columns.%20I%20decided%20to%20use%20this%20to%20build%20my%20mapping%20for%20sink%20rather%20than%20do%20this%20directly%20in%20the%20sink%20like%20I%20did%20for%20the%20match%20row.%20The%20reason%20is%20that%20this%20mapping%20is%20a%20little%20more%20complex%20where%20I%20have%20to%20add%20both%20fixed%20and%20rule-based%20mappings.%20Note%20that%20I%20am%20able%20to%20map%20the%20canonical%20names%20of%20my%20key%20columns%20back%20to%20the%20database%20table%20key%20names%20by%20using%20parameters%20that%20I'll%20set%20in%20the%20data%20flow%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F138416iCE07F49EDBD44573%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22scdt1g5.png%22%20title%3D%22scdt1g5.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3EThe%20Sink%20mapping%20is%20just%20%22auto%20map%22%20because%20I've%20already%20used%20Select%20here%20to%20curate%20my%20fields.%3C%2FLI%3E%0A%3CLI%3ENow%20you%20can%20execute%20this%20data%20from%20a%20pipeline%20and%20set%20all%20of%20your%20parameter%20values%20to%20make%20this%20SCD%20type%201%20work%20across%20different%20dimension%20types.%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F138497iB3E8A0D8259F629C%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_1.png%22%20title%3D%22clipboard_image_1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FOL%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-918519%22%20slang%3D%22en-US%22%3E%3CP%3EAzure%20Data%20Factory's%20Mapping%20Data%20Flows%20feature%20enables%20graphical%20ETL%20designs%20that%20are%20generic%20and%20parameterized.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-918519%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Data%20Factory%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20ETL%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMapping%20Data%20Flows%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-944095%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20Generic%20SCD%20Pattern%20in%20ADF%20Mapping%20Data%20Flows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-944095%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%26nbsp%3B%3C%2FP%3E%3CP%3EI%20just%20tried%20using%20this%20data%20flow%20and%20I%20can't%20%3CSTRONG%3Eupdate%3C%2FSTRONG%3E%20the%20name%20or%20price%20%2C%20for%20example%2C%20however%2C%20%3CSTRONG%3Einsert%3C%2FSTRONG%3E%20a%20new%20line%20(but%20without%20price.%3C%2FP%3E%3CP%3EMy%20file%20CSV%20is%20like%20this%3A%3C%2FP%3E%3CP%3EID%3BNumber%3BNamePrd%3BPrice%3BMDDWhash%3C%2FP%3E%3CUL%3E%3CLI%3E3%3BBFH-16%3BDenver%204You%20Aktivitetsarmband%3B399.90000%3B0xF0F72B3115C548DEDB2A68D1785A8405%26nbsp%3B%20(update%20name)%3C%2FLI%3E%3CLI%3E4%3BFIT-E%3BSamsung%20Galaxy%20XZ%20-%20Aktivitetsarmband%3B499.90000%3B0xEF9F5F41403AFA0DB63908E5EA1F0E95%26nbsp%3B%3CSPAN%3E(update%20name)%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E6%3BVIVOFIT-4%3BGarmin%20Aktivitetsarmband%3B589%3B0x991F6BA23FFE648C11C3E200AD0C5526%26nbsp%3B%3CSPAN%3E(update%20price)%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3BPRO-TIC%3BMobvoi%20Ticwatch%20Pro%20Smartklocka%20Svart%3B2690%3B0xEA90BE3E8EE353BAEDA4C53C4067E673%20(insert)%3C%2FLI%3E%3C%2FUL%3E%3CP%3EI%20had%20to%20make%20some%20changes%2C%20for%20example%20azure%20database%20table%20does%20not%20accept%20more%20than%20one%20timestamp%20column.%20Am%20I%20missing%20something%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-956090%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20Generic%20SCD%20Pattern%20in%20ADF%20Mapping%20Data%20Flows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-956090%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F432673%22%20target%3D%22_blank%22%3E%40AleLem%3C%2FA%3E%26nbsp%3BAre%20you%20using%20an%20AlterRow%20transformation%20and%20a%20database%20sink%3F%20On%20the%20Sink%2C%20you%20must%20allow%20updates%20on%20the%20sink%20settings%20and%20you%20must%20define%20an%20update%20policy%20on%20the%20AlterRow.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-962190%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20Generic%20SCD%20Pattern%20in%20ADF%20Mapping%20Data%20Flows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-962190%22%20slang%3D%22en-US%22%3E%3CP%3ENice%20but%20little%20complex%20to%20follow.%20If%20you%20kindly%20add%20screenshot%20above%20each%20step%20it%20will%20be%20really%20one%20of%20the%20best%20article%20what%20I%20have%20seen%20for%20ADF%20data%20load%3C%2FP%3E%3C%2FLINGO-BODY%3E
Microsoft

Azure Data Factory's Mapping Data Flows feature enables graphical ETL designs that are generic and parameterized. In this example, I'll show you how to create a reusable SCD Type 1 pattern that could be applied to multiple dimension tables by minimizing the number of common columns required, leveraging parameters and ADF's built-in schema drift capability.

 

scdt1g1.png

 

The completed version of this data flow is shown above and is also available as a pipeline template that you can add to your factory by downloading it here and then importing it into your factory. Go to New > "Pipeline from template" and then point to this local file.

 

Typically, when building ETL for a data warehouse solution, you will need to manage many different dimension tables. With ADF Mapping Data Flows, you can minimize the number of different flows that you need to create by creating generic, reusable data flows. The key is to identify the commonality between each dimension table and then create parameters for the elements that change between executions and tables.

 

scdt1g2.png

For this demo data flow, I created string parameters for these elements:

 

1. dimname: can be used to create intermediate files with the name of the dimension

2. keycol: the name of the business key column in the target dimension table. In this case, it is "ProductID"

3. SurrogateKey: the column name for the dimension table's surrogate key (non-business key)

4. tablename: the target dimension table name

 

Inside of the logic in the example, you will see that I am assuming 4 fields will be common in every dimension table in your stars schema model:

 

  1. Name: the member name in the dimension table
  2. _Inserted: timestamp for when the new member was added to the table
  3. _LastUpdated: timestamp for when this member row was last updated
  4. DWhash: a SHA2 hash of the row to use for comparing new vs. old properties in each row

These are all very common attributes used in star schemas. But you can modify these columns and parameters to fit your model. The idea here is to provide a pattern that you can mimic in your business. I explain the steps below, but the best way to get comfortable with this technique is to download this sample and play around with it in your factory.

 

Here are the high-level steps to make this work for more than just one dimension:

 

  1. Sources: There are two sources. One is a file of updated members. In this example, we are using the products dimension. So the first source at the top is a CSV file of members that were changed that day. Because we want this data flow to be reusable, the dataset we use is parameterized. When you execute this data flow from a pipeline, you will set the source filename so that a different file can be processed on every execution. Set a parameter in the source dataset of type Delimited Text called filename. Set this expression in the filename property in the dataset: @dataset().filename. The second source is a database source that points to the DimProducts table. But instead of hardcoding the table name, we'll parameterize it. In the dataset, create a parameter called tablename and use this formula in the table name property (click edit): @dataset().tablename. The 3rd source is used just to grab the max value of the existing surrogate key in the target dimension table. We'll use the dataflow parameters in this query which needs to be constructed from the Expression Builder to provide a string value to ADF: concat('select max(',$SurrogateKey,') as maxsk from ',$tablename).
  2. Derived Column transformations: Both sources use derived column transformations to define the field names that you want to extract from each and then subsequently use in your data flow. The "PickCols" transformation on the 1st and 2nd streams are using pattern matching to create new columns that will be the metadata that I'll have to work with. We are using "schema drift" options in each source and since there is no schema, there is no projection. So I'm using the derived column transformation to create projections.
  3. scdt1g6.pngscdt1g7.png
  4. The first example above is used in the DimProduct source stream. To keep this pattern generic, I am looking for any field that has the characters 'ID' in the column name by using a pattern match with instr(). Then I map that field to the name 'surrogatekey2' so that I can use that canonical name throughout my data flow. Then I do the same thing for 'businesskey2'. For this to work, the dimension table must have a column with 'Number' in the column name for the business key.
  5. The 2nd Derived Column uses the byPosition() function and is used by the CSV file source. With this, I can map ordinal positions in the file to my business key from the updated dimensions and the 'name' field, which I'll use to populate in the dimension database later.
  6. On the 2nd stream, you'll see a "MapDrifted" derived column transformation next. That is created automatically by ADF when I click "Map Drifted" in the data preview. With this, I now have a full set of projection columns from a drifted source to work with.
  7. The next step in the flow is to perform a Lookup. This will match incoming business keys with existing business keys so that we can determine what action to take with the products file: update or insert.
  8. Even though this flow is generic and parameterized, because I mapped the key fields from the sources to canonical names, "businesskey1" and "businesskey2", I can use those in the Lookup as businesskey1 == businesskey2.
  9. Next, I use the isMatch() function to check for which rows matched and which ones didn't match, then add a Conditional Split so that I now have a branch for matches and a branch for no matches.
  10. The matched branch is the top branch in the diagram and the last steps will be a Derived Column to set properties like Updated Time and an Alter Row set the Update policy to true().
  11. clipboard_image_0.png
  12. Because the top row is for SCD Type 1 updates, I need to use both the Alter Row and the update method settings on the Sink. My Sink dataset will be the same dataset I'm using for the DimProducts source. There is no schema defined in this dataset because this is a fully generic, template pattern. So I will set "schema drift" on for the sink, set the Key column to my parameter $keycol and allow updates.
  13. To build a proper mapping for the dimension table, I must remove all drifted columns from the file source and only land the appropriate database columns. So, I'll use a regular expression in the name matches field to tell ADF to land all incoming columns except for those that end in underscore because those are unnamed drifted columns
  14. scdt1g4.png
  15. Lastly, on the "no matches row", I'm only inserting new rows, so I don't need an Alter Row policy. Instead, I just set my properties with a derived column, then I use a Select transformation.
  16. Select transformations allow you to manipulate the flow's metadata columns. I decided to use this to build my mapping for sink rather than do this directly in the sink like I did for the match row. The reason is that this mapping is a little more complex where I have to add both fixed and rule-based mappings. Note that I am able to map the canonical names of my key columns back to the database table key names by using parameters that I'll set in the data flow
  17. scdt1g5.png
  18. The Sink mapping is just "auto map" because I've already used Select here to curate my fields.
  19. Now you can execute this data from a pipeline and set all of your parameter values to make this SCD type 1 work across different dimension types.
  20. clipboard_image_1.png
3 Comments
Occasional Visitor

Hi, 

I just tried using this data flow and I can't update the name or price , for example, however, insert a new line (but without price.

My file CSV is like this:

ID;Number;NamePrd;Price;MDDWhash

  • 3;BFH-16;Denver 4You Aktivitetsarmband;399.90000;0xF0F72B3115C548DEDB2A68D1785A8405  (update name)
  • 4;FIT-E;Samsung Galaxy XZ - Aktivitetsarmband;499.90000;0xEF9F5F41403AFA0DB63908E5EA1F0E95 (update name)
  • 6;VIVOFIT-4;Garmin Aktivitetsarmband;589;0x991F6BA23FFE648C11C3E200AD0C5526 (update price)
  • ;PRO-TIC;Mobvoi Ticwatch Pro Smartklocka Svart;2690;0xEA90BE3E8EE353BAEDA4C53C4067E673 (insert)

I had to make some changes, for example azure database table does not accept more than one timestamp column. Am I missing something?

 

Microsoft

@AleLem Are you using an AlterRow transformation and a database sink? On the Sink, you must allow updates on the sink settings and you must define an update policy on the AlterRow.

Occasional Visitor

Nice but little complex to follow. If you kindly add screenshot above each step it will be really one of the best article what I have seen for ADF data load