bonjour à tous,
j'ai un énorme problème, comme tout le monde ici...
je travail sur kettle qui me permet d’insérer une étape faisant appel à un script java que voici :
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
| //CREATE a Locale according TO the specified LANGUAGE code
var locale = new java.util.Locale(
language_code
, country_code
);
//CREATE a calendar, USE the specified initial date
var calendar = new java.util.GregorianCalendar(locale);
calendar.setTime(initial_date);
//SET the calendar TO the current date BY adding DaySequence days
//calendar.ADD(calendar.DAY_OF_MONTH,DaySequence - 1); anciene ligne
calendar.ADD(calendar.HOUR_OF_DAY,DaySequence - 1);//modification pour génerer les heures de la journée
//get the calendar date
var date = new java.util.Date(calendar.getTimeInMillis());
//en-us example: 9/3/07
var date_short = java.text.DateFormat.getDateInstance(
java.text.DateFormat.SHORT
, locale
).format(date);
//en-us example: Sep 3, 2007
var date_medium = java.text.DateFormat.getDateInstance(
java.text.DateFormat.MEDIUM
, locale
).format(date);
//en-us example: September 3, 2007
var date_long = java.text.DateFormat.getDateInstance(
java.text.DateFormat.LONG
, locale
).format(date);
//en-us example: Monday, September 3, 2007
var date_full = java.text.DateFormat.getDateInstance(
java.text.DateFormat.FULL
, locale
).format(date);
//day IN year: 1..366
var simpleDateFormat = java.text.SimpleDateFormat("D",locale);
var day_in_year = simpleDateFormat.format(date);
//day IN month: 1..31
simpleDateFormat.applyPattern("d");
var day_in_month = simpleDateFormat.format(date);
//en-us example: "Monday"
simpleDateFormat.applyPattern("EEEE");
var day_name = simpleDateFormat.format(date);
//en-us example: "Mon"
simpleDateFormat.applyPattern("E");
var day_abbreviation = simpleDateFormat.format(date);
//week IN year, 1..53
simpleDateFormat.applyPattern("ww");
var week_in_year = simpleDateFormat.format(date);
//week IN month, 1..5
simpleDateFormat.applyPattern("W");
var week_in_month = simpleDateFormat.format(date);
//month number IN year, 1..12
simpleDateFormat.applyPattern("MM");
var month_number = simpleDateFormat.format(date);
//en-us example: "September"
simpleDateFormat.applyPattern("MMMM");
var month_name = simpleDateFormat.format(date);
//en-us example: "Sep"
simpleDateFormat.applyPattern("MMM");
var month_abbreviation = simpleDateFormat.format(date);
//2 digit representation of the year, example: "07" FOR 2007
simpleDateFormat.applyPattern("y");
var year2 = simpleDateFormat.format(date);
//4 digit representation of the year, example: 2007
simpleDateFormat.applyPattern("yyyy");
var year4 = simpleDateFormat.format(date);
//handling Quarters IS a DIY
var quarter_name = "Q";
var quarter_number;
switch(parseInt(month_number)){
case 1: case 2: case 3: quarter_number = "1"; break;
case 4: case 5: case 6: quarter_number = "2"; break;
case 7: case 8: case 9: quarter_number = "3"; break;
case 10: case 11: case 12: quarter_number = "4"; break;
}
quarter_name += quarter_number;
//get the LOCAL yes/no VALUES
var yes = local_yes;
var no = local_no;
//initialize FOR week calculations
var first_day_of_week = calendar.getFirstDayOfWeek();
var day_of_week = java.util.Calendar.DAY_OF_WEEK;
//find out IF this IS the first day of the week
var is_first_day_in_week;
IF(first_day_of_week==calendar.get(day_of_week)){
is_first_day_in_week = yes;
} else {
is_first_day_in_week = no;
}
//calculate the next day
calendar.ADD(calendar.DAY_OF_MONTH,1);
//get the next calendar date
var next_day = new java.util.Date(calendar.getTimeInMillis());
//find out IF this IS the first day of the week
var is_last_day_in_week;
IF(first_day_of_week==calendar.get(day_of_week)){
is_last_day_in_week = yes;
} else {
is_last_day_in_week = no;
}
//find out IF this IS the first day of the month
var is_first_day_of_month;
IF(day_in_month == 1){
is_first_day_in_month = yes;
} else {
is_first_day_in_month = no;
}
//find out IF this IS the last day IN the month
var is_last_day_of_month;
IF(java.text.SimpleDateFormat("d",locale).format(next_day)==1){
is_last_day_in_month = yes;
} else {
is_last_day_in_month = no;
}
//date = year4 + "-" + month_number + "-" + day_in_month
var year_quarter = year4 + "-" + quarter_name;
var year_month_number = year4 + "-" + month_number;
var year_month_abbreviation = year4 + "-" + month_abbreviation;
IF ((day_name=='samedi' ) || (day_name=='dimanche') || (date_short=="01/11/09") || (date_short=="11/11/09") || (date_short=="25/12/09") || (date_short=="01/01/10") || (date_short=="05/04/10") || (date_short=="01/05/10") || (date_short=="08/05/10") || (date_short=="13/05/10") || (date_short=="24/05/10") || (date_short=="14/07/10") || (date_short=="15/08/10") || (date_short=="01/11/10") || (date_short=="11/11/10") || (date_short=="25/12/10")) {
var date_duration_hours= 0;
} else {
var date_duration_hours= 7;
} |
la transformation qui fait appel à ce script me permet de créer une dimension date tenant compte des heures de la journée, au date de passage à l'heure d'été je n'ai pas de ligne avec pour heure 02:00:00 ce qui est normal sauf que mon fichier de données brute qui va servir à remplir la table des faits à des lignes avec 02:00:00 même les jours il ne doit pas y en avoir...
kettle bloque sur ces lignes et me dit qu'il ne peut pas convertir la date de type string à l'origine (fichier csv) en type date...
j'aimerai bien pouvoir créer un calendrier comme plus haut mais sans tenir compte des changement d'heure et pouvoir convertir ma chaine de caractère ex : 30/03/1997 02:00:00 en date sans que java me génère d'erreur.