Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Probléme de load avec un Max sur un champ

J'essais de travailler sur une table événement et de récupérer le dernier événement par rapport à la date et un compteur interne.

Si je lance ce script il me créait une table de 1 800 000 enregistrements, mais avec jointure il me remonte tout soit 12 000 000...... j explose mon application

TMP_DERNIER_EVENEMENTS:
LOAD
DOS_GEX_ANNEE & DIV_CODE_SOURCE & DOS_GEX_NUMERO_DOSSIER as REF_DERNIER_EVE,
DOS_GEX_ANNEE & DIV_CODE_SOURCE & DOS_GEX_NUMERO_DOSSIER & max(EVE_COMPTEUR)as REF_DERNIER_EVEC,
max(EVE_COMPTEUR) as EVE_DERNIER_COMPTEUR,
max(EVE_DATE_CREATION) as EVE_DERNIER_DATE_CREATION
FROM [EVE_SUIVI.QVD](qvd)
group by DOS_GEX_ANNEE , DIV_CODE_SOURCE , DOS_GEX_NUMERO_DOSSIER;

left join (TMP_DERNIER_EVENEMENTS)
LOAD
DOS_GEX_ANNEE & DIV_CODE_SOURCE & DOS_GEX_NUMERO_DOSSIER & EVE_COMPTEUR as REF_DERNIER_EVE, // a enlever si suppression de table TMP
//DOS_GEX_ANNEE & DIV_CODE_SOURCE & DOS_GEX_NUMERO_DOSSIER & max(EVE_COMPTEUR) as REF_DERNIER_EVEC,
EVE_LIBELLE as EVE_DERNIER_LIBELLE1,
EVE_FAMILLE_ACTION as EVE_DERNIER_FAMILLE_ACTION1
FROM [EVE_SUIVI.QVD](qvd);

Si je rajoute un Max au EVE_COMPTEUR  (DOS_GEX_ANNEE & DIV_CODE_SOURCE & DOS_GEX_NUMERO_DOSSIER & EVE_COMPTEUR as REF_DERNIER_EVE)

J' obtiens cette erreur de script sans plus d'information !!!!

Si quelqu'un un à une idée!!

Merci d'avance

9 Replies
Not applicable
Author

Fabrice,

Oui, avec un MAX il faut un GROUP BY. Comme dans la 1ere commande.

Mettre a priori le même GROUP BY que lors de la première commande.

Le pb n'est pas la jointure, je ne pense pas.

Fabrice

Not applicable
Author

Fabrice merci pour ta réponse,

Mais non même avec le group by, je tourne en rond, je n'obtiens pas mon résultat.

matthias_v
Partner - Contributor III
Partner - Contributor III

Hello Fabrice,


The key in your 2nd load is linking with the wrong key.


Original:

DOS_GEX_ANNEE & DIV_CODE_SOURCE & DOS_GEX_NUMERO_DOSSIER & EVE_COMPTEUR asREF_DERNIER_EVE,


Should be (look at the rename of the key):

DOS_GEX_ANNEE & DIV_CODE_SOURCE & DOS_GEX_NUMERO_DOSSIER & EVE_COMPTEUR asREF_DERNIER_EVEC,

Not applicable
Author

Hello,

Thanks for your answer.

No same problem with this key,,, I am testing a lot of program, but same problem.

Currently I test with one LOAD,

But my problem is max(EVE_LIBELLE) .... the field is blank,

Thanks a lot

TMP_DERNIER_EVENEMENTS:

LOAD

   DOS_GEX_ANNEE & DIV_CODE_SOURCE & DOS_GEX_NUMERO_DOSSIER as REF_DERNIER_EVE,

   DOS_GEX_ANNEE & DIV_CODE_SOURCE & DOS_GEX_NUMERO_DOSSIER & max(EVE_COMPTEUR) as REF_DERNIER_EVEC,

   max(EVE_COMPTEUR) as EVE_DERNIER_COMPTEUR,

   max(EVE_DATE_CREATION) as EVE_DERNIER_DATE_CREATION,

   max(EVE_LIBELLE) as EVE_DERNIER_LIBELLE,

   max(EVE_FAMILLE_ACTION) as EVE_DERNIER_FAMILLE_ACTION

   FROM [EVE_SUIVI.QVD](qvd)

group by DOS_GEX_ANNEE , DIV_CODE_SOURCE , DOS_GEX_NUMERO_DOSSIER;

matthias_v
Partner - Contributor III
Partner - Contributor III

Hello Fabrice,

It's because you are trying to take the max value of a text-field, what you actually want is the value on the row for the Year - Source - Dossier - Counter where counter has the highest counter right?

try the following:

TMP_DERNIER_EVENEMENTS:

LOAD DISTINCT

   DOS_GEX_ANNEE & DIV_CODE_SOURCE & DOS_GEX_NUMERO_DOSSIER & max(EVE_COMPTEUR) as REF_DERNIER_EVEC,

max(EVE_COMPTEUR) as EVE_DERNIER_COMPTEUR

   FROM [EVE_SUIVI.QVD](qvd)

group by DOS_GEX_ANNEE , DIV_CODE_SOURCE , DOS_GEX_NUMERO_DOSSIER;

LEFT JOIN (TMP_DERNIER_EVENEMENTS)

LOAD

DOS_GEX_ANNEE & DIV_CODE_SOURCE & DOS_GEX_NUMERO_DOSSIER & EVE_COMPTEUR as REF_DERNIER_EVEC,

EVE_DATE_CREATION               as EVE_DERNIER_DATE_CREATION,

EVE_LIBELLE                                as EVE_DERNIER_LIBELLE,

EVE_FAMILLE_ACTION                as EVE_DERNIER_FAMILLE_ACTION

FROM [EVE_SUIVI.QVD](qvd);



In this way you will first create a value/key for every Year - Source - Dossier - Counter (where counter has the highest value). As such you can join the information you need for the keys you have created.

Not applicable
Author

I change my script,and I think that 's OK

I work with 'maxstring'.

TMP_DERNIER_EVENEMENTS:

LOAD

DOS_GEX_ANNEE & DIV_CODE_SOURCE & DOS_GEX_NUMERO_DOSSIER as REF_DERNIER_EVE,

//DOS_GEX_ANNEE & DIV_CODE_SOURCE & DOS_GEX_NUMERO_DOSSIER & max(EVE_COMPTEUR)as REF_DERNIER_EVEC,

max(EVE_COMPTEUR) as EVE_DERNIER_COMPTEUR,

max(EVE_DATE_CREATION) as EVE_DERNIER_DATE_CREATION,

maxstring(EVE_LIBELLE) as EVE_DERNIER_LIBELLE,

MaxString (EVE_FAMILLE_ACTION) as EVE_DERNIER_FAMILLE_ACTION

FROM [EVE_SUIVI.QVD](qvd)

group by DOS_GEX_ANNEE , DIV_CODE_SOURCE , DOS_GEX_NUMERO_DOSSIER

Thanks a lot for your help 😉

Have a nice day.

matthias_v
Partner - Contributor III
Partner - Contributor III

Hello Fabrice,

I'm afraid you might be making a mistake by using that function. maxstring just returns the last string it finds in the group by, in stead of the label that corresponds to the max(EVE_COMPTEUR). I guess you could do a ORDER BY EVE_COMPTEUR ASC to counter this.

maxstring:

Returns the last text value of expression over a number of records, as defined by a group by clause. If no text value is found, NULL is returned.

Just thinking out loud here. If you have verified your results and they are correct, then please ignore this comment

Not applicable
Author

Hello,

Yes my program isn't good but I have test your idee

First load, 1 186 876 lines (that s ok)

TMP_DERNIER_EVENEMENTS << EVE_SUIVI 1 186 876 lignes récupérées

Second load 14 584 2588 (thats not good)

EVE_SUIVI 14 584 258 lignes récupérées

matthias_v
Partner - Contributor III
Partner - Contributor III

Hi Fabrice,

Could you post a small subset of the data with the script you have right now. It will be a lot easier like that.