SlideShare a Scribd company logo
SQLDay 2018
Level Up Your Biml
Best Practices and Coding Techniques
Cathrine Wilhelmsen
@cathrinew
SQLDay 2018
GOLD SPONSORS
SILVER SPONSORS
BRONZE SPONSOR
STRATEGIC PARTNER
SQLDay 2018
Session Description
Is your Biml solution starting to remind you of a bowl of tangled spaghetti
code? Good! That means you are solving real problems while saving a lot of
time. The next step is to make sure that your solution does not grow too
complex and confusing – you do not want to waste all that saved time on
future maintenance!
Attend this session for an overview of Biml best practices and coding
techniques. Learn how to centralize and reuse code with Include files and the
CallBimlScript method. Make your code easier to read and write by utilizing
LINQ (Language-Integrated Queries). Share code between files by using
Annotations and ObjectTags. And finally, if standard Biml is not enough to solve
your problems, you can create your own C# helper classes and extension
methods to implement custom logic.
Start improving your code today and level up your Biml in no time!
SQLDay 2018
Cathrine Wilhelmsen
@cathrinew cathrinew.net
Business Intelligence Consultant
SQLDay 2018
You…
…?
Know basic Biml and BimlScript
Created a staging environment using Biml
Created a metadata-driven Biml framework
SQLDay 2018
…the next 60 minutes…
Practical Biml Coding C# Classes and Methods
Code Management
SQLDay 2018
Biml Tools
SQLDay 2018
Code
Management
SQLDay 2018
Don't Repeat Yourself
Centralize and reuse code
Update once in one file
1. Tiered Biml Files
2. Include Files
3. CallBimlScript
SQLDay 2018
Tiered Biml Files
Multiple Biml Files Working Together
SQLDay 2018
What are Tiered Biml Files?
Think of tiers as stacked layers or sequential steps
Tier (Layer) 1
Tier 0
Tier (Layer) 2
Tier (Step) 1 Tier (Step) 2
SQLDay 2018
Tiered Biml Files
Split Biml code in multiple files to:
• Solve logical dependencies
• Build solutions in multiple steps behind the scenes
Specify the tier per file by using the template directive:
<#@ template tier="2" #>
SQLDay 2018
Tiered Biml Files: Behind the Scenes
Connections
Load Packages
Master Package
Connections
Databases
Schemas
Tables
Packages
SQLDay 2018
Tiered Biml Files: Behind the Scenes
Connections
Databases
Schemas
Tables
Packages
Connections
Load Packages
Master Package
SQLDay 2018
Tiered Biml Files: Behind the Scenes
Connections
Admin
Source
Destination
Databases
Schemas
Tables
Packages
Connections
Load Packages
Master Package
SQLDay 2018
Tiered Biml Files: Behind the Scenes
Connections
Admin
Source
Destination
Databases
Schemas
Tables
Packages
Connections
Load Packages
Master Package
SQLDay 2018
Tiered Biml Files: Behind the Scenes
Connections
Admin
Source
Destination
Databases
Schemas
Tables
Packages
Connections
Load Packages
Master Package
SQLDay 2018
Tiered Biml Files: Behind the Scenes
Connections
Admin
Source
Destination
Databases
Schemas
Tables
Packages
Load_Customer
Load_Product
Load_Sales
Connections
Load Packages
Master Package
SQLDay 2018
Tiered Biml Files: Behind the Scenes
Connections
Admin
Source
Destination
Databases
Schemas
Tables
Packages
Load_Customer
Load_Product
Load_Sales
Connections
Load Packages
Master Package
SQLDay 2018
Tiered Biml Files: Behind the Scenes
Connections
Admin
Source
Destination
Databases
Schemas
Tables
Packages
Load_Customer
Load_Product
Load_Sales
Connections
Load Packages
Master Package
SQLDay 2018
Tiered Biml Files: Behind the Scenes
Connections
Admin
Source
Destination
Databases
Schemas
Tables
Packages
Load_Customer
Load_Product
Load_Sales
Master Connections
Load Packages
Master Package
SQLDay 2018
Tiered Biml Files: Behind the Scenes
Connections
Admin
Source
Destination
Databases
Schemas
Tables
Packages
Load_Customer
Load_Product
Load_Sales
Master Connections
Load Packages
Master Package
SQLDay 2018
Tiered Biml Files: Behind the Scenes
Connections
Admin
Source
Destination
Databases
Schemas
Tables
Packages
Load_Customer
Load_Product
Load_Sales
Master
SQLDay 2018
How do you use Tiered Biml Files?
1. Create Biml files with specified tiers
2. Select all the tiered Biml files
3. Right-click and click Generate SSIS Packages
1
2
3
SQLDay 2018
Annotations and ObjectTags
Store and Pass Metadata Between Biml Files
SQLDay 2018
Annotations and ObjectTags
Annotations and ObjectTags are Key / Value pairs
Annotations: String / String
ObjectTags: String / Object
Store metadata by attaching tags to Biml objects
Higher tier files can get tags from lower tier files
SQLDay 2018
Annotations
Create annotations:
<OleDbConnection Name="Dest">
<Annotations>
<Annotation Tag="Schema">stg</Annotation>
</Annotations>
</OleDbConnection>
Use annotations:
RootNode.OleDbConnections["Dest"].GetTag("Schema");
SQLDay 2018
ObjectTags
Create ObjectTags:
RootNode.OleDbConnections["Dest"].ObjectTag["Filter"]
= new List<string>{"Product","ProductCategory"};
Use ObjectTags:
RootNode.OleDbConnections["Dest"].ObjectTag["Filter"];
SQLDay 2018
Include Files
Automated Copy & Paste
SQLDay 2018
Include Files
Include common code in multiple files and projects
Can include many file types: .biml .txt .sql .cs
Use the include directive
<#@ include file="CommonCode.biml" #>
The directive will be replaced by the included file
Works like an automated Copy & Paste
SQLDay 2018
Include Files
SQLDay 2018
Include Files
SQLDay 2018
Include Files
SQLDay 2018
Global Include Files
Automated Copy & Paste Everywhere
SQLDay 2018
Global Include Files
Use the global directive
<#@ global #>
Use instead of adding include directive to all files to
• Create global variables
• Include code files
• Make VB default language
SQLDay 2018
Global Include Files
Specify attributes to control global include files:
<#@ global
order="1"
location="top"
active="true" #>
SQLDay 2018
Global Include Files
SQLDay 2018
Global Include Files
SQLDay 2018
How do you use Global Include Files?
1. Create Global Include File
2. Select Biml files and Global Include File
3. Right-click and click Generate SSIS Packages
1
2
3
SQLDay 2018
CallBimlScript
Parameterized Control over Returned Code
SQLDay 2018
CallBimlScript
Control and limit the code returned
Works like a parameterized include (or stored procedure)
CallBimlScript file specifies accepted parameters:
<#@ property name="Parameter" type="String" #>
Main file calls and passes parameters:
<#=CallBimlScript("CommonCode.biml", Parameter)#>
SQLDay 2018
CallBimlScript
SQLDay 2018
CallBimlScript
SQLDay 2018
CallBimlScript
SQLDay 2018
CallBimlScript
SQLDay 2018
CallBimlScript
SQLDay 2018
CallBimlScriptWithOutput
Parameterized Control over Returned Code and Objects
SQLDay 2018
CallBimlScriptWithOutput
CallBimlScript file specifies custom output object:
<# CustomOutput.BimlComment = "Comment"; #>
Main file defines, passes and uses output object:
<# dynamic outObj; #>
<#=CallBimlScriptWithOutput("CommonCode.biml",
out outObj)#>
<#=outObj.BimlComment#>
SQLDay 2018
CallBimlScriptWithOutput
SQLDay 2018
CallBimlScriptWithOutput
SQLDay 2018
CallBimlScriptWithOutput
SQLDay 2018
CallBimlScriptWithOutput
SQLDay 2018
CallBimlScriptWithOutput
use CustomOutput
SQLDay 2018
Wait! When do you use what?
In larger projects, you often see a combination of
Tiered Biml Files, Include Files, and CallBimlScript
Rule of Thumb:
If you reuse code more than 3 times,
refactor so you Don't Repeat Yourself
SQLDay 2018
Include Files
Automated Copy & Paste
Code Included As-Is
CallBimlScript
Parameterized
Control Returned Code
Tiered Biml Files
Solve Dependencies
Multi-Step Builds
SQLDay 2018
DEMO
Code
Management
SQLDay 2018
Practical
Biml Coding
SQLDay 2018
LINQ
SQLDay 2018
LINQ (Language-Integrated Query)
One language to query:
SQL Server Databases
Datasets
Collections
Two ways to write queries:
SQL-ish Syntax
Extension Methods
SQLDay 2018
LINQ Extension Methods
Sort
OrderBy, ThenBy
Filter
Where, OfType
Group
GroupBy
Aggregate
Count, Sum
Check Collections
All, Any, Contains
Get Elements
First, Last, ElementAt
Project Collections
Select, SelectMany
SQLDay 2018
LINQ Extension Methods Example
var numConnections = RootNode.Connections.Count()
foreach (var table in RootNode.Tables.Where(…))
if (RootNode.Packages.Any(…))
SQLDay 2018
LINQ Extension Methods Example
foreach (var table in RootNode.Tables.Where(…))
if (RootNode.Packages.Any(…))
But what do you put in here?
SQLDay 2018
Lambda Expressions
"A lambda expression is an anonymous
function that you can use to create
delegates or expression tree types"
SQLDay 2018
Lambda Expressions
…huh? o_O
SQLDay 2018
Lambda Expressions
table => table.Name == "Product"
SQLDay 2018
Lambda Expressions
table => table.Name == "Product"
The arrow is the lambda operator
SQLDay 2018
Lambda Expressions
table => table.Name == "Product"
Input parameter is on the left side
SQLDay 2018
Lambda Expressions
table => table.Name == "Product"
Expression is on the right side
SQLDay 2018
LINQ and Lambda
Chain LINQ Methods and use Lambda Expressions
for simple and powerful querying of collections:
.Where(table => table.Schema.Name == "Production")
.OrderBy(table => table.Name)
SQLDay 2018
LINQ: Filter collections
Where()
Returns the filtered collection with all elements that meet the criteria
RootNode.Tables.Where(t => t.Schema.Name == "Production")
OfType()
Returns the filtered collection with all elements of the specified type
RootNode.Connections.OfType<AstExcelOleDbConnectionNode>()
SQLDay 2018
LINQ: Sort collections
OrderBy()
Returns the collection sorted by key…
RootNode.Tables.OrderBy(t => t.Name)
ThenBy()
…then sorted by secondary key
RootNode.Tables.OrderBy(t => t.Schema.Name)
.ThenBy(t => t.Name)
SQLDay 2018
LINQ: Sort collections
OrderByDescending()
Returns the collection sorted by key…
RootNode.Tables.OrderByDescending(t => t.Name)
ThenByDescending()
…then sorted by secondary key
RootNode.Tables.OrderBy(t => t.Schema.Name)
.ThenByDescending(t => t.Name)
SQLDay 2018
LINQ: Sort collections
Reverse()
Returns the collection sorted in reverse order
RootNode.Tables.Reverse()
SQLDay 2018
LINQ: Group collections
GroupBy()
Returns a collection of key-value pairs where each value is a new collection
RootNode.Tables.GroupBy(t => t.Schema.Name)
SQLDay 2018
LINQ: Aggregate collections
Count()
Returns the number of elements in the collection
RootNode.Tables.Count()
RootNode.Tables.Count(t => t.Schema.Name == "Production")
SQLDay 2018
LINQ: Aggregate collections
Sum()
Returns the sum of the (numeric) values in the collection
RootNode.Tables.Sum(t => t.Columns.Count)
Average()
Returns the average value of the (numeric) values in the collection
RootNode.Tables.Average(t => t.Columns.Count)
SQLDay 2018
LINQ: Aggregate collections
Min()
Returns the minimum value of the (numeric) values in the collection
RootNode.Tables.Min(t => t.Columns.Count)
Max()
Returns the maximum value of the (numeric) values in the collection
RootNode.Tables.Max(t => t.Columns.Count)
SQLDay 2018
LINQ: Check collections
All()
Returns true if all elements in the collection meet the criteria
RootNode.Databases.All(d => d.Name.StartsWith("A"))
Any()
Returns true if any element in the collection meets the criteria
RootNode.Databases.Any(d => d.Name.Contains("DW"))
SQLDay 2018
LINQ: Check collections
Contains()
Returns true if collection contains element
RootNode.Databases.Contains(AdventureWorks2014)
SQLDay 2018
LINQ: Get elements
First()
Returns the first element in the collection (that meets the criteria)
RootNode.Tables.First()
RootNode.Tables.First(t => t.Schema.Name == "Production")
FirstOrDefault()
Returns the first element in the collection or default value (that meets the criteria)
RootNode.Tables.FirstOrDefault()
RootNode.Tables.FirstOrDefault(t => t.Schema.Name ==
"Production")
SQLDay 2018
LINQ: Get elements
Last()
Returns the last element in the collection (that meets the criteria)
RootNode.Tables.Last()
RootNode.Tables.Last(t => t.Schema.Name == "Production")
LastOrDefault()
Returns the last element in the collection or default value (that meets the criteria)
RootNode.Tables.LastOrDefault()
RootNode.Tables.LastOrDefault(t => t.Schema.Name ==
"Production")
SQLDay 2018
LINQ: Get elements
ElementAt()
Returns the element in the collection at the specified index
RootNode.Tables.ElementAt(42)
ElementAtOrDefault()
Returns the element in the collection or default value at the specified index
RootNode.Tables.ElementAtOrDefault(42)
SQLDay 2018
LINQ: Project collections
Select()
Creates a new collection from one collection
A list of table names:
RootNode.Tables.Select(t => t.Name)
A list of table and schema names:
RootNode.Tables.Select(t => new {t.Name, t.Schema.Name})
SQLDay 2018
LINQ: Project collections
SelectMany()
Creates a new collection from many collections and merges the collections
A list of all columns from all tables:
RootNode.Tables.SelectMany(t => t.Columns)
SQLDay 2018
Preview Pane
The power is in the…
SQLDay 2018
BimlExpress Preview Pane
SQLDay 2018
BimlScript to Biml to SSIS
SQLDay 2018
BimlScript to Biml
Preview Pane
SQLDay 2018
BimlScript to …?
Preview Pane
SQLDay 2018
SQLDay 2018
DEMO
Practical
Biml Coding
SQLDay 2018
C# Classes
and Methods
SQLDay 2018
C# Classes and Methods
BimlScript and LINQ not enough?
Need to reuse C# code?
Create your own classes and methods!
SQLDay 2018
C# Classes and Methods
public static class Utilities {
public static string GetName(AstTableNode table) {
return table.Schema.Name.ToUpper()
+ "_" + table.Name.ToUpper();
}
}
SQLDay 2018
C# Classes and Methods: Class
public static class Utilities {
public static string GetName(AstTableNode table) {
return table.Schema.Name.ToUpper()
+ "_" + table.Name.ToUpper();
}
}
SQLDay 2018
C# Classes and Methods: Method
public static class Utilities {
public static string GetName(AstTableNode table) {
return table.Schema.Name.ToUpper()
+ "_" + table.Name.ToUpper();
}
}
SQLDay 2018
C# Classes and Methods: Logic
public static class Utilities {
public static string GetName(AstTableNode table) {
return table.Schema.Name.ToUpper()
+ "_" + table.Name.ToUpper();
}
}
SQLDay 2018
C# Code Management
SQLDay 2018
Inline Code Blocks
<#+ ... #>
<#+ ... #>
SQLDay 2018
Included Biml Files with Code Blocks
<#@ include file="CodeBlock.biml" #>
<#+ ... #>
SQLDay 2018
Code Files
<#@ code file="Code.cs" #>
SQLDay 2018
Code Blocks vs. Code Files
Code Blocks
• Used when logic is specific to one file
• Reuse by including files with code blocks
Code Files
• Use code editor of choice
• Create extension methods
SQLDay 2018
C# Extension Methods
SQLDay 2018
"Make it look like the method belongs
to an object instead of a helper class"
SQLDay 2018
Extension Methods: From this…
<#@ code file="HelperClass.cs" #>
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<# foreach (var table in RootNode.Tables) { #>
<# if (HelperClass.AnnotationTagExists(table, "SourceSchema")) { #>
...
<# } #>
<# } #>
</Biml>
public static class HelperClass {
public static bool AnnotationTagExists(AstNode node, string tag) {
return (node.GetTag(tag) != "") ? true : false;
}
}
SQLDay 2018
Extension Methods: …to this
<#@ code file="HelperClass.cs" #>
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<# foreach (var table in RootNode.Tables) { #>
<# if (HelperClass.AnnotationTagExists(table, "SourceSchema")) { #>
...
<# } #>
<# } #>
</Biml>
public static class HelperClass {
public static bool AnnotationTagExists(this AstNode node, string tag) {
return (node.GetTag(tag) != "") ? true : false;
}
}
SQLDay 2018
Extension Methods: …to this
<#@ code file="HelperClass.cs" #>
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<# foreach (var table in RootNode.Tables) { #>
<# if (table.AnnotationTagExists("SourceSchema")) { #>
...
<# } #>
<# } #>
</Biml>
public static class HelperClass {
public static bool AnnotationTagExists(this AstNode node, string tag) {
return (node.GetTag(tag) != "") ? true : false;
}
}
SQLDay 2018
Extension Methods: …to this :)
<#@ code file="HelperClass.cs" #>
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<# foreach (var table in RootNode.Tables.Where(t =>
t.AnnotationTagExists("SourceSchema")) { #>
...
<# } #>
<# } #>
</Biml>
public static class HelperClass {
public static bool AnnotationTagExists(this AstNode node, string tag) {
return (node.GetTag(tag) != "") ? true : false;
}
}
SQLDay 2018
DEMO
C# Classes
and Methods
SQLDay 2018
…the past 60 minutes…
Practical Biml Coding C# Classes and Methods
Code Management
SQLDay 2018
Where can you learn more?
cathrinew.net/BimlBook
SQLDay 2018
Evaluations
What can we do better? How can we improve?
:):( :|
SQLDay 2018
Get things done
Start small
Start simple
Start with ugly code
Keep going
Expand
Improve
Deliver often
SQLDay 2018
@cathrinew
cathrinew.net
hi@cathrinew.net
Biml resources and demo files:
cathrinew.net/biml

More Related Content

PDF
Level Up Your Biml: Best Practices and Coding Techniques (PASS Summit 2018)
PDF
Biml for Beginners: Script and Automate SSIS development (SQLSaturday Finland)
PDF
Biml for Beginners: Script and Automate SSIS development (Malibu SQL Server U...
PDF
Biml Tips and Tricks: Not Just for SSIS Packages! (SQLGrillen 2018)
PDF
Biml for Beginners: Script and Automate SSIS development (24 Hours of PASS: S...
PDF
Biml for Beginners: Script and Automate SSIS development (Hybrid VC)
PDF
Biml Tips and Tricks: Not Just for SSIS Packages! (SQLBits 2019)
PDF
Biml for Beginners: Script and Automate SSIS development (Capital Area SQL Se...
Level Up Your Biml: Best Practices and Coding Techniques (PASS Summit 2018)
Biml for Beginners: Script and Automate SSIS development (SQLSaturday Finland)
Biml for Beginners: Script and Automate SSIS development (Malibu SQL Server U...
Biml Tips and Tricks: Not Just for SSIS Packages! (SQLGrillen 2018)
Biml for Beginners: Script and Automate SSIS development (24 Hours of PASS: S...
Biml for Beginners: Script and Automate SSIS development (Hybrid VC)
Biml Tips and Tricks: Not Just for SSIS Packages! (SQLBits 2019)
Biml for Beginners: Script and Automate SSIS development (Capital Area SQL Se...

What's hot (12)

PDF
Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018)
PDF
Biml for Beginners: Script and Automate SSIS development (SQLSaturday Oslo)
PDF
Biml for Beginners: Script and Automate SSIS development (SQLSaturday Chicago)
PDF
O365Engage17 - Using Exchange Online to Classify and Secure Mail
PDF
O365Engage17 - Options for staying compliant in exchange online
PDF
O365Engage17 - Protecting O365 Data in a Modern World
PDF
O365Engage17 - Smart Email Migration Knowing What’s Lurking in the ‘Dark Corn...
PDF
Event Sourcing with Microservices
PDF
Tools and Tips For Data Warehouse Developers (SQLGLA)
PDF
5 Reasons not to use Dita from a CCMS Perspective
PDF
Alternatives for Systems Integration in the NoSQL Era - NoSQL Roadshow 2013
PDF
O365Engage17 - Search Center and the Power of Content Types
Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018)
Biml for Beginners: Script and Automate SSIS development (SQLSaturday Oslo)
Biml for Beginners: Script and Automate SSIS development (SQLSaturday Chicago)
O365Engage17 - Using Exchange Online to Classify and Secure Mail
O365Engage17 - Options for staying compliant in exchange online
O365Engage17 - Protecting O365 Data in a Modern World
O365Engage17 - Smart Email Migration Knowing What’s Lurking in the ‘Dark Corn...
Event Sourcing with Microservices
Tools and Tips For Data Warehouse Developers (SQLGLA)
5 Reasons not to use Dita from a CCMS Perspective
Alternatives for Systems Integration in the NoSQL Era - NoSQL Roadshow 2013
O365Engage17 - Search Center and the Power of Content Types
Ad

Similar to Level Up Your Biml: Best Practices and Coding Techniques (SQLDay 2018) (20)

PDF
Don't Repeat Yourself - An Introduction to Agile SSIS Development (24 Hours o...
PDF
Level Up Your Biml: Best Practices and Coding Techniques (SQLSaturday Minnesota)
PDF
Level Up Your Biml: Best Practices and Coding Techniques (SQLSaturday Sacrame...
PDF
Level Up Your Biml: Best Practices and Coding Techniques (SQLSaturday Oslo)
PDF
Level Up Your Biml: Best Practices and Coding Techniques (TUGA IT 2016)
PDF
Biml for Beginners: Speed up your SSIS development (Malta Microsoft Data Plat...
PDF
Biml for Beginners: Speed up your SSIS development (SQLSaturday Chicago)
PDF
Biml for Beginners: Speed up your SSIS development (SQL PASS Edmonton )
PDF
Biml for Beginners: Speed up your SSIS development (SQLSaturday Vienna)
PDF
CI/CD Templates: Continuous Delivery of ML-Enabled Data Pipelines on Databricks
PDF
Level Up Your Biml: Best Practices and Coding Techniques (NTK 2016)
PDF
Biml for Beginners: Speed up your SSIS development (SQLSaturday Vancouver)
PDF
Biml for Beginners: Speed up your SSIS development (SQLSaturday Nashville)
PPT
Rails Rookies Bootcamp - Blogger
PDF
Domain Driven Design
PPTX
MSBI Online Training in Hyderabad
PPTX
MSBI Online Training
PPTX
MSBI Online Training in India
PDF
Biml for Beginners: Speed up your SSIS development (SQLSaturday Tallinn)
PDF
Dot Net Fundamentals
Don't Repeat Yourself - An Introduction to Agile SSIS Development (24 Hours o...
Level Up Your Biml: Best Practices and Coding Techniques (SQLSaturday Minnesota)
Level Up Your Biml: Best Practices and Coding Techniques (SQLSaturday Sacrame...
Level Up Your Biml: Best Practices and Coding Techniques (SQLSaturday Oslo)
Level Up Your Biml: Best Practices and Coding Techniques (TUGA IT 2016)
Biml for Beginners: Speed up your SSIS development (Malta Microsoft Data Plat...
Biml for Beginners: Speed up your SSIS development (SQLSaturday Chicago)
Biml for Beginners: Speed up your SSIS development (SQL PASS Edmonton )
Biml for Beginners: Speed up your SSIS development (SQLSaturday Vienna)
CI/CD Templates: Continuous Delivery of ML-Enabled Data Pipelines on Databricks
Level Up Your Biml: Best Practices and Coding Techniques (NTK 2016)
Biml for Beginners: Speed up your SSIS development (SQLSaturday Vancouver)
Biml for Beginners: Speed up your SSIS development (SQLSaturday Nashville)
Rails Rookies Bootcamp - Blogger
Domain Driven Design
MSBI Online Training in Hyderabad
MSBI Online Training
MSBI Online Training in India
Biml for Beginners: Speed up your SSIS development (SQLSaturday Tallinn)
Dot Net Fundamentals
Ad

More from Cathrine Wilhelmsen (20)

PDF
Fra utvikler til arkitekt: Skap din egen karrierevei ved å utvikle din person...
PDF
One Year in Fabric: Lessons Learned from Implementing Real-World Projects (PA...
PDF
Data Factory in Microsoft Fabric (MsBIP #82)
PDF
Getting Started: Data Factory in Microsoft Fabric (Microsoft Fabric Community...
PDF
Choosing Between Microsoft Fabric, Azure Synapse Analytics and Azure Data Fac...
PDF
Website Analytics in My Pocket using Microsoft Fabric (SQLBits 2024)
PDF
Data Integration using Data Factory in Microsoft Fabric (ESPC Microsoft Fabri...
PDF
Choosing between Fabric, Synapse and Databricks (Data Left Unattended 2023)
PDF
Data Integration with Data Factory (Microsoft Fabric Day Oslo 2023)
PDF
The Battle of the Data Transformation Tools (PASS Data Community Summit 2023)
PDF
Visually Transform Data in Azure Data Factory or Azure Synapse Analytics (PAS...
PDF
Building an End-to-End Solution in Microsoft Fabric: From Dataverse to Power ...
PDF
Website Analytics in my Pocket using Microsoft Fabric (AdaCon 2023)
PDF
Choosing Between Microsoft Fabric, Azure Synapse Analytics and Azure Data Fac...
PDF
Stressed, Depressed, or Burned Out? The Warning Signs You Shouldn't Ignore (D...
PDF
Stressed, Depressed, or Burned Out? The Warning Signs You Shouldn't Ignore (S...
PDF
"I can't keep up!" - Turning Discomfort into Personal Growth in a Fast-Paced ...
PDF
Lessons Learned: Implementing Azure Synapse Analytics in a Rapidly-Changing S...
PDF
6 Tips for Building Confidence as a Public Speaker (SQLBits 2022)
PDF
Lessons Learned: Understanding Pipeline Pricing in Azure Data Factory and Azu...
Fra utvikler til arkitekt: Skap din egen karrierevei ved å utvikle din person...
One Year in Fabric: Lessons Learned from Implementing Real-World Projects (PA...
Data Factory in Microsoft Fabric (MsBIP #82)
Getting Started: Data Factory in Microsoft Fabric (Microsoft Fabric Community...
Choosing Between Microsoft Fabric, Azure Synapse Analytics and Azure Data Fac...
Website Analytics in My Pocket using Microsoft Fabric (SQLBits 2024)
Data Integration using Data Factory in Microsoft Fabric (ESPC Microsoft Fabri...
Choosing between Fabric, Synapse and Databricks (Data Left Unattended 2023)
Data Integration with Data Factory (Microsoft Fabric Day Oslo 2023)
The Battle of the Data Transformation Tools (PASS Data Community Summit 2023)
Visually Transform Data in Azure Data Factory or Azure Synapse Analytics (PAS...
Building an End-to-End Solution in Microsoft Fabric: From Dataverse to Power ...
Website Analytics in my Pocket using Microsoft Fabric (AdaCon 2023)
Choosing Between Microsoft Fabric, Azure Synapse Analytics and Azure Data Fac...
Stressed, Depressed, or Burned Out? The Warning Signs You Shouldn't Ignore (D...
Stressed, Depressed, or Burned Out? The Warning Signs You Shouldn't Ignore (S...
"I can't keep up!" - Turning Discomfort into Personal Growth in a Fast-Paced ...
Lessons Learned: Implementing Azure Synapse Analytics in a Rapidly-Changing S...
6 Tips for Building Confidence as a Public Speaker (SQLBits 2022)
Lessons Learned: Understanding Pipeline Pricing in Azure Data Factory and Azu...

Recently uploaded (20)

PPT
Quality review (1)_presentation of this 21
PPTX
Business Ppt On Nestle.pptx huunnnhhgfvu
PDF
Foundation of Data Science unit number two notes
PPTX
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
PPTX
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
PPTX
Introduction to Knowledge Engineering Part 1
PDF
Business Analytics and business intelligence.pdf
PPTX
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
PPTX
oil_refinery_comprehensive_20250804084928 (1).pptx
PPTX
STUDY DESIGN details- Lt Col Maksud (21).pptx
PPTX
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
PPTX
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
PDF
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
PPTX
Computer network topology notes for revision
PDF
Lecture1 pattern recognition............
PPT
Miokarditis (Inflamasi pada Otot Jantung)
PDF
Clinical guidelines as a resource for EBP(1).pdf
PPTX
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
PPTX
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
Quality review (1)_presentation of this 21
Business Ppt On Nestle.pptx huunnnhhgfvu
Foundation of Data Science unit number two notes
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
Introduction to Knowledge Engineering Part 1
Business Analytics and business intelligence.pdf
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
oil_refinery_comprehensive_20250804084928 (1).pptx
STUDY DESIGN details- Lt Col Maksud (21).pptx
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
Computer network topology notes for revision
Lecture1 pattern recognition............
Miokarditis (Inflamasi pada Otot Jantung)
Clinical guidelines as a resource for EBP(1).pdf
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
Recruitment and Placement PPT.pdfbjfibjdfbjfobj

Level Up Your Biml: Best Practices and Coding Techniques (SQLDay 2018)

  • 1. SQLDay 2018 Level Up Your Biml Best Practices and Coding Techniques Cathrine Wilhelmsen @cathrinew
  • 2. SQLDay 2018 GOLD SPONSORS SILVER SPONSORS BRONZE SPONSOR STRATEGIC PARTNER
  • 3. SQLDay 2018 Session Description Is your Biml solution starting to remind you of a bowl of tangled spaghetti code? Good! That means you are solving real problems while saving a lot of time. The next step is to make sure that your solution does not grow too complex and confusing – you do not want to waste all that saved time on future maintenance! Attend this session for an overview of Biml best practices and coding techniques. Learn how to centralize and reuse code with Include files and the CallBimlScript method. Make your code easier to read and write by utilizing LINQ (Language-Integrated Queries). Share code between files by using Annotations and ObjectTags. And finally, if standard Biml is not enough to solve your problems, you can create your own C# helper classes and extension methods to implement custom logic. Start improving your code today and level up your Biml in no time!
  • 4. SQLDay 2018 Cathrine Wilhelmsen @cathrinew cathrinew.net Business Intelligence Consultant
  • 5. SQLDay 2018 You… …? Know basic Biml and BimlScript Created a staging environment using Biml Created a metadata-driven Biml framework
  • 6. SQLDay 2018 …the next 60 minutes… Practical Biml Coding C# Classes and Methods Code Management
  • 9. SQLDay 2018 Don't Repeat Yourself Centralize and reuse code Update once in one file 1. Tiered Biml Files 2. Include Files 3. CallBimlScript
  • 10. SQLDay 2018 Tiered Biml Files Multiple Biml Files Working Together
  • 11. SQLDay 2018 What are Tiered Biml Files? Think of tiers as stacked layers or sequential steps Tier (Layer) 1 Tier 0 Tier (Layer) 2 Tier (Step) 1 Tier (Step) 2
  • 12. SQLDay 2018 Tiered Biml Files Split Biml code in multiple files to: • Solve logical dependencies • Build solutions in multiple steps behind the scenes Specify the tier per file by using the template directive: <#@ template tier="2" #>
  • 13. SQLDay 2018 Tiered Biml Files: Behind the Scenes Connections Load Packages Master Package Connections Databases Schemas Tables Packages
  • 14. SQLDay 2018 Tiered Biml Files: Behind the Scenes Connections Databases Schemas Tables Packages Connections Load Packages Master Package
  • 15. SQLDay 2018 Tiered Biml Files: Behind the Scenes Connections Admin Source Destination Databases Schemas Tables Packages Connections Load Packages Master Package
  • 16. SQLDay 2018 Tiered Biml Files: Behind the Scenes Connections Admin Source Destination Databases Schemas Tables Packages Connections Load Packages Master Package
  • 17. SQLDay 2018 Tiered Biml Files: Behind the Scenes Connections Admin Source Destination Databases Schemas Tables Packages Connections Load Packages Master Package
  • 18. SQLDay 2018 Tiered Biml Files: Behind the Scenes Connections Admin Source Destination Databases Schemas Tables Packages Load_Customer Load_Product Load_Sales Connections Load Packages Master Package
  • 19. SQLDay 2018 Tiered Biml Files: Behind the Scenes Connections Admin Source Destination Databases Schemas Tables Packages Load_Customer Load_Product Load_Sales Connections Load Packages Master Package
  • 20. SQLDay 2018 Tiered Biml Files: Behind the Scenes Connections Admin Source Destination Databases Schemas Tables Packages Load_Customer Load_Product Load_Sales Connections Load Packages Master Package
  • 21. SQLDay 2018 Tiered Biml Files: Behind the Scenes Connections Admin Source Destination Databases Schemas Tables Packages Load_Customer Load_Product Load_Sales Master Connections Load Packages Master Package
  • 22. SQLDay 2018 Tiered Biml Files: Behind the Scenes Connections Admin Source Destination Databases Schemas Tables Packages Load_Customer Load_Product Load_Sales Master Connections Load Packages Master Package
  • 23. SQLDay 2018 Tiered Biml Files: Behind the Scenes Connections Admin Source Destination Databases Schemas Tables Packages Load_Customer Load_Product Load_Sales Master
  • 24. SQLDay 2018 How do you use Tiered Biml Files? 1. Create Biml files with specified tiers 2. Select all the tiered Biml files 3. Right-click and click Generate SSIS Packages 1 2 3
  • 25. SQLDay 2018 Annotations and ObjectTags Store and Pass Metadata Between Biml Files
  • 26. SQLDay 2018 Annotations and ObjectTags Annotations and ObjectTags are Key / Value pairs Annotations: String / String ObjectTags: String / Object Store metadata by attaching tags to Biml objects Higher tier files can get tags from lower tier files
  • 27. SQLDay 2018 Annotations Create annotations: <OleDbConnection Name="Dest"> <Annotations> <Annotation Tag="Schema">stg</Annotation> </Annotations> </OleDbConnection> Use annotations: RootNode.OleDbConnections["Dest"].GetTag("Schema");
  • 28. SQLDay 2018 ObjectTags Create ObjectTags: RootNode.OleDbConnections["Dest"].ObjectTag["Filter"] = new List<string>{"Product","ProductCategory"}; Use ObjectTags: RootNode.OleDbConnections["Dest"].ObjectTag["Filter"];
  • 30. SQLDay 2018 Include Files Include common code in multiple files and projects Can include many file types: .biml .txt .sql .cs Use the include directive <#@ include file="CommonCode.biml" #> The directive will be replaced by the included file Works like an automated Copy & Paste
  • 34. SQLDay 2018 Global Include Files Automated Copy & Paste Everywhere
  • 35. SQLDay 2018 Global Include Files Use the global directive <#@ global #> Use instead of adding include directive to all files to • Create global variables • Include code files • Make VB default language
  • 36. SQLDay 2018 Global Include Files Specify attributes to control global include files: <#@ global order="1" location="top" active="true" #>
  • 39. SQLDay 2018 How do you use Global Include Files? 1. Create Global Include File 2. Select Biml files and Global Include File 3. Right-click and click Generate SSIS Packages 1 2 3
  • 41. SQLDay 2018 CallBimlScript Control and limit the code returned Works like a parameterized include (or stored procedure) CallBimlScript file specifies accepted parameters: <#@ property name="Parameter" type="String" #> Main file calls and passes parameters: <#=CallBimlScript("CommonCode.biml", Parameter)#>
  • 48. SQLDay 2018 CallBimlScriptWithOutput CallBimlScript file specifies custom output object: <# CustomOutput.BimlComment = "Comment"; #> Main file defines, passes and uses output object: <# dynamic outObj; #> <#=CallBimlScriptWithOutput("CommonCode.biml", out outObj)#> <#=outObj.BimlComment#>
  • 54. SQLDay 2018 Wait! When do you use what? In larger projects, you often see a combination of Tiered Biml Files, Include Files, and CallBimlScript Rule of Thumb: If you reuse code more than 3 times, refactor so you Don't Repeat Yourself
  • 55. SQLDay 2018 Include Files Automated Copy & Paste Code Included As-Is CallBimlScript Parameterized Control Returned Code Tiered Biml Files Solve Dependencies Multi-Step Builds
  • 59. SQLDay 2018 LINQ (Language-Integrated Query) One language to query: SQL Server Databases Datasets Collections Two ways to write queries: SQL-ish Syntax Extension Methods
  • 60. SQLDay 2018 LINQ Extension Methods Sort OrderBy, ThenBy Filter Where, OfType Group GroupBy Aggregate Count, Sum Check Collections All, Any, Contains Get Elements First, Last, ElementAt Project Collections Select, SelectMany
  • 61. SQLDay 2018 LINQ Extension Methods Example var numConnections = RootNode.Connections.Count() foreach (var table in RootNode.Tables.Where(…)) if (RootNode.Packages.Any(…))
  • 62. SQLDay 2018 LINQ Extension Methods Example foreach (var table in RootNode.Tables.Where(…)) if (RootNode.Packages.Any(…)) But what do you put in here?
  • 63. SQLDay 2018 Lambda Expressions "A lambda expression is an anonymous function that you can use to create delegates or expression tree types"
  • 65. SQLDay 2018 Lambda Expressions table => table.Name == "Product"
  • 66. SQLDay 2018 Lambda Expressions table => table.Name == "Product" The arrow is the lambda operator
  • 67. SQLDay 2018 Lambda Expressions table => table.Name == "Product" Input parameter is on the left side
  • 68. SQLDay 2018 Lambda Expressions table => table.Name == "Product" Expression is on the right side
  • 69. SQLDay 2018 LINQ and Lambda Chain LINQ Methods and use Lambda Expressions for simple and powerful querying of collections: .Where(table => table.Schema.Name == "Production") .OrderBy(table => table.Name)
  • 70. SQLDay 2018 LINQ: Filter collections Where() Returns the filtered collection with all elements that meet the criteria RootNode.Tables.Where(t => t.Schema.Name == "Production") OfType() Returns the filtered collection with all elements of the specified type RootNode.Connections.OfType<AstExcelOleDbConnectionNode>()
  • 71. SQLDay 2018 LINQ: Sort collections OrderBy() Returns the collection sorted by key… RootNode.Tables.OrderBy(t => t.Name) ThenBy() …then sorted by secondary key RootNode.Tables.OrderBy(t => t.Schema.Name) .ThenBy(t => t.Name)
  • 72. SQLDay 2018 LINQ: Sort collections OrderByDescending() Returns the collection sorted by key… RootNode.Tables.OrderByDescending(t => t.Name) ThenByDescending() …then sorted by secondary key RootNode.Tables.OrderBy(t => t.Schema.Name) .ThenByDescending(t => t.Name)
  • 73. SQLDay 2018 LINQ: Sort collections Reverse() Returns the collection sorted in reverse order RootNode.Tables.Reverse()
  • 74. SQLDay 2018 LINQ: Group collections GroupBy() Returns a collection of key-value pairs where each value is a new collection RootNode.Tables.GroupBy(t => t.Schema.Name)
  • 75. SQLDay 2018 LINQ: Aggregate collections Count() Returns the number of elements in the collection RootNode.Tables.Count() RootNode.Tables.Count(t => t.Schema.Name == "Production")
  • 76. SQLDay 2018 LINQ: Aggregate collections Sum() Returns the sum of the (numeric) values in the collection RootNode.Tables.Sum(t => t.Columns.Count) Average() Returns the average value of the (numeric) values in the collection RootNode.Tables.Average(t => t.Columns.Count)
  • 77. SQLDay 2018 LINQ: Aggregate collections Min() Returns the minimum value of the (numeric) values in the collection RootNode.Tables.Min(t => t.Columns.Count) Max() Returns the maximum value of the (numeric) values in the collection RootNode.Tables.Max(t => t.Columns.Count)
  • 78. SQLDay 2018 LINQ: Check collections All() Returns true if all elements in the collection meet the criteria RootNode.Databases.All(d => d.Name.StartsWith("A")) Any() Returns true if any element in the collection meets the criteria RootNode.Databases.Any(d => d.Name.Contains("DW"))
  • 79. SQLDay 2018 LINQ: Check collections Contains() Returns true if collection contains element RootNode.Databases.Contains(AdventureWorks2014)
  • 80. SQLDay 2018 LINQ: Get elements First() Returns the first element in the collection (that meets the criteria) RootNode.Tables.First() RootNode.Tables.First(t => t.Schema.Name == "Production") FirstOrDefault() Returns the first element in the collection or default value (that meets the criteria) RootNode.Tables.FirstOrDefault() RootNode.Tables.FirstOrDefault(t => t.Schema.Name == "Production")
  • 81. SQLDay 2018 LINQ: Get elements Last() Returns the last element in the collection (that meets the criteria) RootNode.Tables.Last() RootNode.Tables.Last(t => t.Schema.Name == "Production") LastOrDefault() Returns the last element in the collection or default value (that meets the criteria) RootNode.Tables.LastOrDefault() RootNode.Tables.LastOrDefault(t => t.Schema.Name == "Production")
  • 82. SQLDay 2018 LINQ: Get elements ElementAt() Returns the element in the collection at the specified index RootNode.Tables.ElementAt(42) ElementAtOrDefault() Returns the element in the collection or default value at the specified index RootNode.Tables.ElementAtOrDefault(42)
  • 83. SQLDay 2018 LINQ: Project collections Select() Creates a new collection from one collection A list of table names: RootNode.Tables.Select(t => t.Name) A list of table and schema names: RootNode.Tables.Select(t => new {t.Name, t.Schema.Name})
  • 84. SQLDay 2018 LINQ: Project collections SelectMany() Creates a new collection from many collections and merges the collections A list of all columns from all tables: RootNode.Tables.SelectMany(t => t.Columns)
  • 85. SQLDay 2018 Preview Pane The power is in the…
  • 88. SQLDay 2018 BimlScript to Biml Preview Pane
  • 89. SQLDay 2018 BimlScript to …? Preview Pane
  • 93. SQLDay 2018 C# Classes and Methods BimlScript and LINQ not enough? Need to reuse C# code? Create your own classes and methods!
  • 94. SQLDay 2018 C# Classes and Methods public static class Utilities { public static string GetName(AstTableNode table) { return table.Schema.Name.ToUpper() + "_" + table.Name.ToUpper(); } }
  • 95. SQLDay 2018 C# Classes and Methods: Class public static class Utilities { public static string GetName(AstTableNode table) { return table.Schema.Name.ToUpper() + "_" + table.Name.ToUpper(); } }
  • 96. SQLDay 2018 C# Classes and Methods: Method public static class Utilities { public static string GetName(AstTableNode table) { return table.Schema.Name.ToUpper() + "_" + table.Name.ToUpper(); } }
  • 97. SQLDay 2018 C# Classes and Methods: Logic public static class Utilities { public static string GetName(AstTableNode table) { return table.Schema.Name.ToUpper() + "_" + table.Name.ToUpper(); } }
  • 98. SQLDay 2018 C# Code Management
  • 99. SQLDay 2018 Inline Code Blocks <#+ ... #> <#+ ... #>
  • 100. SQLDay 2018 Included Biml Files with Code Blocks <#@ include file="CodeBlock.biml" #> <#+ ... #>
  • 101. SQLDay 2018 Code Files <#@ code file="Code.cs" #>
  • 102. SQLDay 2018 Code Blocks vs. Code Files Code Blocks • Used when logic is specific to one file • Reuse by including files with code blocks Code Files • Use code editor of choice • Create extension methods
  • 104. SQLDay 2018 "Make it look like the method belongs to an object instead of a helper class"
  • 105. SQLDay 2018 Extension Methods: From this… <#@ code file="HelperClass.cs" #> <Biml xmlns="http://schemas.varigence.com/biml.xsd"> <# foreach (var table in RootNode.Tables) { #> <# if (HelperClass.AnnotationTagExists(table, "SourceSchema")) { #> ... <# } #> <# } #> </Biml> public static class HelperClass { public static bool AnnotationTagExists(AstNode node, string tag) { return (node.GetTag(tag) != "") ? true : false; } }
  • 106. SQLDay 2018 Extension Methods: …to this <#@ code file="HelperClass.cs" #> <Biml xmlns="http://schemas.varigence.com/biml.xsd"> <# foreach (var table in RootNode.Tables) { #> <# if (HelperClass.AnnotationTagExists(table, "SourceSchema")) { #> ... <# } #> <# } #> </Biml> public static class HelperClass { public static bool AnnotationTagExists(this AstNode node, string tag) { return (node.GetTag(tag) != "") ? true : false; } }
  • 107. SQLDay 2018 Extension Methods: …to this <#@ code file="HelperClass.cs" #> <Biml xmlns="http://schemas.varigence.com/biml.xsd"> <# foreach (var table in RootNode.Tables) { #> <# if (table.AnnotationTagExists("SourceSchema")) { #> ... <# } #> <# } #> </Biml> public static class HelperClass { public static bool AnnotationTagExists(this AstNode node, string tag) { return (node.GetTag(tag) != "") ? true : false; } }
  • 108. SQLDay 2018 Extension Methods: …to this :) <#@ code file="HelperClass.cs" #> <Biml xmlns="http://schemas.varigence.com/biml.xsd"> <# foreach (var table in RootNode.Tables.Where(t => t.AnnotationTagExists("SourceSchema")) { #> ... <# } #> <# } #> </Biml> public static class HelperClass { public static bool AnnotationTagExists(this AstNode node, string tag) { return (node.GetTag(tag) != "") ? true : false; } }
  • 110. SQLDay 2018 …the past 60 minutes… Practical Biml Coding C# Classes and Methods Code Management
  • 111. SQLDay 2018 Where can you learn more? cathrinew.net/BimlBook
  • 112. SQLDay 2018 Evaluations What can we do better? How can we improve? :):( :|
  • 113. SQLDay 2018 Get things done Start small Start simple Start with ugly code Keep going Expand Improve Deliver often