Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
DM2017
Contributor II
Contributor II

Context variable not being used in tmysqlinput

Hi,

I am trying to restrict the number of rows  by using context variable but it's sending all the rows from the table. All record are coming as output in query window too.

Kindly  help in this regard0683p000009Ls2H.jpg0683p000009LsYR.jpg0683p000009LsYb.jpg0683p000009LsKp.jpg.

Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable

Your query is wrong. You are building a SQL query using Java String manipulation. Your query should be more like this....

 

"SELECT  *  FROM  actor  where actor_id> '"+context.MAXID+"'"

I'd argue that you probably do not need the single quotes either, but that shouldn't cause a massive issue.

View solution in original post

7 Replies
manodwhb
Creator III
Creator III

where are you storing into memory,in Talend job?

Anonymous
Not applicable

I think I know what is wrong, but you haven't shown what I need to see. Can you show me the query as text (not a screenshot) and explain the flow of data. It looks like the order of processing is wrong. Your context variable when the query is processed and fired will always be 0 as it is not set until the end of the flow. You also have a timing issue with when queries are generated and when context variables are set. A rule of thumb is that if you want to use a context variable in a query, that it needs to be set in a prior subjob (or in a previous iteration).

DM2017
Contributor II
Contributor II
Author

There is no other job associated with it . it's a single job. 0683p000009LsLP.jpg

 Even I am able to print the MAXID coming from the variable. but issue is not restricting.

 

context.MAXID=input_row.MAXID;

>creating  variable 

 

"SELECT  IFNULL(MAX(actor_id),0) AS MAXID FROM actor  WHERE flag='Y'"

>This is to get the maximul actor_id from the table with flag='Y'

If table has 100 rows I need to show only 10 rows based on variable

 

"SELECT  *  FROM  actor  where actor_id> '+context.MAXID+' "

This is to restrict the rows.

 

Let me know if you need more info.

Thanks

 

manodwhb
Creator III
Creator III

where are you loading MAXID into context?
Anonymous
Not applicable

Your query is wrong. You are building a SQL query using Java String manipulation. Your query should be more like this....

 

"SELECT  *  FROM  actor  where actor_id> '"+context.MAXID+"'"

I'd argue that you probably do not need the single quotes either, but that shouldn't cause a massive issue.

manodwhb
Creator III
Creator III

you need to load MAXID into context using tcontextload.

DM2017
Contributor II
Contributor II
Author

 I had that initially (extra " ") but removed , anyway changed query, it's working as expected.

Thanks a lot..