3

I'm asking for your help,I'm facing a problem with the tJavaFlex component.

editorName ;ProductName ;end_date_resorption_versions;end_date_supported_versions ;end_date_recommended_versions
EditorA;PN_A;31/03/2017,31/03/2017,31/03/2017,31/03/2017,31/03/2017,31/03/2017;null;null 
EditorA;PN_A;30/06/2024;null;30/06/2024
EditorA;PN_A;30/11/2020,30/06/2017;null;null 
EditorA;PN_A;null;30/06/2024;null 
EditorA;PN_A ;null;null;null 
EditorA;PN_A;30/11/2020,30/11/2020;null;null 
EditorB;PN_B;18/05/2017,31/03/2017,31/01/20;null;null 
EditorB;PN_B;03/06/2024;01/02/2020;30/06/2024
EditorB;PN_B;23/12/2014      ;null;null 
EditorB;PN_B;null;01/02/2020;30/06/2020
EditorB;PN_B;null;null;null 
EditorB;PN_B;12/12/2012,31/12/2020;null;13/01/2020

Query

As u can see there are list of date (string format) in same column.

What i want to do ==> it's to find the min date for each column (not row)

Result expected

My approach is this :

  1. By column, store all values in an array
  2. convert ListString to ListDate
  3. Find Date min in each ListDate

I thought the best way to do that was to use the tJavaFlex component.

----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
**Start Code :**

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

// Array for end_date_resorption_versions
List<String> myStringList_edrv = new ArrayList<>();
List<Date> dates = new ArrayList<>();

// Array for end_date_supported_versions
List<String> myStringList_edsv = new ArrayList<>();
List<Date> dates_edsv = new ArrayList<>();

// Array for end_date_recommended_versions
List<String> myStringList_edrev = new ArrayList<>();
List<Date> dates_edrev = new ArrayList<>();
----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
**main code :**

if (row4.end_date_resorption_versions == null ){
        row4.end_date_resorption_versions  = "31/12/2099";
    }
if (row4.end_date_supported_versions == null ){     
        row4.end_date_supported_versions   = "31/12/2099";
    }
if (row4.end_date_recommended_versions == null) {
        row4.end_date_recommended_versions = "31/12/2099";
    }
// populating data : 
myStringList_edrv.addAll(Arrays.asList(row4.end_date_resorption_versions.split(",")));
myStringList_edsv.addAll(Arrays.asList(row4.end_date_supported_versions.split(",")));
myStringList_edrev.addAll(Arrays.asList(row4.end_date_recommended_versions.split(",")));
----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
**end code :**

// transform ListString to ListDate : end_date_resorption_versions
for (int i = 0 ; i < myStringList_edrv.size(); i++) {
    dates.add(sdf.parse(myStringList_edrv.get(i)));
    }
// transform ListString to ListDate : end_date_supported_versions
for (int i = 0 ; i < myStringList_edsv.size(); i++) {
    dates_edsv.add(sdf.parse(myStringList_edsv.get(i)));
    }
// transform ListString to ListDate : end_date_recommended_versions
for (int i = 0 ; i < myStringList_edrev.size(); i++) {
    dates_edrev.add(sdf.parse(myStringList_edrev.get(i)));
    }

// getMinDate : end_date_resorption_versions
row6.out_date_edrv  =   sdf.format(Collections.min(dates));
// getMinDate : end_date_supported_versions
row6.out_date_edsv  =   sdf.format(Collections.min(dates_edsv));
// getMinDate : end_date_recommended_versions
row6.out_date_edrev =   sdf.format(Collections.min(dates_edrev));

row6.out_editor_name = row4.editor_name;
row6.out_product_name = row4.product_name;

System.out.println("out_date_edrv => " + row6.out_date_edrv);
System.out.println("out_date_edsv => " + row6.out_date_edsv);
System.out.println("out_date_edrev => " + row6.out_date_edrev);

all my values are null, while the results present in the system.out.println are good

null value

my job design is :

tPostgresqlInput----row4(Main)----tJavaFlex_1----row6(Main)----tLogRow

some help would really be appreciated.

Ibrahim Mezouar
  • 3,981
  • 1
  • 18
  • 22
raoh
  • 47
  • 5

2 Answers2

1

You don't need all that java code. Here's a solution using only Talend components which has the advantage of being easier to maintain should your requirement change.
enter image description here

I start by normalizing your date columns; if only end_date_resorption_versions can contain a list of dates, then you can skip tNormalize_2 and tNormalize_3 which normalize end_date_supported_versions and end_date_recommended_versions respectively.
enter image description here

the tMap_1 is probably not needed, I use it to convert the "null" literal to null, since I copy pasted your sample data in a file for my test, otherwise the following conversion would fail.

enter image description here

tConvertType_1 then converts the date string to Date type, by checking the option "Auto cast", and setting the schema as follows:
enter image description here

Finally, tAggregateRow_1 will group on the editorName and ProductName columns and get the minimum date from each date column:
enter image description here

Ibrahim Mezouar
  • 3,981
  • 1
  • 18
  • 22
  • 1
    Hi @Ibrahim Mezouar, Thank you very much. It's working properly, and it is easier to maintain. There will be a little frustration left from not being able to do it with the tjavaFlex ;) PS: Thanks for embedding the images, I wasn't allowed to do it because you have to have reputation points – raoh May 20 '20 at 08:06
0

No explanation, just a nasty hack : Try to insert a tFlowToIterate before your tJavaFlex and feed the tJavaFlex with an iterate flow instead of a main flow (See pictures below).

Here, for some reason my tJavaFlex only reads null values from the input main flow

tJavaFlex reading only 'null' values from main flow

But it manages to read the exact same data when provided through an iterate flow. Note that as long as your input data flow isn't renamed (row4 in my example), you won't have to touch the code in your tJavaFlex.

tJavaFlex being able to read from an iterate flow

I have absolutely no clue on why nor when tJavaFlex wouldn't cope well with flows of type main, and I find that rather frustrating. I would surely appreciate if a talend guru could give me an explanation !