Search code examples
oracle-databasecsvtalend

Return last ID from a column


Is there a way to return the last ID from a column (called ID_MES) without browsing through all of the records?

My job Talentd:

my job  TALEND


Solution

  • Without browsing the records it's not possible to find out the last records. However we can minimize the data flow between the components as follows.

    For simplicity I am demonstrating the input as fixed flow input. The logic is as follows.

    1. Suppose there are 'N' number of columns for each record, then first we will consider the column we are interested in using 'tFilterColumns' and eliminate all other columns.
    2. Find the last value of that column using tAggregateRow.
    3. put the value in the globalMap [or] simply display the value using tJavaRow.

    Find the below job which i have developed.

    I have created a fixed flow with 6 columns and 12 records as shown in the image below.

    enter image description here

    I am interested in 'ID_MES' column alone, therefore i am using tFilterColumns. By using this component we can eliminate the unnecessary data flow.

    enter image description here

    Then a tAggregateRow is used and in it's operation section of component properties, I used 'ID_MES' as output column with 'last' function.

    enter image description here This is the tJavaRow component where we can use the last 'ID' value

    And finally the output is as follows.

    enter image description here