Parsing Insert scripts into COlumns and values

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
Ragunathan Gunasekaran
Participant
Posts: 247
Joined: Mon Jan 22, 2007 11:33 pm

Parsing Insert scripts into COlumns and values

Post by Ragunathan Gunasekaran »

Hi ,

I have a very wierd requirement of using datastage to parse the MYSQL Insert Scripts into Column value pairs and then write it to an oracle database.

The requirement comes in the backdrop of business saying that the MYSQL database is a third patry database and they can provide only the scripts of transactions on a day to day basis.They are not likely in a position to give the database for connectivity to datastage.

Can someone give me a clue of how to convert the insert scripts into column value pairs in datastage...
Regards
Ragu
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Could you post a representative portion of one of the scripts?
Ragunathan Gunasekaran
Participant
Posts: 247
Joined: Mon Jan 22, 2007 11:33 pm

Post by Ragunathan Gunasekaran »

Hi ,
I am yet to get that script but i believe the script would be like..

insert into Table(Col1,Col2....) Values (Val1,Val2....)


I am trying to visualise the logic for just insert statements but what i was told is that the third party data provider would be giving me a complete MySql transaction dump for a day. This means it may also have Delete and upate statements in it ...

Any clues for translating insert statements as of now ..?
Regards
Ragu
ETLJOB
Participant
Posts: 87
Joined: Thu May 01, 2008 1:15 pm
Location: INDIA

Post by ETLJOB »

I would have a stored procedure in oracle to execute these statements and would be invoking it using a stored procedure stage in Datastage. SQL Statements can be passed in a single field to SP stage.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

If the insert statements are indeed standard SQL then the approach might be to take the string, replace table/instance/column names as required, then pass that string to your Oracle stage and execute it directly. If it isn't standard SQL then it is not difficult to parse the string in a transform stage; but you would need to provide a specific example in order to get a specific answer.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Before we go too far afield, could you clarify exactly what it is you need to do with these "insert scripts"? You need to break them down and store them as scripts in Oracle or somehow turn them into Oracle DML and execute them?

Best to show us not only what your input would look like but also exactly what the output from that input should be. An example, in other words, so we ensure we're solving the right problem.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

ETLJOB wrote:I would have a stored procedure in oracle to execute these statements and would be invoking it using a stored procedure stage in Datastage. SQL Statements can be passed in a single field to SP stage.
An Oracle stored procedure to execute statements intended to be used against MySQL? A novel approach indeed! Can you please elaborate?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

I have done this in BASIC before. My suggestion is create a list of keywords. Throw these words away when found. I would then look for comment lines (begin with --) and comment pairs from /* to */ and throw those away. At this point I would change end of lines into a space. Now process one word at a time. You then need to look for your insert word in the statement up to (. I would lowercase all words to compare to keywords. I would keep original case except to do these comparisons. Your column names are between the (). Next word should be values with another (). The exception is when this is a select. You need to throw out exceptions like when the next word should be "values" and is not. Same for (). Change your code to deal with these exceptions. Should get you close. You could probably land your results in a flat file with column names as the first row.

By the way I have never done exactly this. I have always done this to extract the metadata like table and column names.
Mamu Kim
Post Reply