<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: dynamic rule in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/dynamic-rule/m-p/2363232#M127182</link>
    <description>just a clarification the &lt;BR /&gt;data &lt;BR /&gt;id,name etc. is the row in a csv file.</description>
    <pubDate>Wed, 28 Sep 2011 12:33:45 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2011-09-28T12:33:45Z</dc:date>
    <item>
      <title>dynamic rule</title>
      <link>https://community.qlik.com/t5/Talend-Studio/dynamic-rule/m-p/2363231#M127181</link>
      <description>I need to have a rule like this&lt;BR /&gt;id,name,sex,age,old&lt;BR /&gt;1,anil,M,40,false&lt;BR /&gt;rule:&lt;BR /&gt;if(age&amp;gt;60){&lt;BR /&gt;   set old = true&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;can this be done using talend?&lt;BR /&gt;it is a conditional setting or replacing of values.  To make this condition static is possible using the various components like treplace, tsearch etc.&lt;BR /&gt;But what i need is for the rule to be dynamic.&lt;BR /&gt;&lt;BR /&gt;Can someone help on this? is there a way to do this? does somebody else face the same issue?</description>
      <pubDate>Sat, 16 Nov 2024 12:39:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/dynamic-rule/m-p/2363231#M127181</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-16T12:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic rule</title>
      <link>https://community.qlik.com/t5/Talend-Studio/dynamic-rule/m-p/2363232#M127182</link>
      <description>just a clarification the &lt;BR /&gt;data &lt;BR /&gt;id,name etc. is the row in a csv file.</description>
      <pubDate>Wed, 28 Sep 2011 12:33:45 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/dynamic-rule/m-p/2363232#M127182</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-09-28T12:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic rule</title>
      <link>https://community.qlik.com/t5/Talend-Studio/dynamic-rule/m-p/2363233#M127183</link>
      <description>Depends of what you mean by a dynamic rule. Can you explain more or give some exemple?</description>
      <pubDate>Wed, 28 Sep 2011 12:47:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/dynamic-rule/m-p/2363233#M127183</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-09-28T12:47:24Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic rule</title>
      <link>https://community.qlik.com/t5/Talend-Studio/dynamic-rule/m-p/2363234#M127184</link>
      <description>yes sure..
&lt;BR /&gt;my dynamic rule would do hypothetically this
&lt;BR /&gt;update delimitedFile.csv set old=true where age&amp;gt;60 
&lt;BR /&gt;this would be what i would like to do but 
&lt;BR /&gt;old=true 
&lt;BR /&gt;&amp;amp; 
&lt;BR /&gt;age&amp;gt;60 
&lt;BR /&gt;would be something that is passed as a context.rule or a context variable.
&lt;BR /&gt;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.</description>
      <pubDate>Wed, 28 Sep 2011 13:03:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/dynamic-rule/m-p/2363234#M127184</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-09-28T13:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic rule</title>
      <link>https://community.qlik.com/t5/Talend-Studio/dynamic-rule/m-p/2363235#M127185</link>
      <description>If you're familiar with Java Collections, the following blog post could be re-worked to store an 'age &amp;gt; 60' rule in a spreadsheet paired with a flag value 'true'. 
&lt;BR /&gt; 
&lt;A href="http://bekwam.blogspot.com/2011/03/regex-lookup-table-with-talend-open.html" rel="nofollow noopener noreferrer"&gt;http://bekwam.blogspot.com/2011/03/regex-lookup-table-with-talend-open.html&lt;/A&gt; 
&lt;BR /&gt;The benefit of the spreadsheet approach is that it can handle bands of ages rather than a binary flag. 
&lt;BR /&gt;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)). 
&lt;BR /&gt;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 &amp;gt; key. If the condition is not met, default to 'false'.</description>
      <pubDate>Wed, 28 Sep 2011 13:17:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/dynamic-rule/m-p/2363235#M127185</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-09-28T13:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic rule</title>
      <link>https://community.qlik.com/t5/Talend-Studio/dynamic-rule/m-p/2363236#M127186</link>
      <description>i had seen this post, but the only problem in this case is 
&lt;BR /&gt;i need to map age condition to this. if i need to write this in java it would mean something like this 
&lt;BR /&gt;if condition.split("/").equals(age) 
&lt;BR /&gt;input_row.age 
&lt;BR /&gt; 
&lt;BR /&gt;if condition.split("/").equals(sex) 
&lt;BR /&gt;input_row.sex 
&lt;BR /&gt;if condition.split("/").equals(name) 
&lt;BR /&gt;input_row.name 
&lt;BR /&gt;if condition.split("/").equals(old) 
&lt;BR /&gt;input_row.old 
&lt;BR /&gt;and this just makes up for the condition... then comes the replacement part... 
&lt;BR /&gt;where again same number of conditions.... 
&lt;BR /&gt;and my delim file is 160 columns... and that too there are 6 diff kinds of delim file with diff column names....</description>
      <pubDate>Wed, 28 Sep 2011 13:29:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/dynamic-rule/m-p/2363236#M127186</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-09-28T13:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic rule</title>
      <link>https://community.qlik.com/t5/Talend-Studio/dynamic-rule/m-p/2363237#M127187</link>
      <description>Do you expect rules for each of the 160 fields?&lt;BR /&gt;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.&lt;BR /&gt;Then, at the base of the generated field assignments in the tJavaRow, add in the special processing (the java.util.Map lookup) for 'age'.</description>
      <pubDate>Wed, 28 Sep 2011 14:12:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/dynamic-rule/m-p/2363237#M127187</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-09-28T14:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: dynamic rule</title>
      <link>https://community.qlik.com/t5/Talend-Studio/dynamic-rule/m-p/2363238#M127188</link>
      <description>The following is the code i used to solve my requirement, this doesn't solve nested conditions but simple &amp;amp;&amp;amp; an d || conditions are solved..... 
&lt;BR /&gt;input rule list would be like ths... 
&lt;BR /&gt;"TRGT_VAR_COMP|&amp;gt;|6.0|float,NAME|==|job_type_sam|string,START_DATE|&amp;lt;|11/02/2012|date,SPLIT|==|world|string--REPLACE--ID|6,SPLIT|SABA--REPLACE--&amp;amp;&amp;amp;" 
&lt;BR /&gt; 
&lt;BR /&gt;String[] ruleArray = context.ruleList.split("--RULES--"); 
&lt;BR /&gt; 
&lt;BR /&gt; for (String conditionArrayElet : ruleArray) { 
&lt;BR /&gt; String conditionList = conditionArrayElet.split("--REPLACE--"); 
&lt;BR /&gt; // "ID|==|1,ORG_NO|!=|1,SPLIT|==|world"; 
&lt;BR /&gt; String replaceList = conditionArrayElet.split("--REPLACE--"); 
&lt;BR /&gt; String operator = conditionArrayElet.split("--REPLACE--"); 
&lt;BR /&gt; // "ID|5,ORG_NO|replacedOrgNo,SPLIT|SABA"; 
&lt;BR /&gt; String[] conditionArr = conditionList.split(","); 
&lt;BR /&gt; String[] replaceArr = replaceList.split(","); 
&lt;BR /&gt; List&amp;lt;Boolean&amp;gt; founds = new ArrayList&amp;lt;Boolean&amp;gt;(); 
&lt;BR /&gt; for (String condition : conditionArr) { 
&lt;BR /&gt; if (condition.split("\\|").equals("float")) { 
&lt;BR /&gt; Float firstElet = (Float) (row1.getClass().getField((condition.split("\\|")).trim()).get(row1)); 
&lt;BR /&gt; Float secondElet = Float.parseFloat(condition.split("\\|")); 
&lt;BR /&gt; if (condition.split("\\|").equals("&amp;lt;")) { 
&lt;BR /&gt; if (firstElet &amp;lt; secondElet) { 
&lt;BR /&gt; founds.add(true); 
&lt;BR /&gt; } else { 
&lt;BR /&gt; founds.add(false); 
&lt;BR /&gt; } 
&lt;BR /&gt; } else if (condition.split("\\|").equals("&amp;gt;")) { 
&lt;BR /&gt; if (firstElet &amp;gt; secondElet) { 
&lt;BR /&gt; founds.add(true); 
&lt;BR /&gt; } else { 
&lt;BR /&gt; founds.add(false); 
&lt;BR /&gt; } 
&lt;BR /&gt; } else if (condition.split("\\|").equals("==")) { 
&lt;BR /&gt; if (firstElet == secondElet) { 
&lt;BR /&gt; founds.add(true); 
&lt;BR /&gt; } else { 
&lt;BR /&gt; founds.add(false); 
&lt;BR /&gt; } 
&lt;BR /&gt; } else if (condition.split("\\|").equals("!=")) { 
&lt;BR /&gt; if (!firstElet.equals(secondElet)) { 
&lt;BR /&gt; founds.add(true); 
&lt;BR /&gt; } else { 
&lt;BR /&gt; founds.add(false); 
&lt;BR /&gt; } 
&lt;BR /&gt; } 
&lt;BR /&gt; } else if (condition.split("\\|").equals("date")) { 
&lt;BR /&gt; Date firstElet = 
&lt;BR /&gt; (Date) (row1.getClass().getField((condition.split("\\|")).trim()).get(row1)); 
&lt;BR /&gt; SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); 
&lt;BR /&gt; Date secondElet = format.parse(condition.split("\\|")); 
&lt;BR /&gt; // System.out.println(firstElet); 
&lt;BR /&gt; // System.out.println(secondElet); 
&lt;BR /&gt; if (condition.split("\\|").equals("&amp;lt;")) { 
&lt;BR /&gt; if (firstElet.before(secondElet)) { 
&lt;BR /&gt; founds.add(true); 
&lt;BR /&gt; } else { 
&lt;BR /&gt; founds.add(false); 
&lt;BR /&gt; } 
&lt;BR /&gt; } else if (condition.split("\\|").equals("&amp;gt;")) { 
&lt;BR /&gt; if (firstElet.after(secondElet)) { 
&lt;BR /&gt; founds.add(true); 
&lt;BR /&gt; } else { 
&lt;BR /&gt; founds.add(false); 
&lt;BR /&gt; } 
&lt;BR /&gt; } else if (condition.split("\\|").equals("==")) { 
&lt;BR /&gt; if (firstElet.equals(secondElet)) { 
&lt;BR /&gt; founds.add(true); 
&lt;BR /&gt; } else { 
&lt;BR /&gt; founds.add(false); 
&lt;BR /&gt; } 
&lt;BR /&gt; } else if (condition.split("\\|").equals("!=")) { 
&lt;BR /&gt; if (!firstElet.equals(secondElet)) { 
&lt;BR /&gt; founds.add(true); 
&lt;BR /&gt; } else { 
&lt;BR /&gt; founds.add(false); 
&lt;BR /&gt; } 
&lt;BR /&gt; } 
&lt;BR /&gt; } else { 
&lt;BR /&gt; if (condition.split("\\|").equals("==")) { 
&lt;BR /&gt; if (row1.getClass().getField((condition.split("\\|")).trim()).get(row1).equals( 
&lt;BR /&gt; (condition.split("\\|")).trim())) { 
&lt;BR /&gt; founds.add(true); 
&lt;BR /&gt; } else { 
&lt;BR /&gt; founds.add(false); 
&lt;BR /&gt; } 
&lt;BR /&gt; } else if (condition.split("\\|").equals("!=")) { 
&lt;BR /&gt; if (row1.getClass().getField((condition.split("\\|")).trim()).get(row1).equals( 
&lt;BR /&gt; (condition.split("\\|")).trim())) { 
&lt;BR /&gt; founds.add(false); 
&lt;BR /&gt; } else { 
&lt;BR /&gt; founds.add(true); 
&lt;BR /&gt; } 
&lt;BR /&gt; } 
&lt;BR /&gt; } 
&lt;BR /&gt; } 
&lt;BR /&gt; if (founds.size() &amp;gt; 0) { 
&lt;BR /&gt; boolean found = founds.get(0); 
&lt;BR /&gt; if (operator.equals("&amp;amp;&amp;amp;")) { 
&lt;BR /&gt; for (Boolean boolean1 : founds) { 
&lt;BR /&gt; found = boolean1 &amp;amp;&amp;amp; found; 
&lt;BR /&gt; } 
&lt;BR /&gt; } else { 
&lt;BR /&gt; for (Boolean boolean1 : founds) { 
&lt;BR /&gt; found = boolean1 || found; 
&lt;BR /&gt; } 
&lt;BR /&gt; } 
&lt;BR /&gt; // there are multiple conditions joined by and, so we need to look at the output condition 
&lt;BR /&gt; if (found) { 
&lt;BR /&gt; for (String replace : replaceArr) { 
&lt;BR /&gt; if (row1.getClass().getField(replace.split("\\|")).get(row1) instanceof Float) { 
&lt;BR /&gt; Float replaceFloat = Float.parseFloat(replace.split("\\|")); 
&lt;BR /&gt; row1.getClass().getField(replace.split("\\|")).set(row1, replaceFloat); 
&lt;BR /&gt; } else if (row1.getClass().getField(replace.split("\\|")).get(row1) instanceof Date) { 
&lt;BR /&gt; SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); 
&lt;BR /&gt; Date replaceDate = format.parse(replace.split("\\|")); 
&lt;BR /&gt; row1.getClass().getField(replace.split("\\|")).set(row1, replaceDate); 
&lt;BR /&gt; } else { 
&lt;BR /&gt; row1.getClass().getField(replace.split("\\|")).set(row1, replace.split("\\|")); 
&lt;BR /&gt; } 
&lt;BR /&gt; } 
&lt;BR /&gt; } 
&lt;BR /&gt; } 
&lt;BR /&gt; // row2Struct row3 = new row2Struct(); 
&lt;BR /&gt; // The row1 is modified need to write it into row2 
&lt;BR /&gt; Field[] fields = row1.getClass().getFields(); 
&lt;BR /&gt; for (Field field : fields) { 
&lt;BR /&gt; Object fieldValue = row1.getClass().getField(field.getName()).get(row1); 
&lt;BR /&gt; row3.getClass().getField(field.getName()).set(row3, fieldValue); 
&lt;BR /&gt; } 
&lt;BR /&gt; // System.out.println(row2); 
&lt;BR /&gt; }</description>
      <pubDate>Tue, 04 Oct 2011 11:09:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/dynamic-rule/m-p/2363238#M127188</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-10-04T11:09:09Z</dc:date>
    </item>
  </channel>
</rss>

