pig-matching todate函数

ijnw1ujt  于 2021-05-30  发布在  Hadoop
关注(0)|答案(2)|浏览(360)

我试图在hadoop pig中向datetime对象强制转换字符串。但是grunt给了我一个奇怪的错误信息:它好像无法选择正确的“todate”函数。它要求一个“明确的演员阵容”,但我不知道怎么做。你知道吗?
=>错误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.
gywdnpxw

gywdnpxw1#

原因是你路过 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 ),在展平 debut_tempchararray 第二个stmt( ie, derivees )之后 ToDate 的数据类型 debutdatetime .

8yparm6h

8yparm6h2#

当我们没有为函数传递正确的参数类型时,就会出现这种异常。你们也面临同样的问题。todate函数支持各种类型的参数,请参考链接并根据需要更正代码。

相关问题