LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  While loop

    Employee
    Posted 03-11-2015 08:11

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Varsha.Pindola

    Hello

    I trying to count how many nulls appear in a string separated by ; eg xx is the string and I want to generate countofnulls column data below:

    xxx xx ctn&month countofnulls
    5 NULL;NULL;-0.5;-1;-1 7401254466-201209 2
    5 NULL;NULL;-0.62;-1.24;-1.24 7407542466-201209 2
    5 NULL;NULL;-0.83;-1.66;-1.66 7411211338-201209 2
    5 NULL;NULL;NULL;NULL;NULL 584654525-201301 5
    5 NULL;NULL;NULL;NULL;NULL 584655375-201301 5
    5 NULL;NULL;NULL;NULL;NULL 7400060121-201407 5
    5 NULL;NULL;NULL;NULL;NULL 7400181558-201309 5
    5 NULL;NULL;NULL;NULL;NULL 7400262677-201303 5
    5 NULL;NULL;NULL;NULL;NULL 7400515717-201402 5
    5 NULL;NULL;NULL;NULL;NULL 7400515717-201407 5


    Trying to achieve in a loop as shown below:

    xxx = split ('1:XX',";")
    yyy =len(xxx)

    i = 0
    countofnulls = 0
    while (i < yyy)
    {
    do{
    if isNull(xxx[i]) then
    dontEmit = countofnulls + 1
    else countofnulls = countofnulls
    i = i + 1
    }
    emit xx, countofnulls

    Please can you help

    Kind regards

    Varsha


  • 2.  RE: While loop

    Employee
    Posted 03-11-2015 12:34

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ryeh

    I can't exactly see what your data looks like. Everything looks good, but remove the do{ line. Do you get an error? If so, could you share the graph/nodes?


  • 3.  RE: While loop

    Employee
    Posted 03-12-2015 00:51

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Varsha.Pindola

    morning

    removed do { no error, but don't get the accepted results, I want to see a count of nulls in the string.
    The string is as shown below 4 variations:

    NULL;NULL;-0.5;-1;-1
    NULL;NULL;-0.62;-1.24;-1.24
    NULL;NULL;-0.83;-1.66;-1.66
    NULL;NULL;NULL;NULL;NULL

    So as a result I like to see a
    count of 2 for first 3 string fields and 5 for the last, I get a 0 for all.


    Thanks Varsha



    xxx = split ('1:XX',";")
    yyy =len(xxx)

    i = 0
    countofnulls = 0
    while (i < yyy)
    {

    if isNull(xxx[i]) then
    countofnulls = countofnulls + 1
    else countofnulls = countofnulls
    i = i + 1
    }
    emit xx, countofnulls


  • 4.  RE: While loop

    Employee
    Posted 03-12-2015 04:39

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ryeh

    So from what you're showing, you're saying "NULL" appears inside your string? If so, you need to change your IF condition to:
    if xxx[i] == "NULL"