2012-03-22 16 views
8

Sto provando a scrivere uno script latin maiale per estrarre il conteggio di un set di dati che ho filtrato.Impossibile dedurre la funzione COUNT

Ecco lo script finora:

/* scans by title */ 

scans   = LOAD '/hive/scans/*' USING PigStorage(',') AS (thetime:long,product_id:long,lat:double,lon:double,user:chararray,category:chararray,title:chararray); 
productscans = FILTER scans BY (title MATCHES 'proactiv'); 
scancount  = FOREACH productscans GENERATE COUNT($0); 
DUMP scancount; 

Per qualche ragione, ottengo l'errore:

Could not infer the matching function for org.apache.pig.builtin.COUNT as multiple or none of them fit. Please use an explicit cast.

che cosa sto facendo male qui? Suppongo che abbia qualcosa a che fare con il tipo di campo in cui sto passando, ma non riesco a risolverlo.

TIA, Jason

risposta

14

E 'questo quello che stai cercando (gruppo da parte di tutti per portare tutto in un sacchetto, poi contare le voci):

scans   = LOAD '/hive/scans/*' USING PigStorage(',') AS (thetime:long,product_id:long,lat:double,lon:double,user:chararray,category:chararray,title:chararray); 
productscans = FILTER scans BY (title MATCHES 'proactiv'); 
grouped   = GROUP productscans ALL; 
count   = FOREACH grouped GENERATE COUNT(productscans); 
dump count; 
+2

Questo è tutto (meno" FOREACH g "dovrebbe essere" FOREACH raggruppato ") - grazie Chris! – JasonA

+0

Modificato, grazie per la recensione –

0

Forse

/* scans by title */ 

scans   = LOAD '/hive/scans/*' USING PigStorage(',') AS (thetime:long,product_id:long,lat:double,lon:double,user:chararray,category:chararray,title:chararray); 
productscans = FILTER scans BY (title MATCHES 'proactiv'); 
scancount  = FOREACH productscans GENERATE COUNT(productscans); 
DUMP scancount; 
+0

grazie Jake - purtroppo, senza fortuna. che mi dà: 'Proiezione scalare non valida: productscans: una colonna deve essere proiettata da una relazione perché sia ​​usata come scalare' – JasonA

4

COUNT richiede una istruzione GROUP ALL precedente per i conteggi globali e un'istruzione GROUP BY per i conteggi di gruppo.

È possibile utilizzare uno dei seguenti:

scans   = LOAD '/hive/scans/*' USING PigStorage(',') AS (thetime:long,product_id:long,lat:double,lon:double,user:chararray,category:chararray,title:chararray); 
productscans = FILTER scans BY (title MATCHES 'proactiv'); 
grouped   = GROUP productscans ALL; 
count   = FOREACH grouped GENERATE COUNT(productscans); 
DUMP scancount; 

O

scans   = LOAD '/hive/scans/*' USING PigStorage(',') AS (thetime:long,product_id:long,lat:double,lon:double,user:chararray,category:chararray,title:chararray); 
productscans = FILTER scans BY (title MATCHES 'proactiv'); 
grouped   = GROUP productscans ALL; 
count   = FOREACH grouped GENERATE COUNT($1); 
DUMP scancount; 
Problemi correlati