<?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: Add rowNumber similar as SQL DENSE_RANK() in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/Add-rowNumber-similar-as-SQL-DENSE-RANK/m-p/2335782#M104302</link>
    <description>&lt;P&gt;&lt;A href="https://community.qlik.com/s/profile/0053p000007LKj7AAG"&gt;@TRF&lt;/A&gt;&amp;nbsp;I left this question open for a while while knocking up my example and doing something else. Didn't mean to steal your thunder mate&lt;/P&gt;</description>
    <pubDate>Thu, 07 Sep 2017 22:44:29 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2017-09-07T22:44:29Z</dc:date>
    <item>
      <title>Add rowNumber similar as SQL DENSE_RANK()</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Add-rowNumber-similar-as-SQL-DENSE-RANK/m-p/2335779#M104299</link>
      <description>&lt;P&gt;There is a flat file with CustomerID and Sales column. How can I add the RowNum column like below (similar as&amp;nbsp;SQL Dense_Rank() )for each CustomerID?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to use tJavaFlex, but was unable to get the Dense Rank. Thank you very much.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;CustomerID&lt;/TD&gt;&lt;TD&gt;sales&lt;/TD&gt;&lt;TD&gt;rowNum&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14256&lt;/TD&gt;&lt;TD&gt;30.34&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14256&lt;/TD&gt;&lt;TD&gt;30.34&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14256&lt;/TD&gt;&lt;TD&gt;30.32&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14256&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14567&lt;/TD&gt;&lt;TD&gt;45.3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14567&lt;/TD&gt;&lt;TD&gt;43.2&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14567&lt;/TD&gt;&lt;TD&gt;41&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14567&lt;/TD&gt;&lt;TD&gt;35&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14567&lt;/TD&gt;&lt;TD&gt;35&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 07 Sep 2017 21:26:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Add-rowNumber-similar-as-SQL-DENSE-RANK/m-p/2335779#M104299</guid>
      <dc:creator>JaneYu</dc:creator>
      <dc:date>2017-09-07T21:26:54Z</dc:date>
    </item>
    <item>
      <title>Re: Add rowNumber similar as SQL DENSE_RANK()</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Add-rowNumber-similar-as-SQL-DENSE-RANK/m-p/2335780#M104300</link>
      <description>Using tJavaRow you can:
&lt;BR /&gt;- compare the current ID with the previous one memorized in a global variable (initialize to a specific value when the job starts)
&lt;BR /&gt;- if the value changes, get the next value for the sequence s1 and store the result into the global variable "dr" using the syntax globalMap.set("dr", Numeric.sequence("s1", 1, 1))
&lt;BR /&gt;- push the value of "dr" to the field rownum with output_row.rownum = (Integer)global Map.get("dr")
&lt;BR /&gt;
&lt;BR /&gt;Hope this helps.</description>
      <pubDate>Thu, 07 Sep 2017 21:56:41 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Add-rowNumber-similar-as-SQL-DENSE-RANK/m-p/2335780#M104300</guid>
      <dc:creator>TRF</dc:creator>
      <dc:date>2017-09-07T21:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: Add rowNumber similar as SQL DENSE_RANK()</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Add-rowNumber-similar-as-SQL-DENSE-RANK/m-p/2335781#M104301</link>
      <description>&lt;P&gt;Here's a way you could approach this using a tJavaFlex. I have built an example job using your data. The job looks like below....&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2017-09-07 at 22.28.06.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009LwZB.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/138435i47A684F69B7E138C/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009LwZB.png" alt="0683p000009LwZB.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;The tFixedFlowInput simply holds your example data. This can be seen below....&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2017-09-07 at 22.28.21.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009Lwdu.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/154252iCD6A8B76DA2D0D6C/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009Lwdu.png" alt="0683p000009Lwdu.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;The tSortRow is simply there to ensure the order is correct. The sort key is CustomerID, then Sales. This is seen below....&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2017-09-07 at 22.28.46.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009LwUA.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/133635i0E3B8EC088E7C882/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009LwUA.png" alt="0683p000009LwUA.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;Once the data is ordered, we get on with the dense rank code. This uses a bit of Java, but it is quite simple. This can be seen in the tJavaFlex below.....&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2017-09-07 at 22.29.16.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009LwJr.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/137218iB41AD31A3C35E99B/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009LwJr.png" alt="0683p000009LwJr.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;I have included the code below so that you can copy it.....&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Start Code&lt;/P&gt; 
&lt;PRE&gt;// start part of your Java code
String curCustomerID = null;
double lastValue = 0.0;
int rank = 0;&lt;/PRE&gt; 
&lt;P&gt;Main Code&lt;/P&gt; 
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt; 
&lt;PRE&gt;// here is the main part of the component,
// a piece of code executed in the row
// loop
if(curCustomerID==null || curCustomerID.compareToIgnoreCase(row2.CustomerID)!=0){
	curCustomerID = row2.CustomerID;
	lastValue = -99999.9;
}

row3.CustomerID = curCustomerID;

if(row2.Sales!=lastValue){
	lastValue = row2.Sales; 
	rank = routines.Numeric.sequence(curCustomerID, 1, 1);
}

row3.Sales = lastValue;
row3.Rank = rank;&lt;/PRE&gt; 
&lt;P&gt;Essentially what we do is set up some variables to keep track of values between rows in the Start Code section. We then use the Main Code section to identify when the CustomerID has changed and when the Sales value has changed. When either have changed, we call the "Sequence" routine using the CustomerID as the key. When there are no changes, we reuse the last "rank" value.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2017 22:42:48 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Add-rowNumber-similar-as-SQL-DENSE-RANK/m-p/2335781#M104301</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-09-07T22:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: Add rowNumber similar as SQL DENSE_RANK()</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Add-rowNumber-similar-as-SQL-DENSE-RANK/m-p/2335782#M104302</link>
      <description>&lt;P&gt;&lt;A href="https://community.qlik.com/s/profile/0053p000007LKj7AAG"&gt;@TRF&lt;/A&gt;&amp;nbsp;I left this question open for a while while knocking up my example and doing something else. Didn't mean to steal your thunder mate&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2017 22:44:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Add-rowNumber-similar-as-SQL-DENSE-RANK/m-p/2335782#M104302</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-09-07T22:44:29Z</dc:date>
    </item>
  </channel>
</rss>

