+ All Categories
Home > Data & Analytics > Generate SSIS packages automatically with Biml and BimlScript (SQLKonferenz 2015)

Generate SSIS packages automatically with Biml and BimlScript (SQLKonferenz 2015)

Date post: 06-Aug-2015
Category:
Upload: cathrine-wilhelmsen
View: 741 times
Download: 5 times
Share this document with a friend
Popular Tags:
59
Generate SSIS packages automatically with Biml and BimlScript Cathrine Wilhelmsen February 5th 2015
Transcript

Generate SSIS packages automatically with Biml and BimlScript

Cathrine WilhelmsenFebruary 5th 2015

Session description

SSIS is a powerful tool for extracting, transforming and loading data, but creating the actual SSIS packages can be both tedious and time-consuming. Even if you use templates and follow best practices you often have to repeat the same steps over and over again. There are no easy ways to handle metadata and schema changes, and if there are new requirements you might have to go through all the packages one more time.

It's time to bring the Don't Repeat Yourself principle to SSIS development. In this session I will use the free BIDS Helper add-in to show you the basics of Biml and BimlScript, how to generate SSIS packages automatically from databases, how easy those packages can be changed, and how to move common code to separate files that can be included where needed. See why they say Biml allows you to complete in a day what once took more than a week!

Cathrine Wilhelmsen

@cathrinew

cathrinewilhelmsen.netData Warehouse Architect

Business Intelligence Developer

Who are you? (*)

SSIS and ETL Developer?

Easily bored?

Tired of repetitive work?

( * Probably not a cat )

Why are you here?

Long development time?

Many SSIS packages?

Slow GUI editor?

(Drag, drop, drag, drop, connect, drag, drop, connect,

resize, align, drag, drop, connect, resize, align…)

project done!

new standards

yay

Have you ever experienced this?

How can Biml help you?

Timesaving: Many SSIS Packages from one Biml file

Reusable: Write once and run on any platform (2005 – 2014)

Flexible: Start simple, expand as you learn

(Of course I can create 200 packages!

What do you need me to do after lunch?)

What is Business Intelligence Markup Language?

Easy to read and write XML dialect

Specifies business intelligence objects

Databases, schemas, tables, columns

SSIS packages

SSAS cubes, facts, dimensions (Mist only)

Highlights in Biml History

Scott Currie works on Microsoft's Project Vulcan

2008: Varigence creates Biml and Mist

2011: Biml compiler added to BIDS Helper

(2015: Everyone wonders what we did before Biml?)

(Live Long And Prosper)

How does it work?

Biml syntax

<Biml xmlns="http://schemas.varigence.com/biml.xsd">

<Connections>

<OleDbConnection Name="Source" ConnectionString="…" />

</Connections>

<Packages>

<Package Name="EmptyPackage" ConstraintMode="Linear">

</Package>

</Packages>

</Biml>

Biml syntax

<Biml xmlns="http://schemas.varigence.com/biml.xsd">

<Connections>

<OleDbConnection Name="Source" ConnectionString="…" />

</Connections>

<Packages>

<Package Name="EmptyPackage" ConstraintMode="Linear">

</Package>

</Packages>

</Biml>

Biml Declaration = Root Element

Biml syntax

<Biml xmlns="http://schemas.varigence.com/biml.xsd">

<Connections>

<OleDbConnection Name="Source" ConnectionString="…" />

</Connections>

<Packages>

<Package Name="EmptyPackage" ConstraintMode="Linear">

</Package>

</Packages>

</Biml>

Logical Objects = Elements

Biml syntax

<Biml xmlns="http://schemas.varigence.com/biml.xsd">

<Connections>

<OleDbConnection Name="Source" ConnectionString="…" />

</Connections>

<Packages>

<Package Name="EmptyPackage" ConstraintMode="Linear">

</Package>

</Packages>

</Biml>

Child Elements

Biml syntax

<Biml xmlns="http://schemas.varigence.com/biml.xsd">

<Connections>

<OleDbConnection Name="Source" ConnectionString="…" />

</Connections>

<Packages>

<Package Name="EmptyPackage" ConstraintMode="Linear">

</Package>

</Packages>

</Biml>

Empty Elements

Biml syntax

<Biml xmlns="http://schemas.varigence.com/biml.xsd">

<Connections>

<OleDbConnection Name="Source" ConnectionString="…" />

</Connections>

<Packages>

<Package Name="EmptyPackage" ConstraintMode="Linear">

</Package>

</Packages>

</Biml>

Attributes

Demo – Biml

Getting started with Biml

1. Download and install BIDS Helper (http://bidshelper.codeplex.com)

2. Right-click on SSIS project and click Add New Biml File

Intellisense

Intellisense while typing

CTRL+Space to AutoComplete or show Intellisense

Errors

Red squiggly line: Error

Blue squiggly line: Missing attribute or child element

Error spelling

Missing attribute: ConstraintMode

Errors

Hovering over errors will show descriptive text

Missing attribute: ConstraintMode

Error spelling

Right-click to Check Biml for Errors

Your first SSIS Package from Biml

Right-click on Biml file and click Generate SSIS Packages

Packages will appear under SSIS Packages

From Biml to SSIS

From Biml to SSIS

.biml vs .dtsxhuman-readable vs. ALL THE CODE!

I create SSIS packages faster than that

But wait!

The magic is in the

Extend Biml with C# or VB.NET code blocks

Import database structure and metadata

Loop over tables and columns

Add expressions to replace static values

(And anything else you can do in C# or VB)

BimlScript code blocks

<#@ … #> Directives

<# … #> Control Blocks

<#= … #> Expression Control Blocks

BimlScript syntax

<#@ import namespace="Varigence.Hadron.CoreLowerer.SchemaManagement" #>

<Biml xmlns="http://schemas.varigence.com/biml.xsd">

<Packages>

<# foreach (var table in RootNode.Tables) { #>

<Package Name="Load<#=table.Name#>">

</Package>

<# } #>

</Packages>

</Biml>

BimlScript syntax

<#@ import namespace="Varigence.Hadron.CoreLowerer.SchemaManagement" #>

<Biml xmlns="http://schemas.varigence.com/biml.xsd">

<Packages>

<# foreach (var table in RootNode.Tables) { #>

<Package Name="Load<#=table.Name#>">

</Package>

<# } #>

</Packages>

</Biml>

Directive

BimlScript syntax

<#@ import namespace="Varigence.Hadron.CoreLowerer.SchemaManagement" #>

<Biml xmlns="http://schemas.varigence.com/biml.xsd">

<Packages>

<# foreach (var table in RootNode.Tables) { #>

<Package Name="Load<#=table.Name#>">

</Package>

<# } #>

</Packages>

</Biml>

Control Blocks

BimlScript syntax

<#@ import namespace="Varigence.Hadron.CoreLowerer.SchemaManagement" #>

<Biml xmlns="http://schemas.varigence.com/biml.xsd">

<Packages>

<# foreach (var table in RootNode.Tables) { #>

<Package Name="Load<#=table.Name#>">

</Package>

<# } #>

</Packages>

</Biml>

Expression Control block

Demo – BimlScript

Basic for loop

<Packages>

<# for (int count = 1; count <= 5; count++) { #>

<Package Name="Load_Person_Person_<#=count#>">

</Package>

<# } #>

</Packages>

foreach (table in a database) loop

<#@ import namespace="Varigence.Hadron.CoreLowerer.SchemaManagement" #>

<# var conAW2014 = SchemaManager.CreateConnectionNode("AW2014", "Data Source..."); #>

<# var AW2014DB = conAW2014.ImportDB("","", ImportOptions.ExcludeViews); #>

<Packages>

<# foreach (var table in AW2014DB.TableNodes) { #>

<Package Name="Load_<#=table.Schema#>_<#=table.Name#>">

</Package>

<# } #>

</Packages>

Don't Repeat Yourself

Move common code to separate files

Centralize and reuse in many projects

Update code once for all projects

1. Split and combine Biml files

2. Include files

3. CallBimlScript with parameters

Split and combine Biml files

Multiple Biml files can be compiled together

Control compile order by specifying tiers in files

<#@ template tier="2" #>

Files are compiled into RootNode from lowest to highest tier

Higher tiers can use objects in RootNode from lower tiers

Behind the scenes: compile and load objects into RootNode

RootNode

<#@ template tier="0" #><Connections><Databases><Schemas>

<#@ template tier="1" #><Tables>

<Columns>

<#@ template tier="2" #><Packages>

<Connections><Databases><Schemas>RootNode

<#@ template tier="0" #><Connections><Databases><Schemas>

<#@ template tier="1" #><Tables>

<Columns>

<#@ template tier="2" #><Packages>

compile

Behind the scenes: compile and load objects into RootNode

<Connections><Databases><Schemas>RootNode

<#@ template tier="0" #><Connections><Databases><Schemas>

<#@ template tier="1" #><Tables>

<Columns>

<#@ template tier="2" #><Packages>

use

Behind the scenes: compile and load objects into RootNode

<Connections><Databases><Schemas><Tables>

<Columns>

RootNode

<#@ template tier="0" #><Connections><Databases><Schemas>

<#@ template tier="1" #><Tables>

<Columns>

<#@ template tier="2" #><Packages>

compile

Behind the scenes: compile and load objects into RootNode

<Connections><Databases><Schemas><Tables>

<Columns>

RootNode

<#@ template tier="0" #><Connections><Databases><Schemas>

<#@ template tier="1" #><Tables>

<Columns>

<#@ template tier="2" #><Packages> use

Behind the scenes: compile and load objects into RootNode

<Connections><Databases><Schemas><Tables>

<Columns><Packages>

RootNode

<#@ template tier="0" #><Connections><Databases><Schemas>

<#@ template tier="1" #><Tables>

<Columns>

<#@ template tier="2" #><Packages> compile

Behind the scenes: compile and load objects into RootNode

<Connections><Databases><Schemas><Tables>

<Columns><Packages>

RootNode

<#@ template tier="0" #><Connections><Databases><Schemas>

<#@ template tier="1" #><Tables>

<Columns>

<#@ template tier="2" #><Packages>

generate

Behind the scenes: compile and load objects into RootNode

RootNode

<#@ template tier="0" #><Connections><Databases><Schemas>

<#@ template tier="1" #><Tables>

<Columns>

<#@ template tier="2" #><Packages>

Behind the scenes: compile and load objects into RootNode

Demo – Split and combine Biml files

Split and combine multiple Biml files

Create tiered files:

Split and combine multiple Biml files

Select all the tiered files

Right-click and click Generate SSIS Packages

Behind the scenes: Objects will be compiled and loaded into RootNode from lowest to highest tier

Split and combine multiple Biml files

All packages will be generated at the same time

Load packages from 302LoadAllTables.biml

Master package from 303MasterPackage.biml

Include files

Include common code in multiple files and projects

Use the include directive

<#@ include file="CommonCode.biml" #>

Include directive will be replaced by content of file

Can include several file types: .biml .txt .sql .cs

Demo – Include files

CallBimlScript with parameters

Works like a parameterized include

File to be called (callee) specifies input parameters

<#@ property name="Parameter" type="String" #>

Callee can use parameter values as regular variables and to control logic

File that calls (caller) provides input parameters

<#=CallBimlScript("CommonCode.biml", Parameter)#>

CallBimlScript code block is replaced by Biml returned by callee

Demo – CallBimlScript with Parameters

View compiled Biml

Credits: Marco Schreuder (@in2bi)http://blog.in2bi.eu/biml/viewing-or-saving-the-compiled-biml-file-s/

Helper file with high tier (tier="100")

Saves output of RootNode.GetBiml() to file

What do you do next?

1. Download BIDS Helper

2. Identify your SSIS patterns

3. Rewrite one SSIS package to Biml to learn the basics

4. Expand with BimlScript

5. Get involved in the Biml community

Biml on Monday...

…BimlBreak the rest of the week

Thank you!

@cathrinew

cathrinewilhelmsen.net

no.linkedin.com/in/cathrinewilhelmsen

[email protected]

cathrinewilhelmsen.net/biml

Biml resourcesover there!


Recommended