Thursday, November 5, 2009

Day 219 - New Convert Sequence Function

We have a functional requirement that needed our technical expertise to be solved, it was a small challenge but an interesting one.

Data Fusion already has a convert sequence function, which receives a key a returns a sequence.
It is very useful to convert things like keys and identifiers between the old system and the new system.
It works on a very simple basis: the new system key is requested based on the old system key, if it exists it is returned, otherwise it is created based on the addition of 1 to the current maximum value present, and the returned.
Here is an example:

Old Key
ACC0005
ACC0008
ACC0017
[...]
New Key
1
2
3
[...]

This is persistent between data migration executions, which means only new keys will be added, and it is quite efficient since it is entirely loaded into memory.

This has suit us for almost a decade. All our previous data migrations never required identifier conversions, or creations, based on anything other than a set of identifiers.
But here a new challenge raised. We still must return the new system key based on the old system key, but the creation of a new system key is no longer based on the old system key.
The creation of the new system key is now based on a subset of the old system key.
Here is how it works:
  1. Request the new system key based on the old system key
  2. If if exists: return the value
  3. If if does not exist:
    1. Select the next value from the old system sequence key
    2. Add an entry to the conversion table registering the old system key, the old system sequence key and the new system key
    3. Return the new system key

Here is a very simple example for better understanding.
Consider the old system key to be based on the source system account number (ACC) and historical image (IMG). Consider the sequence being incremented only by the account number. A conversion table would be something like:


Old Key
ACC0005 # IMG0001
ACC0005 # IMG0002
ACC0008 # IMG0001
ACC0017 # IMG0001
ACC0017 # IMG0002
ACC0017 # IMG0003
[...]
Old Sequence Key
ACC0005
ACC0005
ACC0008
ACC0017
ACC0017
ACC0017
[...]
New Key
1
2
1
1
2
3
[...]
Note that the old system sequence key varies based on a subset of the old system key.

Obviously the above example is purely academic, but the this easy to use mechanism is being used to solve a complex transformation problem and it has became extremely useful.

No comments:

Post a Comment