Sparse look up query

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

devsonali
Premium Member
Premium Member
Posts: 155
Joined: Sun Mar 18, 2007 2:31 pm

Sparse look up query

Post by devsonali »

Hello all,

I have the following scenario

Source file - transformer - look up database (being looked up sparse look up )-output

The idea is for each row value (varchar) , I need to to break the string into words (which I am handling with loop variables) and look up each word to database to get matching records

For example
Source input is "A BMP C D XYZ" then I break them up into 'A' , 'BMP','C','D','XYZ' in a separate row say Input_break (Which I have already tested) and do a sparse look up where database column_name like '%orchestrate.Input_break%'

The problem : I am expecting a lot of records out of database (because a lot of rows do exist in database satisfying the query) , However , I only get 5 rows in the output all of which populate a null (or empty) database column_name along with each word (for the input_break) column

Output

input_break,database_colume_name
'A' ,
'BMP',
'C',
'D',
'XYZ',




Thanks for looking
ShaneMuir
Premium Member
Premium Member
Posts: 508
Joined: Tue Jun 15, 2004 5:00 am
Location: London

Post by ShaneMuir »

Without testing - and this is pure speculation, I am guessing that the problem is that like statement is looking for the literal '%orchestrate.Input_break%' rather than the value that you are actually wanting to pass to that value.

I have never tried to pass a like statement to a sparse lookup. But as a guess I would think that you might have to pass the % as part of your text and just have in the query column_name like orchestrate.Input_break

where input_break would equal %value%.

Again this is all just a guess.
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

You should check the query in db stage and run the query by providing this value replacing the variable in any other database client. How many records are you getting?
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
rkashyap
Premium Member
Premium Member
Posts: 532
Joined: Fri Dec 02, 2011 12:02 pm
Location: Richmond VA

Post by rkashyap »

You can also try to use 'instr' function instead of 'like'.
devsonali
Premium Member
Premium Member
Posts: 155
Joined: Sun Mar 18, 2007 2:31 pm

Post by devsonali »

Thanks for all your inputs

Firstly I checked if my column name is exactly what I get in the transformer and then I took off the % sign , I get the exact same result , this tells me there is something wrong , but I just don't know what is it .

Secondly , I did check the number of records with like statement in database and I am getting plenty on each word .

Finally, When I try to test it with an = sign instead of like and ensuring the record I test exists in database , I get the correct result .
Last edited by devsonali on Tue Jun 30, 2015 12:51 pm, edited 5 times in total.
devsonali
Premium Member
Premium Member
Posts: 155
Joined: Sun Mar 18, 2007 2:31 pm

Post by devsonali »

rkashyap wrote:You can also try to use 'instr' function instead of 'like'.
I think that will give you the position , i am looking for the matching string here
Thank you
rkashyap
Premium Member
Premium Member
Posts: 532
Joined: Fri Dec 02, 2011 12:02 pm
Location: Richmond VA

Post by rkashyap »

INSTR will indeed give the position. However if returned value is greater than 0, then string is present.i.e

Code: Select all

WHERE INSTR(Tab_Col,searched_string) >0
devsonali
Premium Member
Premium Member
Posts: 155
Joined: Sun Mar 18, 2007 2:31 pm

Post by devsonali »

Yeah , but as I mentioned , my requirement is to collect all the matching records (from database ) from each word within each string (input)
rkashyap
Premium Member
Premium Member
Posts: 532
Joined: Fri Dec 02, 2011 12:02 pm
Location: Richmond VA

Post by rkashyap »

We don't know the root cause of this issue. However if the issue is due to "like" clause then INSTR can be used.

Code: Select all

WHERE INSTR(Tab_Col,searched_string) >0
is equivalent of

Code: Select all

WHERE Tab_Col like "%searched_string%"
devsonali
Premium Member
Premium Member
Posts: 155
Joined: Sun Mar 18, 2007 2:31 pm

Post by devsonali »

Now , I see what your were saying , Yes the query works fine but only in external sql portal , not in database stage (Oracle)

However , if I hard code with a value say 'A' to test the sql
Instead of 'ORCHESTRATE.searched_string'

select tab_col from table_T
WHERE INSTR(Tab_Col,'A') >0 then I get required rows in datastage

When I try INSTR(Tab_Col,'ORCHESTRATE.searched_string') >0 , I get only 5 ROWS (Just as how I got by using LIKE statement)

Thanks again
rkashyap
Premium Member
Premium Member
Posts: 532
Joined: Fri Dec 02, 2011 12:02 pm
Location: Richmond VA

Post by rkashyap »

Try without enclosing searched string in quotes i.e.

Code: Select all

INSTR(Tab_Col,ORCHESTRATE.searched_string) >0
devsonali
Premium Member
Premium Member
Posts: 155
Joined: Sun Mar 18, 2007 2:31 pm

Post by devsonali »

I tried that earlier but saw the following error
"The connector could not find a column in the input schema to match parameter"

That's when I added the quote
ShaneMuir
Premium Member
Premium Member
Posts: 508
Joined: Tue Jun 15, 2004 5:00 am
Location: London

Post by ShaneMuir »

Not sure what your reference DB is but what you want to do is write the where clause as some sort of concatenated string eg In oracle the following does work

select field1, field2 from TableName
where Tab_Col like '%'||ORCHESTRATE.LKP_STRING||'%'
devsonali
Premium Member
Premium Member
Posts: 155
Joined: Sun Mar 18, 2007 2:31 pm

Post by devsonali »

i am using Oracle but the concatenation fails with the same error
ShaneMuir
Premium Member
Premium Member
Posts: 508
Joined: Tue Jun 15, 2004 5:00 am
Location: London

Post by ShaneMuir »

devsonali wrote:i am using Oracle but the concatenation fails with the same error
What is the exact sql you have in your sparse query?
What is the exact error you are getting?
What is the exact column name you are using in the lookup stage?
Post Reply