Pergunta


I need to replace text (month name) into another string (month number)
Is there any DECODE-like function that allows to replace one text into another?

I need something like oracle decode:

DECODE(inputStrint,'textToReplace1','Replacement1','textToReplace2,'Replacement2',etc);

Regards
Pawel

Foi útil?

Solução

You want to change the string value of a certain variable (let's say Month) by another string value ?

  • Since you use date you could check if there is any function which could help you here:

    [http://pig.apache.org/docs/r0.11.1/func.html#datetime-functions][1]

  • Or You can code your UDF fonction

  • Or you can do it with something like this :

    res = foreach Data {
        NewMonth = (Month matches 'January'? '1' : (Month matches 'February'? '2':(...) ) )
    Generate ...,NewMonth AS Month, ... ;
    }; 
    

    But it's not very beautiful, I truly recommend you to write a UDF fonction and then just call it :

    res = foreach Data Generate ...,ChangeMonth(Month) AS Month,...;
    
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top