Grokbase Groups Pig user October 2010
FAQ
Hi,

I have this pig script.

1 data = LOAD '$INPUT' USING PigStorage(',') AS (app:chararray,
user:chararray , timestamp:int, duration:int);
2
3 appUserIn = FOREACH data GENERATE app, user;
5 distinctAppUserIn = DISTINCT appUserIn;
6
7 groupOnApp = GROUP distinctAppUserIn BY app;
8
9 result = FOREACH groupOnApp GENERATE group, COUNT(distinctAppUserIn);
10
11 STORE result INTO '$OUTPUT' USING PigStorage();

I would like to add a constant to the output such a a timestamp pass into
the pig script. So idealy I could do FOREACH groupOnApp GENERATE group,
COUNT(distinctAppUserIn), *'time_constant'*;

Is this possible in Pig?

thanks,

John

Search Discussions

  • Konstantin Ignatyev at Oct 20, 2010 at 9:32 pm
    g1 = LOAD 'data/grptest' USING PigStorage(',') AS ( a, b , c, d);

    r = FOREACH g1 GENERATE
    '$myconstant' as constant,
    a
    ;


    when called like this:
    pig [-x local] -param myconstant=zz <script name>

    the output looks like this:

    (zz,3)
    (zz,5)
    (zz,2)
    (zz,7)...
    On Wed, Oct 20, 2010 at 1:00 PM, John Hui wrote:

    Hi,

    I have this pig script.

    1 data = LOAD '$INPUT' USING PigStorage(',') AS (app:chararray,
    user:chararray , timestamp:int, duration:int);
    2
    3 appUserIn = FOREACH data GENERATE app, user;
    5 distinctAppUserIn = DISTINCT appUserIn;
    6
    7 groupOnApp = GROUP distinctAppUserIn BY app;
    8
    9 result = FOREACH groupOnApp GENERATE group, COUNT(distinctAppUserIn);
    10
    11 STORE result INTO '$OUTPUT' USING PigStorage();

    I would like to add a constant to the output such a a timestamp pass into
    the pig script. So idealy I could do FOREACH groupOnApp GENERATE group,
    COUNT(distinctAppUserIn), *'time_constant'*;

    Is this possible in Pig?

    thanks,

    John


    --
    Konstantin Ignatyev

    PS: If this is a typical day on planet earth, humans will add fifteen
    million tons of carbon to the atmosphere, destroy 115 square miles of
    tropical rainforest, create seventy-two miles of desert, eliminate between
    forty to one hundred species, erode seventy-one million tons of topsoil, add
    2,700 tons of CFCs to the stratosphere, and increase their population by
    263,000

    Bowers, C.A. The Culture of Denial: Why the Environmental Movement Needs a
    Strategy for Reforming Universities and Public Schools. New York: State
    University of New York Press, 1997: (4) (5) (p.206)

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriespig, hadoop
postedOct 20, '10 at 8:13p
activeOct 20, '10 at 9:32p
posts2
users2
websitepig.apache.org

2 users in discussion

John Hui: 1 post Konstantin Ignatyev: 1 post

People

Translate

site design / logo © 2021 Grokbase