biml for beginners - generating ssis packages with bimlscript (sqlsaturday exeter)

63
Biml for Beginners: Generating SSIS packages with BimlScript Cathrine Wilhelmsen April 25th 2015

Upload: cathrine-wilhelmsen

Post on 18-Jul-2015

1.293 views

Category:

Data & Analytics


3 download

TRANSCRIPT

Page 1: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Biml for Beginners:

Generating SSIS packages with BimlScriptCathrine Wilhelmsen

April 25th 2015

Page 2: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Today is brought to you by

and in association with

Page 3: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Please visit our sponsors

Page 4: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

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!

Page 5: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

@cathrinew

cathrinewilhelmsen.netData Warehouse Architect

Business Intelligence Developer

Cathrine Wilhelmsen

Page 6: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Who are you? (*)

SSIS and ETL Developer?

Easily bored?

Tired of repetitive work?

( * Probably not a cat )

Page 7: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

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, resize, connect, align…)

Page 8: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

project done!

new standards

yay

Have you ever experienced this?

Page 9: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

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?)

Page 10: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

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)

Page 11: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Highlights in Biml History

founded by Scott Currie, is born

Biml was extended with

Biml compiler added to

is launched

founded

is launched

2008:

2009:

2011:

2012:

2014:

2015:

Page 12: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

How does it work?

Page 13: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Biml syntax

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

<Connections>

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

</Connections>

<Packages>

<Package Name="EmptyPackage">

</Package>

</Packages>

</Biml>

Page 14: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Biml syntax

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

<Connections>

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

</Connections>

<Packages>

<Package Name="EmptyPackage">

</Package>

</Packages>

</Biml>

Biml Declaration = Root Element

Page 15: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Biml syntax

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

<Connections>

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

</Connections>

<Packages>

<Package Name="EmptyPackage">

</Package>

</Packages>

</Biml>

Logical Objects = Elements

Page 16: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Biml syntax

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

<Connections>

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

</Connections>

<Packages>

<Package Name="EmptyPackage">

</Package>

</Packages>

</Biml>

Child Elements

Page 17: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Biml syntax

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

<Connections>

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

</Connections>

<Packages>

<Package Name="EmptyPackage">

</Package>

</Packages>

</Biml>

Empty Elements

Page 18: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Biml syntax

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

<Connections>

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

</Connections>

<Packages>

<Package Name="EmptyPackage">

</Package>

</Packages>

</Biml>

Attributes

Page 19: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Demo – Biml

Page 20: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

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

Page 21: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Intellisense

Intellisense while typing

CTRL+Space to AutoComplete or show Intellisense

Page 22: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Errors

Red squiggly line: Error

Blue squiggly line: Missing attribute or child element

Error spelling

Missing attribute: ConstraintMode

Page 23: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Errors

Hovering over errors will show descriptive text

Missing attribute: ConstraintMode

Error spelling

Page 24: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Right-click to Check Biml for Errors

Page 25: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Your first SSIS Package from Biml

Right-click on Biml file and click Generate SSIS Packages

Packages will appear under SSIS Packages

Page 26: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

From Biml to SSIS

Page 27: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

From Biml to SSIS

Page 28: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

.biml vs .dtsx

human-readable vs. ALL THE CODE!

Page 29: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

I create SSIS packages faster than that

Page 30: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

But wait!

Page 31: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

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)

Page 32: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

BimlScript code blocks

<#@ … #> Directives

<# … #> Control Blocks

<#= … #> Expression Control Blocks

Page 33: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

BimlScript syntax

<#@ import

namespace="Varigence.Biml.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>

Page 34: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

BimlScript syntax

<#@ import

namespace="Varigence.Biml.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

Page 35: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

BimlScript syntax

<#@ import

namespace="Varigence.Biml.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

Page 36: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

BimlScript syntax

<#@ import

namespace="Varigence.Biml.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

Page 37: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Demo – BimlScript

Page 38: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Basic for loop

<Packages>

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

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

</Package>

<# } #>

</Packages>

Page 39: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

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>

Page 40: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

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

Page 41: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

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

Page 42: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

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>

Page 43: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

<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

Page 44: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

<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

Page 45: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

<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

Page 46: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

<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

Page 47: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

<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

Page 48: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

<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

Page 49: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

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

Page 50: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Demo – Split and combine Biml files

Page 51: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Split and combine multiple Biml files

Create tiered files:

Page 52: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

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

Page 53: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

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

Page 54: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

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

Page 55: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Demo – Include files

Page 56: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

CallBimlScript with parameters

Works like a parameterized include

File to be called (callee) specifies input parameters

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

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

File that calls (caller) provides input parameters

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

CallBimlScript code block is replaced by Biml returned by callee

Page 57: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Demo – CallBimlScript with Parameters

Page 58: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Demo – Don't Repeat Yourself

Page 59: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

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

Page 60: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

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

Page 61: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Biml on Monday...

…BimlBreak the rest of the week

Page 62: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Become a Biml Buccaneer!

Next session:

Building a meta-driven near realtime

ETL solution with BIML and SSIS

Page 63: Biml for Beginners - Generating SSIS Packages with BimlScript (SQLSaturday Exeter)

Thank you!

@cathrinew

cathrinewilhelmsen.net

no.linkedin.com/in/cathrinewilhelmsen

[email protected]

cathrinewilhelmsen.net/biml

slideshare.net/cathrinewilhelmsen