I need to have a rule like this id,name,sex,age,old 1,anil,M,40,false rule: if(age>60){ set old = true }
can this be done using talend? it is a conditional setting or replacing of values. To make this condition static is possible using the various components like treplace, tsearch etc. But what i need is for the rule to be dynamic.
Can someone help on this? is there a way to do this? does somebody else face the same issue?
yes sure..
my dynamic rule would do hypothetically this
update delimitedFile.csv set old=true where age>60
this would be what i would like to do but
old=true
&
age>60
would be something that is passed as a context.rule or a context variable.
This is very easy to do on a table.. the problem is in my case the data is not in a table and i want to run this on a delimited file.
If you're familiar with Java Collections, the following blog post could be re-worked to store an 'age > 60' rule in a spreadsheet paired with a flag value 'true'.
http://bekwam.blogspot.com/2011/03/regex-lookup-table-with-talend-open.html The benefit of the spreadsheet approach is that it can handle bands of ages rather than a binary flag.
The post creates a Java Map of rules. The rules are applied to a data flow using a tJavaRow. In the tJavaRow, several of the output row fields are assigned input row fields directly. For one of the output row fields (VALUE), the assignment is based on looking up a rule from the Java Map and computing it against the input (SYSTEM_FUND_SOURCE_NM.matches(key)).
To adapt this to your case, you would define a spreadsheet record 'age/60/true'. In the tJavaRow, you'd look up this rule and compare input_row.age > key. If the condition is not met, default to 'false'.
i had seen this post, but the only problem in this case is
i need to map age condition to this. if i need to write this in java it would mean something like this
if condition.split("/").equals(age)
input_row.age
if condition.split("/").equals(sex)
input_row.sex
if condition.split("/").equals(name)
input_row.name
if condition.split("/").equals(old)
input_row.old
and this just makes up for the condition... then comes the replacement part...
where again same number of conditions....
and my delim file is 160 columns... and that too there are 6 diff kinds of delim file with diff column names....
Do you expect rules for each of the 160 fields? If not, you can use the "Sync columns" and "Generate code" buttons on the tJavaRow to map the 159 non-age fields without much effort. Then, at the base of the generated field assignments in the tJavaRow, add in the special processing (the java.util.Map lookup) for 'age'.
The following is the code i used to solve my requirement, this doesn't solve nested conditions but simple && an d || conditions are solved.....
input rule list would be like ths...
"TRGT_VAR_COMP|>|6.0|float,NAME|==|job_type_sam|string,START_DATE|<|11/02/2012|date,SPLIT|==|world|string--REPLACE--ID|6,SPLIT|SABA--REPLACE--&&"