我试图将字符串转换为hadoop pig中的datetime对象。但是Grunt给了我一个奇怪的错误消息:就像它无法选择正确的'ToDate'函数。它正在要求“明确的 Actor 表”,但我不知道如何去做。任何的想法 ?

=>错误1045:无法推断出org.apache.pig.builtin.ToDate的匹配函数,因为它们多个或不合适。请使用显式强制转换。

grunt> describe infos_by_nu_affa;
infos_by_nu_affa: {NU_AFFA: bytearray,affaires: {(NU_AFFA:bytearray,NU_PCP: bytearray,debut: bytearray,fin: bytearray)},prestations: {(NU_AFFA: bytearray,montant: bytearray,date: bytearray,NU_presta: bytearray,beneficiaire: bytearray)},clients: {(NU_PCP: bytearray,nom: bytearray,prenom: bytearray)}}


derivees = foreach infos_by_nu_affa  generate *, ToDate(affaires.debut, 'dd/MM/yyyy') as (debut:datetime);
2015-03-28 15:46:36,089 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1045: <line 155, column 0> Could not infer the matching function for org.apache.pig.builtin.ToDate as multiple or none of them fit. Please use an explicit cast.


grunt> dump infos_by_nu_affa
(affaire5,{(affaire5,client5,01/01/14,05/01/15)},{},{(client5,enders,kililan)})
(affaire6,{(affaire6,client6,01/01/13,01/06/14)},{},{(client6,blanco,martine)})
(affaire7,{(affaire7,client7,01/01/10,02/03/13)},{},{(client7,sarah,moore)})
(affaire8,{(affaire8,client8,01/01/15,01/01/01)},{},{(client8,evrard,dominique)})



grunt> derivees = foreach infos_by_nu_affa
>> generate *,
>> COUNT(prestations) as nb_prestations,
>> ToDate(affaires.debut, 'dd/MM/yy') as debut;
2015-03-28 15:56:06,729 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1045:
<line 155, column 0> Could not infer the matching function for org.apache.pig.builtin.ToDate as multiple or none of them fit. Please use an explicit cast.

最佳答案

原因是您将bag datatype(ie,affaires.debut)作为输入传递给ToDate函数,但是Todate函数将仅接受chararray or byterarray作为输入。要解决此问题,需要在传递给flatten函数之前先对(affaires.debut)进行ToDate编码。应该是这样的

derivees_temp = foreach infos_by_nu_affa  generate *,FLATTEN(affaires.debut) as (debut_temp:chararray);
derivees = foreach derivees_temp  generate *, ToDate(debut_temp, 'dd/MM/yyyy') as (debut:datetime);

注意:在第一个stmt(ie,derivees_temp)中,将ozt_code的数据类型展平后为debut_temp,第二个stmt(chararray)在ie, derivees之后的数据类型为ToDate

关于hadoop - PIG-匹配toDate函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29318526/

10-12 17:32