Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
Below you can see the result of a query, with list of date in string
.-----------+------------+-----------------------------------------------------------------+----------------------------+-----------------------------. | tLogRow_2 | |=----------+------------+-----------------------------------------------------------------+----------------------------+----------------------------=| |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 | '-----------+------------------------+-----------------------------------------------------+----------------------------+-----------------------------'
Here's the result I want to get :
.-----------+------------------------+-----------------------------------------------------------------+-------------. | tLogRow_10 | |=----------+------------------------+-----------------------------------------------------------------+-------------=| |editorName |ProductName |end_date_resorption_versions |end_date_supported_versions |end_date_recommended_versions| |=----------+-------------+-------------------------------+----------------------------+----------------------------=| |EditorA |PN_A |31/03/2017 |30/06/2024 |30/06/2024 | |EditorB |PN_B |31/01/2012 |01/02/2020 |13/01/2020 | '-----------+-------------+-------------------------------+----------------------------+-----------------------------'
I want for each column find the min date.
12 rows in input -> 2 rows in outputs
My approach is this:
First, by column, I store all the values in an array
In a second step, I convert the dates which are in STRING to DATE.
In a third step, I retrieve for each column the date min.
So i to try to get the result i wanted : i used tJavaFlex
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 : end_date_resorption_versions myStringList_edrv.addAll(Arrays.asList(row4.end_date_resorption_versions.split(","))); // populating data : end_date_supported_versions myStringList_edsv.addAll(Arrays.asList(row4.end_date_supported_versions.split(","))); // populating data : end_date_recommended_versions myStringList_edrev.addAll(Arrays.asList(row4.end_date_recommended_versions.split(","))); // For => end_date_resorption_versions for (String ListOfDateString : myStringList_edrv) { dates.add(sdf.parse(ListOfDateString)); } // For end_date_supported_versions for (String ListOfDateString_edsv : myStringList_edsv) { dates_edsv.add(sdf.parse(ListOfDateString_edsv)); } // For end_date_recommended_versions for (String ListOfDateString_edrev : myStringList_edrev) { dates_edrev.add(sdf.parse(ListOfDateString_edrev)); }
End Code
// Output row // getDate min end_date_resorption_versions Date minDate = Collections.min(dates); String strDate = sdf.format(minDate); System.out.println(" getDate min end_date_resorption_versions : "+strDate); // getDate min end_date_supported_versions Date minDate_edsv = Collections.min(dates_edsv); String strDate_edsv = sdf.format(minDate_edsv); System.out.println(" getDate min end_date_supported_versions : "+strDate_edsv); // getDate min end_date_recommended_versions Date minDate_edrev = Collections.min(dates_edrev); String strDate_edrev = sdf.format(minDate_edrev); System.out.println(" getDate min end_date_recommended_versions : "+strDate_edrev); // row6.end_date_resorption_versions = strDate; row6.end_date_supported_versions = strDate_edsv; row6.end_date_recommended_versions = strDate_edrev; System.out.println(" THE END " );
And When I run the job, here's the result.
I get what I want when I put "System.out.println", but my output is like my input...
at the limit if I had the same values in the columns, I could use a tAggregateRow to have only a single row
where i'm wrong ?
Regards