Categories
Business Intelligence Geeky/Programming SQLServerPedia Syndication

SSIS – Slowly Changing Dimensions with Checksum

In the Microsoft Business Intelligence world, most people use SQL Server Integration Services (SSIS) to do their ETL. Usually with your ETL you are building a DataMart or OLAP Database so then you can build a multi-dimensional cube using SQL Server Analysis Services (SSAS) or report on data using SQL Server Reporting Services (SSRS).

When creating the ETL using SSIS, you pull data from one or many sources (usually an OLTP database) and summarize it, put it into a snowflake or star schema in your DataMart. You build you Dimension tables and Fact tables, which you can then build your Dims and Measures in SSAS.

When building and populating your Dimensions in SSIS, you pull data from a source table, and then move it to your dimension table (in the most basic sense).

You can handle situations in different ways (SCD type 1, SCD type 2, etc) – basically, should you update records, or mark them as old and add new records, etc.

The basic problem with dimension loading comes in with grabbing data from the source, checking if you already have it in your destination dimension table, and then either inserting, updating, or ignoring it.

SSIS has a built in transformation, called the “Slowly Changing Dimension” wizard. You give it some source data, you go through some wizard screens, choosing what columns from your source are “business keys” (columns that are the unique key/primary key in your source table) and what other columns you want. You choose if the other columns are changing or historical columns, and then choose what should happen when data is different, update the records directly, or add date columns, etc.

Once you get through the SCD wizard, some things happen behind the scenes, and you see the insert, update transformations are there and things just “work” when you you run your package.

What most people fail to do, is tweak any settings with the automagically created transformations. You should tweak some things depending on your environment, size of source/destination data, etc.

What I have found in my experience though, is that the SCD is good for smaller dimensions (less than 10,000 records). When you get a dimension that grows larger than that, things slow down dramatically. For example, a dimension with 2 million, or 10 million or more records, will run really slow using the SCD wizard – it will take 15-20 minutes to process a 2 million row dimension.

What else can you do besides use the SCD wizard?

I have tried a few other 3rd party SCD “wizard” transformations, and I couldn’t get them to work correctly in my environment, or they didn’t work correctly. What I have found to work the best, the fastest and the most reliable is using a “checksum SCD method”

The checksum method works similarly to the SCD wizard, but you basically do it yourself.

First, you need to get a checksum transformation (you can download here: http://www.sqlis.com/post/Checksum-Transformation.aspx)

The basic layout of your package to populate a dimension will be like this:


What you want to do, is add a column your dimension destination table called “RowChecksum” that is a BIGINT. Allow nulls, you can update them all to 0 by default if you want, etc.

In your “Get Source Data” Source, add the column to the result query. In your “Checksum Transformation”, add the columns that you want your checksum to be created on. What you want to add is all the columns that AREN’T your business keys.

In your “Lookup Transformation”, your query should grab from your destination the checksum column and the business key or keys. Map the business keys as the lookup columns, add the dimension key as a new column on the output, and the existing checksum column as a new column as well.

So you do a lookup, and if the record already exists, its going to come out the valid output (green line) and you should tie that to your conditional transformation. You need to take the error output from the lookup to your insert destination. (Think of it this way, you do a lookup, you couldn’t find a match, so it is an “error condition, the row doesn’t already exist in your destination, so you INSERT it).

On the conditional transformation, you need to do a check if the existing checksum == the new checksum. If they equal, you don’t need to do anything. You can just ignore that output, but I find it useful to use a trash destination transform, so when debugging you can see the row counts.

If the checksums don’t equal, you put that output the OLEDB Command (where you do your update statement).

Make sure in your insert statement, you set the “new checksum” column from the lookup output to the RowChecksum column in your table. In the update, you want to do the update on the record that matches your business keys, and set the RowChecksum to the new checksum value.

One thing you might also run into is this. If your destination table key column isn’t an identity column, you will need to create that new id before your insert transformation. Which probably consists of grabbing the MAX key + 1 in the Control Flow tab, dumping into a variable, and using that in the Data Flow tab. You can use a script component to add 1 each time, or you can get a rownumber transformation as well (Both the trash and rownumber transformations are on the SQLIS website – same as the checksum transformation)>

After getting your new custom slowly changing dimension data flow set up, you should see way better performance, I have seen 2.5 million rows process in around 2 minutes.

One other caveat I have seen, is in the Insert Destination, you probably want to uncheck the “Table Lock” checkbox. I have seen the Insert and Update transformations lock up on each other. Basically what happens is the run into some type of race condition. The cpu on your server will just sit low, but the package will just run forever, never error out, just sit there. It usually happens with dimension tables that are huge.

Like I said earlier, the checksum method is good for large dimension tables. I use the checksum method for all my dimension population, small or large, I find it easier to manage when everything is standardized.

By no means is this post an extensive list of everything that you would run across, but more of a basic overview of how it works with using the checksum method.

In any event, you can get huge performance gains by using the checksum method and not using the SCD Wizard that comes with SSIS, and you will also feel like you have more control of what is going on, because you will. Happy ETL’ing 🙂


Categories
Geeky/Programming Product Reviews

How 20$ Saved Me 100$ + A Month – HDTV Antenna

I really hate TV. I don’t even watch it. It is something that you should be able to pay for what you use, not pay for everything and use a little bit of it, so here is what I did.

I went to Best Buy and picked up and HDTV Antenna.

It rocks. I just plug it in to the coax, do a search and it finds the local channels. ABC, NBC, CBS, FOX, WB, PBS, and Weather Plus. Picks up the regular versions and HD versions. Since that is all that Emily wants, to see weather alerts and crap, it’s good enough for me.

I have PlayOn setup on my Vista box so I can get Hulu, YouTube and Netflix streaming to my PS3. I can rent movies, buy movies and TV shows on the PS3, Xbox 360, and AppleTV, and I can get podcasts and YoutTube on the AppleTV. What else do I need? And if I really want something, I can get it using rapidshare or whatever, or stream it on my laptop.

So, yeah, “Hello, Charter? Cancel my cable, I don’t need you anymore, kthxbye”

It’s liberating, and adds more $$ to my bottom line every month.

Categories
Geeky/Programming

Password Generation – Online

I have had to set up some windows users recently, and needed to come up with some way to generate random passwords. I have found this online app has tons of options, and it works well

http://www.pctools.com/guides/password/

Categories
Life

Congrats Joel

Friend and ex-coworker Joel and his wife Allison had a baby girl today. Congrats! Looks like I’m on deck now 🙂

Twitter / dukebaby: BabyUpdate – Her name is o ….

Categories
Blogging

My Lifestream

I have set up a “Lifestream” at soup.io

Pretty cool, aggregates all my stuff I do around the web. My blog posts, tweets, flickr pics, last.fm stuff, Google Reader shared items, diggs, delicious shares, etc.

It is kind of like FriendFeed but not on FriendFeed 🙂

I set up my DNS to point to soup.io and decided to use a domain I had lying around, stevenovoselac.com

Check it out, subscribe if you want, check out soup.io as well. It was a little slow/buggy but finally worked

Steve Novoselac’s Lifestream.

Categories
Life

Big Changes and Other Updates

It’s been a week at the new job, and I am really enjoying it. I am working on a project dealing with .NET and SQL, and SSIS. Fun stuff. I am really enjoying the environment and project, hopefully more to come.

The new job coupled with the move into the new apt, I have been really busy. Our new place hasn’t lived up to expectations. They haven’t got all the blinds up, and the master bathroom shower and tub aren’t working. I have called a couple times and nothing in response. Irking me.

The band I am in played last weekend too, which was fun. We are playing again on Halloween at MT Bar in Waterloo. I play keyboards on most songs, piano, horns, synth, strings. I sing backup on a few and sing a couple myself, so it is pretty fun. Lugging all the band gear there and back isn’t so fun. We need roadies 🙂

The baby is still coming along. Coming up quick. Now that we are in the new place, we have an empty room for the baby stuff. Looking forward to it.

Categories
Blogging Random

Sorry State Of My Blogroll

Doing some “Fall Cleanup” type stuff, I decided to hit the links in my BlogRoll to see the last time some of them have been updated. Boy, surprised me.

What happened? I don’t know, but the state of most of my buddies blogs is in total neglect.

  • Aaron Ballman – updates regularly, really techie, mostly Real Basic stuff (Last post Sept 26th)
  • Aaron Weber – updates sometimes, some good content (Last post Sept 16th)
  • Adam Rudolph – updates sometimes – but his feed was jacked for the longest time (Last post Sept 8th)
  • Bill Zitomer – started off good and fell off (Last post Feb 16th)
  • Brad Gocken – totally ghandi (Last post Nov 7th 2007)
  • Brye Weis – blogspot site shut down – removed him, yikes
  • Chris Super – was going strong, but..was twittering strong for a while (Last post June 13th)
  • Chris Super Personal – pretty much done (Last post April 14th 2008)
  • Jeff Bollinger – site was down, he didn’t know, fixed now, but pretty much gone (Last post June 13th)
  • Jennifer Dammann – was going strong, neglected (Last post May 19th)
  • Joe Gay – a few posts and nothing (Last post Apr 28th)
  • Joel Dahlin – good stuff every once in a while (Last post July 30th)
  • Jon Shern – good stuff every now and then (Last: post Sept 4th)
  • Kyle Ohme – post every now and then – hey Kyle, your site is down now, and when it isn’t it is slow, and the text formatting is goofy – Last (unsure, cant get to site)
  • Michael Fransen – good quality stuff, in spurts 🙂 (Last post Aug 21st)
  • Mickey Slater – brand new endeavor, good content (Last post Sept 23rd)
  • Reena – cant seem to pick a blog engine!! (Last post Jul 10th)

So there you have it, my blog roll.. most of them havent updated in months. What gives guys? I’m sure everyone has SOMETHING they can blog about. I know I don’t update that often, and I should post more, but some of you (Gocken?) are almost hitting a year with no updates!! let your knowledge out on the world, keep us up to date! I like to give the link love, but give me some content in return, something so we can have a conversation on this blogosphere of ours.

And feel free to get on my case when I don’t update 🙂

P.S. – if any of my friends reading this have a blog I don’t know about, let me know, I will subscribe and add you to the blog roll. But maybe if you update often you might not want me to add you, it seems to be a curse of blog neglect once you make the list – Mickey, don’t let the curse get you!

Categories
Life

Big Change #3 – New Job

Recently, in May 2008, I took a position with Stratagem. Though the summer I worked for 2 places as a consultant, KHS in Waukesha, and The Dept. Of Regulation and Licensing (DRL) in Madison.

A little history. I was full time for W3i around 2 years, and then went independent for about a year, then as a consultant with Stratagem. All the different types (full, indie, and consultant) have the pros and cons, and it all depends on what you are doing, where you are, and things you are working on.

I have done .NET, Team Lead, Database Stuff, C++, Data Warehouse/BI (Business Intelligence), ERP Stuff, more .NET and everything in between. Over the past 2 years I have come to love the database stuff more and more, especially BI and Data Warehousing. It is funny, because pretty much 99% of people have no clue what “BI” is. I was just a High Tech Happy Hour at Pooleys and everyone I talked to, “What is BI?” – and this is a tech event!! Anyways, I really do like BI and wanted to move my career forward doing BI. Stratagem hired me to do BI and work on their BI stuff, but there just wasn’t work out there, and I really wasn’t going down the path I wanted to. Stratagem is a great place, great people, I just wasn’t enjoying what I have been working on. (Although I did work on a small part time project for a couple weeks at night doing some SSIS stuff, which was exactly what I wanted to be doing full time!)

Now everyone probably knows I have an iPhone and use it extensively. A couple months ago, I installed the “Career Builder” app from the app store to check it out. It uses your location based on GPS, which I thought was cool. Just for kix, I typed in “Data Warehouse” and there was a result near Madison! Sweet, but what about details? Yeah everything that hit my buttons. Microsoft, SQL Server 2005, Analysis Services, Integration Services, some .NET, etc. Awesome!

I sent in my resume, and figured I would either hear back, and get the job, or wouldn’t hear back at all, not knowing how long the position had been out there, etc. I waited and finally heard back! Sweet. A phone interview, in person interview, informal interview, and another in person interview, and I got the job.

But who is this job with you ask? Well I am proud to say that this upcoming Tuesday I will be the newest “BI Architect” at Trek Bicycle Corp. You know, “Trek”. “Trek Bikes”. The awesome bike company. The HUGE bike company. The type of bikes Lance Armstrong rides. The USA Teams ride. The bikes that have won a ton of Tour De France’s. Sweet, sweet bikes.

Trek is located in Waterloo, WI, which is about 15 miles from where I live now in Madison, and about 14 from where I am moving tomorrow in Sun Prairie, WI. It is about 4 miles from where our band practices, in Marshall, WI. It is out in countryside, on the edge of a small town. Weird how the world HQ for this company is located in such a small town.

In any event, it is a new adventure that I am very excited for. I am really looking forward to get back into BI stuff head first and work back in SQL Server!! (I have been working Oracle for the last 2 months – ugh!)

I will even start riding bikes I’m sure, and I’m betting I am the envy of all my bike nerd friends out in PDX!!!

So this is Big Change #3 out of 3. #1 was moving, #2 is the baby, and #3 is the job. Another whirlwind couple of weeks here, and then the next couple of months, but I am excited and don’t worry, you will see my blogging to continue here. Although I am twittering more (http://twitter.com/scaleovenstove) but I still want to blog a couple of times a week. And hopefully I dive into BI/Data Warehousing and have more cool stuff to blog about in that realm.

One thing, this is the first time since I graduated college where my title isn’t some kind of “Software Dev” title. When I was indie, I really didn’t have a title, even though I was doing BI, so that is different. I don’t see myself going back to being a full time dev, even though I can do .NET. I will still use programming and development as a tool with my BI work, and also just for myself or helping friends.

Go buy a Trek! Save Gas! 😉

Categories
Life

Big Change #2 – Baby

Yes, that’s right. We are having a baby. A baby girl (they think, you never know!) due February 5th. Everything is going along just fine. I am very excited!!

We haven’t done much as far as getting baby stuff yet. We hit some garage sales and got some neutral clothes for really cheap before we knew the gender of the baby, so that was good. I figure after the move (Big Change #1) we will start getting baby stuff like the crib and what not.

There isn’t much more to say at this point, just waiting for the little bugger to come.

Here is the latest ultrasound:

Categories
Uncategorized

Big Change #1 – Moving

Since moving to Madison, WI back in November of 2007, not much has changed as far as the living situation. The apartment we are in is ok, and I was planning on not moving for a while. I just counted today and I have moved like 12 times since 1998. Yikes.

The problem is.. our apartment management company, “The Madison Apartments”, aka “Fiduciary Real Estate”, aka “Stoneridge Pointe Condos” decided they wanted to turn our apartment into a condo. You see, most of the places around where we live are condos, and when we moved in, they said NOTHING about our place being converted into a condo.

Fast forward 6 months, we come home and have a letter saying basically “you can buy it, or you can move” which is total BS. On top of that, I asked if we could move out early, since we are being FORCED out. And of course they said no. Greedy, greedy. I really do hope someone run across this post and sees how greedy they are, and that they should look for somewhere else to live.

Anyway, we found some new condos in Sun Prairie, WI which is about 2 miles east of where we live now. These condos have been sitting empty for a while, and no one has even lived in them. We are moving in there next weekend, a bigger place, and just nicer all around.

The funny thing is, the old apartments are changing rentals into condos, and the new place is turning condos into rentals. You would think that these places would be wanting to keep rentals as rentals, especially the way the housing market is. Do they really think someone is going to buy the apartment we are in as a condo? If they did they would really be missing out. Overpriced and really just not worth how much they want for it.

So, #12 move, coming up here soon. This time I am getting smart and hiring movers. I will get a case of beer, and watch THEM move. So worth it.

This is big change #1 out of 3. Stay tuned for the next two…