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.  Do while loop

    Employee
    Posted 02-26-2016 03:45

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

    Originally posted by: dhrobertson

    Hi,

    I having a problem with a Do While loop. I'm just trying to test the logic so the graph itself may not make much sense but, the issue is, the loop will go round once, and increment the "counter", in this case lineno. it continues and with the loop and outputs as expected, but the 3rd time it goes around where the lineno is now 2.... the node "Determine Next" will not evaluate the lineno as expected and assigns the final value.

    in other words:

    I have an if statement which increases lineno. it works successfully for 2 passes after which is doesn't evaluate when lineno == "2" and jumps to the final assignment of "5".

    what might be happening here? I cant work it out... is something happening in the Do While node which is causing lineno to stop evaluating or am I doing something stupid?

    nodes are pasted below... any help appreciated...

    thanks

    Douglas


    node:Static_Data_3
    bretype:core::Static Data
    editor:sortkey=56bdf60f489f3ca6_2
    output:@40fe6c55598828e5/=
    prop:StaticData=<<EOX
    country_code:string,line:string
    CA,this is CA1
    CA,this is CA2
    CA,this is CA3
    CA,this is CA4
    CA,this is CA5
    CA,this is CA6
    CA,this is CA7
    CA,this is CA8
    CA,this is CA9
    CA,this is CA9
    PT, this is PT1
    PT, this is PT2
    PT, this is PT3
    PT, this is PT4
    PT, this is PT5
    PT, this is PT6
    SE, this is SE1
    SE, this is SE2
    SE, this is SE3
    SE, this is SE4
    EOX
    editor:XY=1140,660
    end:Static_Data_3

    node:XRef_5
    bretype:core::X-Ref
    editor:sortkey=56bdf5d2237f661e_4
    input:@45781ca80c2802d0/=Static_Data_3.40fe6c55598828e5
    input:@45781ca971fe502f/=States_4.40fe6c55598828e5
    output:@45781cad02e051b0/=
    output:@457826825d7c2de0/=
    output:@4578268450ad5d88/=
    prop:LeftInputKey=<<EOX
    country_code
    EOX
    prop:RightInputKey=<<EOX
    State
    EOX
    prop:SortLeftInput=true
    prop:SortRightInput=true
    editor:XY=1310,660
    node:Sort_2
    bretype:::Sort
    editor:shadow=45782670131b71e8
    input:@40fd2c743ebf4304/=
    output:@40fd2c746a2a3b47/=
    end:Sort_2

    node:Bypass_3
    bretype:::Bypass
    editor:shadow=4578267017753cec
    input:@45782010749f0c96/=
    input:@457820124fef7658/=
    output:@40fd2c7436717256/=
    end:Bypass_3

    node:Join
    bretype:::Join
    editor:shadow=457826701862249e
    input:@40fd2c745b6d7704/=
    input:@40fd2c74504921cd/=
    output:@40fd2c7430f76546/=
    output:@457826cc03a465f4/=
    output:@457826cc510c69e0/=
    end:Join

    node:Bypass
    bretype:::Bypass
    editor:shadow=4578267041681261
    input:@45782010749f0c96/=
    input:@457820124fef7658/=
    output:@40fd2c7436717256/=
    end:Bypass

    node:Sort
    bretype:::Sort
    editor:shadow=4578267075a60d09
    input:@40fd2c743ebf4304/=
    output:@40fd2c746a2a3b47/=
    end:Sort

    end:XRef_5

    node:States_4
    bretype:core::Static Data
    editor:Label=States
    editor:sortkey=56bdf60f1dd53337_3
    output:@40fe6c55598828e5/=
    prop:StaticData=<<EOX
    lineno:unicode,State
    1,CA
    EOX
    editor:XY=1140,750
    end:States_4

    node:XRef_2
    bretype:core::X-Ref
    editor:sortkey=56bdf5d2237f661e_3
    input:@45781ca80c2802d0/=Static_Data_3.40fe6c55598828e5
    input:@45781ca971fe502f/=XRef_6.457826825d7c2de0
    editor:bend=1=1750|850
    editor:bend=1=1750|930
    editor:bend=1=1260|930
    output:@45781cad02e051b0/=
    output:@457826825d7c2de0/=
    output:@4578268450ad5d88/=
    prop:LeftInputKey=<<EOX
    country_code
    EOX
    prop:RightInputKey=<<EOX
    State
    EOX
    prop:SortLeftInput=true
    prop:SortRightInput=true
    editor:XY=1290,790
    node:Sort_2
    bretype:::Sort
    editor:shadow=45782670131b71e8
    input:@40fd2c743ebf4304/=
    output:@40fd2c746a2a3b47/=
    end:Sort_2

    node:Bypass_3
    bretype:::Bypass
    editor:shadow=4578267017753cec
    input:@45782010749f0c96/=
    input:@457820124fef7658/=
    output:@40fd2c7436717256/=
    end:Bypass_3

    node:Join
    bretype:::Join
    editor:shadow=457826701862249e
    input:@40fd2c745b6d7704/=
    input:@40fd2c74504921cd/=
    output:@40fd2c7430f76546/=
    output:@457826cc03a465f4/=
    output:@457826cc510c69e0/=
    end:Join

    node:Bypass
    bretype:::Bypass
    editor:shadow=4578267041681261
    input:@45782010749f0c96/=
    input:@457820124fef7658/=
    output:@40fd2c7436717256/=
    end:Bypass

    node:Sort
    bretype:::Sort
    editor:shadow=4578267075a60d09
    input:@40fd2c743ebf4304/=
    output:@40fd2c746a2a3b47/=
    end:Sort

    end:XRef_2

    node:Do_While_4
    bretype:core::Do While
    editor:sortkey=56d0287458cc4346
    input:@537256b86cbc760c/=XRef_5.457826825d7c2de0
    input:@537256ba68710f32/=XRef_2.457826825d7c2de0
    output:@537256d866506f43/=
    output:@537389af52916f5d/=
    prop:WhileScript=<<EOX
    emit *
    setSuccessReturnCode(101)
    EOX
    editor:XY=1430,660
    node:Bypass
    bretype:::Bypass
    editor:shadow=5418a18062c250fe
    input:@5373907f34d02b95/=
    input:@537390b90a07215c/=
    output:@40fd2c7436717256/=
    end:Bypass

    node:Output_BRD_File
    bretype:::Output BRD File
    editor:shadow=5418a18079a32a59
    input:@40fd2c7476600190/=
    end:Output_BRD_File

    node:BRD_File
    bretype:::BRD File
    editor:shadow=5418a1804a3b7eb6
    output:@40fd2c742cab0bf0/=
    end:BRD_File

    node:Filter_2
    bretype:::Filter
    editor:shadow=5418a180664f1c14
    input:@40fd2c74167f1ca2/=
    output:@40fd2c7420761db6/=
    end:Filter_2

    node:Static_Data
    bretype:::Static Data
    editor:shadow=5418a1800209138c
    output:@40fe6c55598828e5/=
    end:Static_Data

    node:Switch
    bretype:::Switch
    editor:shadow=5418a180494e0bdd
    input:@51645e775c5b5fb1/=
    input:@51645e7c5d73480d/=
    inputattr:@51645e7c5d73480d.type=optional
    output:@51645e802b0d6e53/=
    end:Switch

    node:Agg
    bretype:::Agg
    editor:shadow=5418a18070a07535
    input:@40fd2c7427456e5b/=
    output:@40fd2c744c862db0/=
    end:Agg

    node:Filter
    bretype:::Filter
    editor:shadow=5420671f12257e11
    input:@40fd2c74167f1ca2/=
    output:@40fd2c7420761db6/=
    end:Filter

    end:Do_While_4

    node:Determine_next_loop_3
    bretype:core::Filter
    editor:Label=Determine next loop
    editor:sortkey=56bdf60f1ac70cc5_2
    input:@40fd2c74167f1ca2/=Do_While_4.537389af52916f5d
    output:@40fd2c7420761db6/=
    inclock:/=Append_Excel
    prop:Script=<<EOX

    if lineno == "1" then {lineno = "2"}
    else
    if lineno == "2" then {lineno = "3"}
    else
    lineno = "5"

    override emit lineno.unicode() as lineno

    where firstExec
    EOX
    editor:XY=1530,780
    end:Determine_next_loop_3

    node:States_5
    bretype:core::Static Data
    editor:Label=States
    editor:sortkey=56bdf60f1dd53337_4
    output:@40fe6c55598828e5/=
    prop:StaticData=<<EOX
    lineNo:unicode,State
    2,PT
    3,SE
    EOX
    editor:XY=1530,860
    end:States_5

    node:Append_Excel
    bretype:core::Append Excel
    editor:sortkey=56d029a163d25952
    input:@49e34a5e55c82040/=Do_While_4.537389af52916f5d
    prop:DataAppendMethod=Append
    prop:ExistingDataPreservation=Preserve All
    prop:File=c:\looptext.xls
    editor:XY=1660,670
    end:Append_Excel

    node:XRef_6
    bretype:core::X-Ref
    editor:sortkey=56bdfa280eb42d29_2
    input:@45781ca80c2802d0/=Determine_next_loop_3.40fd2c7420761db6
    input:@45781ca971fe502f/=States_5.40fe6c55598828e5
    output:@45781cad02e051b0/=
    output:@457826825d7c2de0/=
    output:@4578268450ad5d88/=
    prop:LeftInputKey=<<EOX
    lineno
    EOX
    prop:RightInputKey=<<EOX
    lineNo
    EOX
    prop:SortLeftInput=true
    prop:SortRightInput=true
    editor:XY=1680,850
    node:Sort_2
    bretype:::Sort
    editor:shadow=45782670131b71e8
    input:@40fd2c743ebf4304/=
    output:@40fd2c746a2a3b47/=
    end:Sort_2

    node:Bypass_3
    bretype:::Bypass
    editor:shadow=4578267017753cec
    input:@45782010749f0c96/=
    input:@457820124fef7658/=
    output:@40fd2c7436717256/=
    end:Bypass_3

    node:Join
    bretype:::Join
    editor:shadow=457826701862249e
    input:@40fd2c745b6d7704/=
    input:@40fd2c74504921cd/=
    output:@40fd2c7430f76546/=
    output:@457826cc03a465f4/=
    output:@457826cc510c69e0/=
    end:Join

    node:Bypass
    bretype:::Bypass
    editor:shadow=4578267041681261
    input:@45782010749f0c96/=
    input:@457820124fef7658/=
    output:@40fd2c7436717256/=
    end:Bypass

    node:Sort
    bretype:::Sort
    editor:shadow=4578267075a60d09
    input:@40fd2c743ebf4304/=
    output:@40fd2c746a2a3b47/=
    end:Sort

    end:XRef_6


  • 2.  RE: Do while loop

    Employee
    Posted 02-26-2016 04:49

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

    Originally posted by: simon.wilby

    Hi,

    have you reviewed the IterationExample.brg shipped with LAE? this example covers various different ways that the looping functionality can be used.

    You should find the IterationExample.brg in your Public documents/ Lavastorm BRAIN/Examples folder.

    Hope that helps

    Simon


  • 3.  RE: Do while loop

    Employee
    Posted 02-26-2016 08:02

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

    Originally posted by: ryeh

    The problem is in the 'Determine Next Loop' filter. You set the variable 'lineno' to the next value. But that's the same name as the field. So just creating a temp variable '_lineno' and then emitting that as 'lineno' fixes the problem.
    Attachments:
    loopExample.brg


  • 4.  RE: Do while loop

    Employee
    Posted 02-26-2016 10:17

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

    Originally posted by: dhrobertson

    Originally posted by: ryeh
    					

    The problem is in the 'Determine Next Loop' filter. You set the variable 'lineno' to the next value. But that's the same name as the field. So just creating a temp variable '_lineno' and then emitting that as 'lineno' fixes the problem.
    Knew I was being stupid... just couldn't see it! thank you!

    doug


  • 5.  RE: Do while loop

    Employee
    Posted 02-26-2016 10:36

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

    Originally posted by: dhrobertson

    Originally posted by: ryeh
    					

    The problem is in the 'Determine Next Loop' filter. You set the variable 'lineno' to the next value. But that's the same name as the field. So just creating a temp variable '_lineno' and then emitting that as 'lineno' fixes the problem.
    out of interest, I notice that you use the function CONSUME... I tried to understand the help file with regards this command but struggled to understand it.... can you let me know what it does exactly? I'm assuming it is forfilling the role of the firstexec command? but how is it working exactly?

    thanks

    Doug


  • 6.  RE: Do while loop

    Employee
    Posted 02-26-2016 10:45

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

    Originally posted by: ryeh

    So in your case, it doesn't matter that much, since you only have 10 records coming in, and each iteration happens really quick. But say you had 1M records coming in, and the logic in the filter takes 1 second (I'm being dramatic here). Then what would happen is that you would actually have to wait 1M seconds for the filter to run even though you only care about the first record. Use CONSUME to basically discards all the remainder of the records. So after you process the first record, you throw away the remainder of the input and move on. Check out the example that my colleague, Josh Belliveau, created to illustrate the difference.
    Attachments:
    ConsumeFunction.brg


  • 7.  RE: Do while loop

    Employee
    Posted 02-26-2016 10:53

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

    Originally posted by: dhrobertson

    ah I see. thank you for the explanation !


  • 8.  RE: Do while loop

    Employee
    Posted 02-26-2016 10:54

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

    Originally posted by: stonysmith

    I want to add one point of clarity.. CONSUME causes the node to stop processing the input. It doesn't "skip over" the records, it stops reading of any more input records.

    Imagine this:
    c=count()
    emit *
    where c<100
    In this case, all input records (potentially millions) are read - taking a lot of CPU time, I/O processing, etc. even though the output is only 99 records.

    But..
    c=count()
    emit *
    if c>99 then consume(1,true)
    will cause the node to read the first 99 records and then stop processing, potentially saving you significant amounts of time.

    It can also be written this way for brevity.
    c=count()
    emit *
    consume(1,c>99)
    As soon as C is greater than 99, it will stop.


  • 9.  RE: Do while loop

    Employee
    Posted 07-13-2016 04:06

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

    Originally posted by: samsons

    hen what would happen is that you would actually have to wait 1M seconds for the filter to run even though