Truncate table before loading....Occassionally

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

kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Truncate table before loading....Occassionally

Post by kris007 »

Hi All,

I have developed a ETL job in two parts..Extraction and Staging in one and the second part is loading. I am loading the tables(incremental loading) using regular update existing rows and insert new rows. My requirement here is, occasionally we would want to refresh the target tables i.e. truncate the table and insert all new rows. I thought one way of doing it is create another link in the staging job between Transformer and Oracle DB with update action as Truncatetable and insert rows and pass that update action as a parameter. But it doesnt seem to work. I would want to create a parameter for the update action so that one could always choose between doing the daily incremental loading or totally refreshing the target tables. Is there a way around to do it? Other option I have on mind is write a procedure as a before sql query to truncate the table if I pass a parameter.

Note: I would know before hand when I would want to do a full refresh i.e truncate and insert. So, for that particular I wish to pass a parameter so that the job could pick it up and do the needful.

Need guidance.

Thanks
Kris.:?
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

If you are using a DRS stage, then in the before tab you can specify a parameter, and whenever you want you can pass a delete command in there or if your id has truncate authority, you can pass a truncate command in there. That might do the trick
cheers
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

I don't have DRS stage in my job or palette. I am staging date in a sequential file in my first job and calling it in the second job.

Thanks
Kris.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

For loading the table, what stage are u using, and what DB is it?
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

I am loading into Oracle DB and using Oracle OCI stage

Kris
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

Hi,

I think kris had already mentioned in the first post that it is Oracle DB and OCI stage is implicitly understood. :wink:

Thanks,
Naveen.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

:oops:
i totally overlooked that. Thats what happens when you try to multitask.
So coming back to the problem,
in the OCI stage, go to the tab sql, and in there is a tab before. in the section specified there put ur delete command. Test it. If it works, parametrize the Delete command and put the parameter there.
When ever you want to refresh your table, pass the delete statement through your parameter.
I dont see why that wouldnt work.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Kris,
I just made a test job and tested the solution i proposed. It works just fine.
cheers :P
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

Yeah....It works whenever I want to do a refresh. But If I am doing a regular Update else Insert, the Job finishes with warnings saying invalid sql statement..which further sends an emailnotification. To be more clear,
I tried giving the TRUNCATE statement as a parameter in before sqltab in OCI stage in my extraction and staging job(First part ) where I try to pull the last successful load timestamp(for incremental loading). So it solves the purpose when I want to do a refresh because the before query is truncating the target table and I dont get any timestamp from the target which pulls the whole data from the source. But when I want to do a normal UpdateelseInsert I dont give an value for the DELETE parameter and the job is finishing with warning which I want to avoid. Still trying to comeup with something which might solve this. :? Please let me know if I am not clear so that I could explain it better.

Thanks
Kris
rasi
Participant
Posts: 464
Joined: Fri Oct 25, 2002 1:33 am
Location: Australia, Sydney

Post by rasi »

Kris

The job is going to execute Before Command on every single run. It's important to give a valid SQL to your parameter. One way is to construct your SQL parameter as
"Select 1 from Dual"
make this as your default SQL to be executed every time. Whenever you want to refresh pass the value to SQL paramter as
"Truncate Table Table_Name"

If you want to use delete command

"Delete from Table_Name where SQL_Parameter"
in SQL Parameter use default value as 1=2
and whenever you want to refesh then use 1=1


Truncate is faster and more efficient to use in Oracle to remove records permanently.
Regards
Siva

Listening to the Learned

"The most precious wealth is the wealth acquired by the ear Indeed, of all wealth that wealth is the crown." - Thirukural By Thiruvalluvar
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

I was thinking on the same lines too but am hesitant to pass the TRUNCATE TABLE TABLE_NAME statement as parameter becos I would end up with more problems if I give a wrong table name accidentally. But I guess there no way round as of now. Can't complain and need to be careful while I pass parameters.
Thanks
Kris :?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Kris - just how 'occassional' is this occassional need to occassionally truncate the table in question? If it is truly occassional, why go through all this who-ha and why not just occassionaly truncate the table... manually? :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
rasi
Participant
Posts: 464
Joined: Fri Oct 25, 2002 1:33 am
Location: Australia, Sydney

Post by rasi »

Or even create a separate job in datastage to truncate table and run it manually whenever you want to truncate table....
Regards
Siva

Listening to the Learned

"The most precious wealth is the wealth acquired by the ear Indeed, of all wealth that wealth is the crown." - Thirukural By Thiruvalluvar
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

Why should one waste resources by creating a seperate DS job for a simple task like 'manually' truncating a table.

A simple 'TRUNCATE Table_Name' command execution would suffice. :wink:

Thanks,
Naveen.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
rasi
Participant
Posts: 464
Joined: Fri Oct 25, 2002 1:33 am
Location: Australia, Sydney

Post by rasi »

Naveen

I agree with you but if it is in a job then it is more controlled. Once the code is compiled, tested and promoted to production then you don't need to worry about it. In manual approach there is always a danger on truncating other tables in production and there could be other security issues.
Regards
Siva

Listening to the Learned

"The most precious wealth is the wealth acquired by the ear Indeed, of all wealth that wealth is the crown." - Thirukural By Thiruvalluvar
Post Reply