1

I have written an ETL in Talend Open Studio that loads a CSV/TSV file in a database. To do so, I want to provide the delimiter in tFileInputDelimited component using dynamic context load from a text file. I have specified it in the context file as fieldDelimiter="\t" and in the tFileInputDelimited component as shown in the screenshot. But, it doesn't work as a delimiter. I have also tried using fieldDelimiter="\\t" or fieldDelimiter="\u0009" (unicode character for tab).

What should I provide in the context file so that the delimiter is a tab character and not "\t" string as is happening in this case?

Jagrati Gogia
  • 221
  • 1
  • 3
  • 12
  • What do you mean by context *file*? Is this option set in the job tab "Context" as well? How do you execute the job? – tobi6 Jun 14 '17 at 12:21

4 Answers4

1

I notice a difference in the context variable names. In the screen shot you have mentioned (String)context.get("fileDelimiter"). But in the text you are saying "I have specified it in the context file as fieldDelimiter="\t" ".

just keeping the context as follows in the .properties file should work

fieldDelimiter=\t

Also use context.fieldDelimiter instead of (String)context.get("fileDelimiter").

Naga Pradeep
  • 200
  • 1
  • 8
1

In your context file, just put fileDelimiter = \t (Without quotes) And then access the variable in field delimiter. Talend will automatically handle it as string. Hope this works.

PreetyK
  • 455
  • 5
  • 14
0

There is no function (String)context.get("key") that I know of. If you have set the separator as a String element in the Context, just access it directly. Now there will be an empty String set as the field separator I suppose.

So if your field is called fileDelimiter simply put context.fileDelimiter into the Field Separator.

tobi6
  • 8,033
  • 6
  • 26
  • 41
  • I am unable to access context variables using context.fileDelimiter, but context.get("fileDelimiter") works. The problem is when I specify fileDelimiter="\t", it intends to delimit the file records using the string "\t" rather than the tab character. – Jagrati Gogia Jun 14 '17 at 12:08
  • Funny thing is, I have just seen that the method you are using is being used by Talend internally - to fill a variable called `context.fileDelimiter`. So there might be some issue with code generation. Also, the value is being taken as-is and no escaping is being done. I'd look further into why `context.fileDelimiter` is not available, this might help. – tobi6 Jun 14 '17 at 12:19
  • Thanks a lot @tobi6! – Jagrati Gogia Jun 17 '17 at 11:48
  • If this or another answer helped you, consider accepting the answer as the right one to help others as well. – tobi6 Jun 17 '17 at 11:50
0

As pointed out by others, you should use context.ParamName syntax, the benefit of this method is syntax checking at compile time which eliminates the risk of typos in your variable names. This parameter must be declared in your job (contexts tab) in order for Talend to recognize it. You can either create it as a built-in or import it if it's in the repository.

Ibrahim Mezouar
  • 3,981
  • 1
  • 18
  • 22