How to dynamically pass or select the context variable of file type when run through build batch file?

Highlighted
Six Stars

How to dynamically pass or select the context variable of file type when run through build batch file?

Hi All,

In my job, I have tFileInputDelimited which loads the context variables. The file is located in my local directory.

How can I configure the path dynamically so that when I run the build using batch file through command prompt, I can pass the tFileInputDelimited dynamically. I am doing this because I will be running the build in target server.

How can I give relative path to tFileInputDelimited, so that it can read the file from same directory?

 

 


Accepted Solutions
Highlighted
Sixteen Stars
Sixteen Stars

Re: How to dynamically pass the path of tFileInputDelimited?

Remove tFileInputDelimited and tContextLoad from your job.
Define a new context variable (contextFilepath for example) with the desired value path for each context.
Go go job tab, then extra and untick option "Use Project Settings", tick "Implicit tContextLoad", tick "From file" and enter "context.contextFilepath" into the associated field.
At runtime, on command line add "--context=theContextYouWant" to start the job within the desired context or add "--context_param contextFilepath=thePathYouWantToUse" to use the context file you want.

TRF

View solution in original post


All Replies
Highlighted
Six Stars

Re: How to dynamically pass or select the context variable of file type when run through build batch file?

I have used context variable of type File with prompt and configured in the File name/Stream of the tFileInputDelimited. 

 

When I run the job through Talend Open Source, I get the prompt to select the file from my directory. How can I pass the path when I run the batch file?

I copied the tFileInputDelimited file in same location of the batch file and passed with batch execution but getting file not found error for the file whose path is present in the input file then setting it to context variable.

Please help!!

Capture.JPGCapture2.JPGCapture.JPG

Highlighted
Sixteen Stars
Sixteen Stars

Re: How to dynamically pass the path of tFileInputDelimited?

Remove tFileInputDelimited and tContextLoad from your job.
Define a new context variable (contextFilepath for example) with the desired value path for each context.
Go go job tab, then extra and untick option "Use Project Settings", tick "Implicit tContextLoad", tick "From file" and enter "context.contextFilepath" into the associated field.
At runtime, on command line add "--context=theContextYouWant" to start the job within the desired context or add "--context_param contextFilepath=thePathYouWantToUse" to use the context file you want.

TRF

View solution in original post

Highlighted
Six Stars

Re: How to dynamically pass the path of tFileInputDelimited?

Many thanks for the solution @TRF .


I also did something similar to solve the problem. I removed the tfileinput and contextload from my job. Now I just have my context variables. After I build the job, i navigate to the context/Default.properties and added the value of my context variables. I checked when I ran the build, it was showing the context=Default
That way I am able to pass my variable values.

 

I will use your solution to implement using implicit tContextLoad in my job.

Highlighted
Sixteen Stars
Sixteen Stars

Re: How to dynamically pass the path of tFileInputDelimited?

That's the way context work by default.
What I suggest is a more advanced solution.
Imagine you have 10 jobs whith 3 different context. If you want to change the value for 1 variable used by all jobs and context, you have to modify 30 context files. Right?
With the proposed solution you just have to modify 3 files. Also, you don't have to define the value for each variable within the Studio. You can do it from outside and it's often more confortable.
I strongly recommand to think about this way to operate with context.

TRF
Highlighted
Six Stars

Re: How to dynamically pass the path of tFileInputDelimited?

Yes, it is more advanced and easy to configure.

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Put Massive Amounts of Data to Work

Learn how to make your data more available, reduce costs and cut your build time

Watch Now

How OTTO Utilizes Big Data to Deliver Personalized Experiences

Read about OTTO's experiences with Big Data and Personalized Experiences

Blog

Talend Integration with Databricks

Take a look at this video about Talend Integration with Databricks

Watch Now