How to capture tFileOutputPositional output in a global variable? - talend

How can I capture the output of a tFileOutputPositional in a variable? My tFileOutputPositional outputs only one row.

You would have to put variables fields by fields in global variables. For example :
InputFlow--->tFileOutputPositional-->tJavarow
Then in your tjavarow :
globalMap.put("myVariable_01",input_row.Field_01);
globalMap.put("myVariable_02",input_row.Field_02);
with Field_01/02 etc the names of fields in your input schema.

Related

How to set ts3Get key field dynamically in Talend?

I have extracted file name from tSQSInput using a tExtractJSONFields component and logged it on to the console using tLogRow. How can I pass this value to the "key" field in tS3Get component?
You can use either a context variable or a globalVariable
tSQSInput-->tExtractJsonFields-->TjavaRow
in tJavarow , set :
context.myKey=input_row.inputkey;
or
global.put("mykey",input_row.inputkey);
("inputkey" being the fieldname for your key)
Then in tS3Get (which you can link through a onSubJobOK), you can use the variable in the right field
context.myKey or ((String)globalMap.get("mykey"))
If you use context variable make sure you declared it on the 'context' tab of your job.

loop through field in a matlab struct array

I have a MatLab struct array as follow:
'country.source.scenario.category.entity= year'
I would like to loop over the existing 'country.source.scenario' combinations and produce cell or matrix containing the fields: category, entity and year.
Anyone as an idea about how to do that? Thanks
You can use fieldnames to get the fields at each level, and isstruct at each sublevel to see if you need to keep drilling, e.g.
fields = fieldnames(str);
for field = fields'
sub = str.(field{1});
if isstruct(sub)
%loop through fieldnames
end
end
You can put it in a recursive function whereby inside the if you again call the function. I did not do it like that because it was not clear to me what you wanted as a result, it seemed like you only wanted the tags and not the values at the end.

Put File Mask on tFileList Component dynamically

I was wondering if you let me know how I can set file mask for tFilelist component in Talend that it recognize date automatically and it will download only data for desired date?
I have tried some approach and I faced with some errors like "the method add (string) in the type list <String> is not applicable for the arguments (Date)"
There are two ways of doing it.
Create context variable and use this variable in file mask.
Directly use TalendDate.getDate() or any other date function in file mask.
See both of them in component
1st approach,
Create context variable named with dateFilter as string type.
Assign value to context.dateFilter=TalendDate.getDate("yyyy-MM-dd");
Suppose you have file name as "ABC_2015-06-19.txt" then
In tFileList file mask use this variable as follows.
"ABC_"+context.dateFilter+".*"
2nd approach
In tFileList file mask use date function as follows.
"ABC_"+TalendDate.getDate("yyyy-MM-dd")+".*"
these are the two best way, you can make changes in file mask per your file names.

when accessing teacher(1,2) why it doesn't execute both names khan and taj?

The MATLAB code
teacher(1)=struct('FirstName','Sohaib','LastName','Khan');
teacher(2)=struct( 'FirstName','Murtaza','LastName','Taj');
disp(teacher(1,2).LastName(1:end))
creates the output Taj. Why are not both names Khan and Taj displayed?
With teacher(1,2) you access the element in the first column and the second row of teacher. This is the entry with Taj. With LastName(1:end) you only access the name of the teacher you selected with teacher(1,2).
To display the names of both teachers, you have to specify the indexes of the teachers inside square brackets [1,2]. As disp only takes one argument, you have to create an array of names to print.
disp([teacher([1,2]).LastName])

Remove quotes from string

I have a MATLAB GUI that shows all variable names in the base workspace in a popupmenu. The user can then choose a variable. This variable is then passed into a function. My problem is that I cannot find a way to grab the variable's value from the popupmenu. I am getting a cell, which I convert into a string.
data = get(handles.popupmenu1,'String');
data = data{1};
The problem is that if the variable is named n, then this will return 'n', with quotes, when I need it to return it without quotes. So, when I try to get the value, it does not work.
data = evalin('base','data');
How do I remove the quotes from the string?
It's probably not the most efficient way, especially if you have a lot of variables in the popup menu, but could you store your variables in the handles structure of the GUI, and when the user selects a variable name from the popup menu it triggers a switch/case scenario in which you use strcmp, for example, to evaluate what the variable is and thus get its value form the handles structure?
Or maybe create some kind of lookup table in the UserData property of the popup menu, so that each 'String' displayed in the popup menu can be related to the corresponding variable, after which you get its value and can then pass to other callbacks?
I can't test it with a simple script right now and that's only ideas; I'll check tomorrow unless someone comes up with an idea in the meantime!
Ok, you can try this:
data = get(handles.popupmenu1,'Value');
Use 'Value' instead of 'String'.