Stage Variable manupilation query

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
seell
Participant
Posts: 22
Joined: Fri Nov 07, 2003 9:46 pm

Stage Variable manupilation query

Post by seell »

hi
I am trying to use ETL to insert and update an existing data warehouse dimension table with surrogate keys.

Data would be extracted from the existing table to a csv file where amendments would be made and this would be the input to the job.
What I have done is retrieve the maximum surrogate key into a stage variable say VarCitzCnt. During the transformation stage, I would check using the code, if code found use the same surrogate key, update the record else use the Variable VarCitzCnt + 1 as the surrogate key and insert into the table

The update is not a problem but I found that during multiple inserts, only the last insert was successful. I do not know why but have also tried to change the 'TRANSACTION HANDLING' for that table to be 1 but that also did not work;

If instead I chose to use @OUTROWNUM, I got the correct number of records inserted; The reason for that using this that we want to be sure that the surrogate key generated is correct as there might be deleted rows in the output file.

Any advise ??
Thank you
Regards
SLL
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

When did you ever increment your stage variable?

Code: Select all

Variable VarCitzCnt + 1 
Did you try this on your update derivation:

Code: Select all

Variable VarCitzCnt + @OUTROWNUM
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
seell
Participant
Posts: 22
Joined: Fri Nov 07, 2003 9:46 pm

Post by seell »

hi
I thought that the variable would be incremented each time the process is repeated like @OUTROWNUM ?

If not, then I could not use the @OUTROWNUM as I wanted a serial increment ie the next serial no.

Thank you
Regards
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Kenneth

VarCitzCnt = VarCitzCnt + 1

should increment every row. The initial value should be 0 or max of current surrogate key.

It should work but I would not check to see if the surrgate key exists. You do need to find the max ans start from there.

Kim.
Mamu Kim
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Alright Kim, I'm supposed to be the sleepy one. :wink:

I simply quoted the original text verbatim. I figured the stage variable was being misused, and somehow the poster thought it auto-incremented, as the followup then stated.

Since @OUTROWNUM will introduce gaps (ohh, the horror) in assignment, because the row is either an insert or and update, @OUTROWNUM gaps one the update because the value is not used.

My recommendation would be to fork the stream and send updates up one path and inserts down another and handle it that way. Nobody listens to me so the other solution is to involve another stage variable that increments only when an update is seen that that variable is added to the seed variable.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

And to follow up on Ken and his Shakespeare "Oh Horrible, Horrible, Most Horrible" comment...

If all this is to ensure that there are no gaps in the surrogate key sequence, don't worry about. They are by definition, after all, meaningless and you shouldn't burn too many brain cells worrying about "wasting" any. Typically. IMHO. :)
-craig

"You can never have too many knives" -- Logan Nine Fingers
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Yeah, until you get a client with an Oracle table with a primary surrogate key of decimal(3).

AHHHHHHHHH. Kill me, kill me now.

bang
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Ok, except then. :lol: Horde them well, Grasshopper.

[bang!]

Sorry, thought I saw you move.
Last edited by chulett on Mon Nov 17, 2003 4:10 pm, edited 1 time in total.
-craig

"You can never have too many knives" -- Logan Nine Fingers
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Ken

I like the idea only counting each insert. Leaving gaps in the surrogate keys is much faster.

Sleep dude per chance to dream of surrogate keys.

Kim.
Mamu Kim
Teej
Participant
Posts: 677
Joined: Fri Aug 08, 2003 9:26 am
Location: USA

Post by Teej »

You're mad! You're all mad!

:)

-T.J.
Developer of DataStage Parallel Engine (Orchestrate).
datastage
Participant
Posts: 229
Joined: Wed Oct 23, 2002 10:10 am
Location: Omaha

someone please put Ken out of his misery

Post by datastage »

kcbland wrote:Yeah, until you get a client with an Oracle table with a primary surrogate key of decimal(3).

AHHHHHHHHH. Kill me, kill me now.

bang
that's pretty bad. I just got through with a slowly changing dimension in which it was closing in on time to increase the key from decimal(6) to decimal(7). They kept insisting they wanted it to be decimal(10) to be safe. I projected, even with accelerated growth, that it would be 70 years before it would need to even be decimal(8). At least erring on the large size doesn't create the pain of erring in the low side.
Teej
Participant
Posts: 677
Joined: Fri Aug 08, 2003 9:26 am
Location: USA

Re: someone please put Ken out of his misery

Post by Teej »

datastage wrote:that's pretty bad. I just got through with a slowly changing dimension in which it was closing in on time to increase the key from decimal(6) to decimal(7). They kept insisting they wanted it to be decimal(10) to be safe. I projected, even with accelerated growth, that it would be 70 years before it would need to even be decimal(8). At least erring on the large size doesn't create the pain of erring in the low side.
Oh, witnessing the durability of Cobol, and its constant persistency, requiring Ascential to provide tools to continue to improve on Cobol...

I wouldn't be surprised when our grandkids wonders if we need to increase it to Decimal(20) to be safe. ;-)

-T.J.
Developer of DataStage Parallel Engine (Orchestrate).
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You'll hit the Y10K problem in ISO 8601 dates before you'll need Decimal(20)! :lol:
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Teej
Participant
Posts: 677
Joined: Fri Aug 08, 2003 9:26 am
Location: USA

Post by Teej »

ray.wurlod wrote:You'll hit the Y10K problem in ISO 8601 dates before you'll need Decimal(20)! :lol:
Ohhhh yeah! That would be a HUGE problem due to the amount of C++ programs out there and the fact that they're all compiled. "Hey, where's the source code for this?"

At least with the Y2k problem, you had the Cobol source code there.

We'll be so filthy rich, and so filthy bald at that time. ;-)

-T.J.
Developer of DataStage Parallel Engine (Orchestrate).
mhester
Participant
Posts: 622
Joined: Tue Mar 04, 2003 5:26 am
Location: Phoenix, AZ
Contact:

Post by mhester »

You'll hit the Y10K problem in ISO 8601 dates before you'll need Decimal(20)!
I think the upcoming date problems that might happen have more to do with storage than format. If the system can store dates as 64 bit signed then you are correct. If the storage is 32 bit then we have a problem that will happen around 2037 and it really won't matter how the date is formatted.

Regards,

Michael Hester
Post Reply