Mapping

BizTalk Mapper – Keyed Cumulative Sum

From time to time I get questions about mapping puzzles, and I love it! Send me more of those! (I realize might regret that statement later). This time the puzzle was how best to do a conditional cumulative sum, or keyed conditional sum, also possibly known as grouped conditional sum.

The scenario is this (I’ve removed some namespaces etc for readability):

<Compensation>
  <rows>
    <row>
      <Compensation_Code>1</Compensation_Code>
      <Compensation_SubCode>1</Compensation_SubCode>
      <Compensation_Level>1</Compensation_Level>
      <Compensation_Id>1113</Compensation_Id>
      <Compensation_Days>41856.50</Compensation_Days>
      <Compensation_Amount>25288084</Compensation_Amount>
      <Compensation_Tax>6690289</Compensation_Tax>
    </row>
  <row>
      <Compensation_Code>1</Compensation_Code>
      <Compensation_SubCode>1</Compensation_SubCode>
      <Compensation_Level>1</Compensation_Level>
      <Compensation_Id>1113</Compensation_Id>
      <Compensation_Days>41856.50</Compensation_Days>
      <Compensation_Amount>29627</Compensation_Amount>
      <Compensation_Tax>6690289</Compensation_Tax>
    </row>
    <row>
      <Compensation_Code>1</Compensation_Code>
      <Compensation_SubCode>1</Compensation_SubCode>
      <Compensation_Level>2</Compensation_Level>
      <Compensation_Id>1113</Compensation_Id>
      <Compensation_Days>41856.50</Compensation_Days>
      <Compensation_Amount>234348</Compensation_Amount>
      <Compensation_Tax>6690289</Compensation_Tax>
    </row>
  </rows>
</Compensation>

How do you best produce a map that as step one summarize all Compensation_Amount for each variation of Compensation_SubCode, and returns this (let’s call this scenario 1):

<Compensation>
  <rows>
    <row>
      <Compensation_SubCode>1</Compensation_SubCode>
      <Compensation_Amount>25552059</Compensation_Amount>
    </row>
  </rows>
</Compensation>

and as step two, summarize all Compensation_Amount for each combination of Compensation_SubCode and Compensation_Level, and return this (let’s call this scenario 2):

<Compensation>
  <rows>
    <row>
      <Compensation_SubCode>1</Compensation_SubCode>
      <Compensation_Level>1</Compensation_Level>
      <Compensation_Amount>25317711</Compensation_Amount>
    </row>
    <row>
      <Compensation_SubCode>1</Compensation_SubCode>
      <Compensation_Level>2</Compensation_Level>
      <Compensation_Amount>234348</Compensation_Amount>
    </row>
  </rows>
</Compensation>

You might start thinking custom xslt and xsl:sort or xsl:keys or muenchian methods and things like that. That’s one way to do it. I actually prefer using the mapper for most maps until performance forces me to go another way.

My solution for scenario 1:

clip_image001

My Solution for scenario 2:

clip_image002

I am not presenting a complete solution for scenario 1, since it’s really just a subset of the functionality required for scenario 2, but you should get the point from the explanation of scenario 2.

The magic of the scenario 2 solution happens in the three scripting functoids. The first one, connected to the destination root node contains the following snippet (again namespace deprived for readability):

List<string> keyList= new List<string>();
void initglobals() {}

It’s simply responsible for making sure that the variable keyList is set up. The empty method that return void ensures that I can connect this to an output node to make sure it triggers, yet it will produce no output.

The next functoid then makes use of that list, and adds all unique keys to it (which is unique combinations of the two keys separated by a secure character, in this case a colon):

public string AddKey(string key)
{
  if (keyList.Contains(key))
    return string.Empty;
  keyList.Add(key);
  return key;
}

The Not Equals functoid then makes sure that we will only see output when a new unique combination is found, by checking to make sure that the string outputted from the scripting functoids <> and empty string.

The third functoid then is responsible for doing the summation (I’ve inserted a linebreak and some spaces in the xpath statement for readability, so don’t just copy paste this):

<xsl:template name="OutputSum">
  <xsl:param name="param1" />
  <xsl:param name="param2" />
  <xsl:element name="Compensation_Amount">
  <xsl:value-of select="sum(//row[Compensation_SubCode=$param1 
              and Compensation_Level=$param2]/Compensation_Amount)" />
  </xsl:element>
</xsl:template>

This simple xslt call template takes the two key values in, and does a summation of all rows that has these key values set to these specific values.

Now someone might object and say that this would mean an unnecessary amount of summation gets done. But that’s actually not the case, the mapper is clever enough to only do this under the condition of the Not Equals functoid returning true, as the following xslt snippet shows (this is just a portion of the xslt generated):

<xsl:variable name="var:v3" select="userCSharp:LogicalNe(string($var:v2) , &quot;&quot;)" />
<xsl:if test="$var:v3">
  <row>
    ...
    <xsl:call-template name="OutputSum">
    <xsl:with-param name="param1" select="string(Compensation_SubCode/text())" />
    <xsl:with-param name="param2" select="string(Compensation_Level/text())" />
    </xsl:call-template>
  </row>
</xsl:if>

’So a short summation (pun intended) of the work involved:

1. Create a global variable, a list to hold keys

2. Add to that list once you discover a new key

3. Add logic to that discovery to only output your destination node when you hit a new key

4. Implement a xslt call template and use xpath to sum based on your keys

AppFabric, BizTalk, Presentation, TechDaysSE

My TechDays 2011 presentations – something old, something borrowed, something new and something blue

This is bordering on being somewhat old news (but don’t blame me for that). I attended the Swedish TechDays as a speaker, user group leader and ask the experts answerer. Now as far as the first one goes my two sessions “Windows Azure AppFabric – Middleware i molnet” (Middleware in the cloud) and “.NET utvecklare – utöka verktygslådan med BizTalk Server” (expand your toolkit with BizTalk Server) are now available online (unfortunately there is no direct links since they are hidden away inside a Silverlight player application). However note that they are in Swedish. My presentation slides should be available alongside them shortly, and those are (at least mostly) in English. I’ll give you a preview…

BizTalk for NET Devs 1BizTalk for NET Devs 2

The site makes those available as pdf’s. If you ask me nicely though, I might let you get your hands on the pptx’s 😉 I am however not shy to borrow from previous presentations held by Microsoft or other luminaries if those are made available online an encouraged to be (re-)used. And since I have been doing BizTalk presentations for quite some time I do have some of my my favorite slides in there, so if you have seen a presentation by me before, chances are you will recognize a slide or two, even if most of what I communicate is still new. Thus you will find “something old, something new, something borrowed and something blue” (since the theme for this years TechDays was blue on a black background). Enjoy.

emailsignature

BizTalk Server 2010, Certification

The 70-595 exam and the first rule of fight club

I’ve had a not-so-few asks to blog about the 70-595 exam. I’m answering those calls with this post.

The exam launched on march 30th. I actually tried taking it on the 7th of April, though due to technical difficulties, on Prometric and the testing sites behalf, I had to leave without getting a chance to do it after waiting 90 minute for the issue to be resolved (see my twitter history if you want more on that story). I found the time to come back a week later though, on the 14th, and manage to successfully pass the exam.

70-595 is the Developing Business Process and Integration Solutions using BizTalk Server 2010 exam. Its coverage includes core BizTalk functionality as well as extended capabilities. The excerpt from the exams Microsoft learning page is:

Configuring a Messaging Architecture (20 percent)
Developing BizTalk Artifacts (20 percent)
Debugging and Exception Handling (17 percent)
Integrating Web Services and Windows Communication Foundation (WCF) Services (14 percent)
Implementing Extended Capabilities (13 percent)
Deploying, Tracking, and Supporting a BizTalk Solution (16 percent)

Which brings me to the first rule of fight club, and why Tyler Durden would be a good MCP (therefore not claiming that we (MCPs) are all insomnia cursed paranoid schizophrenics in any way ;).  But, “You don’t talk about fight club”, as in “You don’t talk about the contents of certification exams”. In fact you actually agree to an NDA about the contents of the exam – not that that stops any of the cheat sheet providers out there or the people that use them, but it does me. Therefore, you will not find any details as to what kind of questions or what specific areas were covered. All I’m going to say about the contents of the exam is that it pretty much mirrored that division into areas.  So let’s delve into that…

…and rephrase those percentages in another way:
Core functionality (like messaging, development, debugging, deploying, tracking and troubleshooting) make up roughly 90%, and BAM, BRE, RFID and EDI make up the other 10 percent.

Since the test is 50 questions, that would mean that on an average 45 question would be on the core functionality and 5 questions on the rest.

Following on with the math lesson that means that you are very likely to make the passing score of 700 (out of 1000), without any deeper knowledge on the “extended capabilities”. Which I know will be a soothing thought for a lot of people. No guarantees though, because it’s not always a 1 question =  1000/50 points kind of thing.

If you want to truly ace the test, you’ll really need to know all of your BizTalk, including reading into things like RFID. I did not ace the test (as in a perfect 1000), though I did reasonably well; close enough for me to be pleased and well within the margin.

How did I prepare is a question that often follow along with the ask to write a post on the subject. Others might compose a prep guide. I won’t. Not in this post anyway. I do have a simple answer with two sides to it for you though. One the one side – I didn’t. On the other – I prepared working in real BizTalk projects over the course of 6 years, 5 version of the product and took the two exams that came before this one. What I am saying is – if that sounds anything like you you are likely to just as I did just go take the test, and you’ll likely be fine. If it doesn’t – well, you know yourself best – perhaps you need to study?

On the note of previous tests, I found this to be about the same level of difficulty as the 2006 exam, though easier then the 2006 R2 exam. I don’t know about the 2004 exam – I never did that – you’ll have to ask someone like Jan or Thiago about that comparison.

Anyway, I encourage you to go take the exam, and if you do – best of luck to you!

MCT

Certified Trainer renewal – and why €400 is a magic cc limit

I renewed my Microsoft Certified Trainer “license” (if you so will) for another year today. I really do enjoy spending some time in the classroom now and then. I recognize that I might not always be the best pedagogue, though you should know I try, but I do hope that that mix of theoretic learning material with that crucial ingredient of real world experience gives “this is how this thing works” that extra nuance of “this is how this thing is actually used”. And that’s super important and often left outside of the course material since it’s hard to convey, but in many cases I believe I can bring that to the table.

To those that are unaware, the certified trainer is not really a certification that you pass, although you do need to have passed a certification as one of the requirements, it’s more of a affirmation of your ability and commitment to pass on your insight into your-technology-of-choice to others.

Or as the MCT site puts it:

Become part of an elite, international community that spans more than 150 countries and regions and includes classroom and e-learning instructors, learning consultants, authors, conference presenters, and user group leaders. Microsoft Certified Trainers (MCTs) are the premier technical and instructional experts on Microsoft technologies, and are the only individuals authorized to deliver training for Microsoft Certification.

Now, why is €400 (or really 4000 Swedish crowns) a magic limit to (my) credit card companies? Well, that’s roughly what the MCT renewal cost me, and it bounced. When I called the cc company to see why, and verify that it had, I got told that they had an outage of the system that day, and that only amounts below the 4k Swedish crown limit were automatically approved when the system was unavailable. That sounds like a security hole if any to me. I really do hope there are more safeguards in place around that. Or is there someone there in need of an MCT for some security best practices classes?