Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

dynamically updating the context variable

Hi,
We are planning to implement the Incremental Extract, our source is SqlServer and Target is Oracle.
In our source DB we have column called timestamp, using this column i have to perform a incremental load.
Each time when the job runs i have to capture the maximum value of the timestamp and i will be using that particular value during my next run dynamically. So i have created a context as Last_Run_Timestamp which should dynamically capture the max value of the Timestamp.
In order to do this,
In the tMSsqlInput component wrote a query as "select max(timestamp) from <tablename>", after that i have made this as input to tjavarow where i wrote a code as
context.Last_Run_Timestamp=row2.Timestamp
but the context is not getting updated...!!!
Thanks
Arul
0683p000009MCDa.png
Labels (3)
14 Replies
Anonymous
Not applicable
Author

Could you show us the whole job design?
Did the tJavaRow receive a row (shown in the metrics of the flow to tJavaRow) ?
The code works only if at least one row will be delivered.
Anonymous
Not applicable
Author

Hi,
Yeah, it is getting 1row as input. In order to verify that i have tried placing a tlogrow component where am getting the one value(i.e) max(timestamp) value.
While defining the context, in the place of default i have entered a timestamp value, if i keep the value as null means am gettin a error in Where Clause of the query which i wrote in the main job.
Code:
Select eventid, viodate,status from <tablename> where timestamp>=context.Last_Run_Date.
Inputs would be very useful.
Thanks
Arul
0683p000009MCLM.png
Anonymous
Not applicable
Author

Hi,
The main job will populate some columns from source to target in which am using the condition as
where timestamp>=context.Last_Run_Timestamp.
In the Subjob i have to find the Max(Timestamp) from the source and have to update them to the context variable, so that i will make use of that in the next run to do incremental extract.
The 2nd pic has the value as NULL which comes out from the t_javarow.
But in the place of t_javarow if i place tlogrow means am getting correct output.
The code i wrote in the t_javarow:
context.Last_Run_Timestamp=row2.Timestamp;
I have no clue y am getting the output from t_javarow as NULL.
can u guys help me to resolve this..

Thanks
Arul
0683p000009MCLW.png
Anonymous
Not applicable
Author

Any one there..??
Anonymous
Not applicable
Author

Please take care the schema of your tMASqlInput_2 component fits exactly to the result field of the query. The matching between the result set fields and the schema columns will be done by the position not by the name!
And please note, most people from Talend and most users here on vacation currently. This could cause some delays of answers.
Anonymous
Not applicable
Author

Hi,
Any one there..!!
Will explain my requirement more clearly. My source table has a audit column TimeStamp, In order to perform a incremental load, i need to find the Max(Timestamp) in Each run(Subjob) and will pass this value onto the main job, and the value will be used in the where Clause
code:
where timestamp>=context.Last_Run_Timestamp
in which the context.Last_Run_Timestamp will hold the max(Timestamp) value which is calculated in the Subjob.
tMSSQLinput--tMSSqlOutput
|
subjob ok
|
tMSSQlinput--tmap--tJava_Row
In the subjob tMSSqlInput i wrote a code
select max(Timestamp) from table Name -- tmap -- tJava_Row
In tJava_Row i wrote the code as
code:
context.Last_Run_Timestamp=out1.Timestamp
System.out.println(context.Last_Run_Timestamp)
While i tried Printing the Context.Last_Run_Timestamp am getting the Correct value, but it not reflecting in the
First tMSSQlinput where clause..!!
Help me out to resolve this issue..!!
I have also attached the Screen Shot.
0683p000009MCC4.png 0683p000009MC2E.png
Anonymous
Not applicable
Author

updates on this..?
Still am facing the same problem..
Anonymous
Not applicable
Author

Hi
To access the input data flow on tJavaRow, the format is as below:
context.Last_Run_Timestamp=input_row.Timestamp;

I would suggest you to read a KB article: the difference between tJava, tJavaRow and tJavaFlex
Shong
Anonymous
Not applicable
Author

hi,
use load context component for that.
1.read your max value from table
2.store in globalMap with "flow to iterate component"
3. create key,value flow with "fixed flow input"
4. load key,value with context load (context parameter must exist in your context field)
tip : use print operation of contextLoad to validate parameters load to your application
Starting job truc at 12:07 06/01/2014.

connecting to socket on port 3999
connected
tContextLoad_1 set key "max" with value "M308RA4029"
context max :M308RA4029
disconnected
Job truc ended at 12:07 06/01/2014.

regards
laurent
0683p000009MCLg.png