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.  Text to Columns ouput

    Employee
    Posted 03-09-2017 16:04

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

    Originally posted by: Buddha

    Hi All, I'm trying to split out an address by space into separate columns but I'm not having much luck with the output part. Ideally I'd like to have it as fairly dynamic as the number of columns needed can change.

    need to change
    00 smith st Melbourne Vic 3000

    into

    c1 c2 c3 c4 c5 c6
    00 Smith st Melbourne Vic 3000

    Thanks
    Buddha


  • 2.  RE: Text to Columns ouput

    Employee
    Posted 03-10-2017 04:35

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

    Originally posted by: jmok

    Hi Buddha,

    Thanks for putting your question on here. To split your address string by a space, you'll want to use the 'split' and 'getItem' functions within a Filter node, to get the result you've specified.

    Please copy and paste the below onto your Lavastorm canvas:

    ------------------------

    node:Split_and_getItem
    bretype:core::Filter
    editor:Label=Split and getItem
    editor:sortkey=58c28d967ab669b9
    input:@40fd2c74167f1ca2/=Static_Data.40fe6c55598828e5
    output:@40fd2c7420761db6/=
    prop:Script=<<EOX
    # Split the string into a list of parts and using the getItem function to specify
    # which element (part) you would like. 0 always being the first part on the left

    c1 = 'Data'.split(" ").getItem(0)
    c2 = 'Data'.split(" ").getItem(1)
    c3 = 'Data'.split(" ").getItem(2)
    c4 = 'Data'.split(" ").getItem(3)
    c5 = 'Data'.split(" ").getItem(4)
    c6 = 'Data'.split(" ").getItem(5)

    # emit all variables to view in the ouput

    emit *,c1,c2,c3,c4,c5,c6

    EOX
    editor:XY=210,80
    end:Split_and_getItem

    node:Static_Data
    bretype:core::Static Data
    editor:sortkey=58c28d59334d1966
    output:@40fe6c55598828e5/=
    prop:StaticData=<<EOX
    Data:string
    00 smith st Melbourne Vic 3000
    EOX
    editor:XY=100,80
    end:Static_Data

    ------------------------

    Hope that works and if you have any questions, let us know


  • 3.  RE: Text to Columns ouput

    Employee
    Posted 03-10-2017 05:26

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

    Originally posted by: awilliams1024

    To build on Janice's example, if you know the maximum number of elements you will get in the data you could use the following to handle a variable number of elements:

    node:Split_and_getItem
    bretype:core::Filter
    editor:Label=Split and getItem
    editor:sortkey=58c28d967ab669b9
    input:@40fd2c74167f1ca2/=Static_Data.40fe6c55598828e5
    output:@40fd2c7420761db6/=
    prop:Script=<<EOX
    # Split the string into a list of parts and using the getItem function to specify # which element (part) you would like. 0 always being the first part on the left
    
    Splits = 'Data'.split(" ")
    
    c1 = if(len(Splits) >0) then Splits.getItem(0) else str(null)
    c2 = if(len(Splits) >1) then Splits.getItem(1) else str(null)
    c3 = if(len(Splits) >2) then Splits.getItem(2) else str(null)
    c4 = if(len(Splits) >3) then Splits.getItem(3) else str(null)
    c5 = if(len(Splits) >4) then Splits.getItem(4) else str(null)
    c6 = if(len(Splits) >5) then Splits.getItem(5) else str(null)
    
    # emit all variables to view in the ouput
    
    emit *,c1,c2,c3,c4,c5,c6
    
    
    EOX
    editor:XY=210,80
    end:Split_and_getItem
    
    node:Static_Data
    bretype:core::Static Data
    editor:sortkey=58c28d59334d1966
    output:@40fe6c55598828e5/=
    prop:StaticData=<<EOX
    Data:string
    00 smith st Melbourne Vic 3000
    01 Jones st Melbourne Vic
    02 Harris Rd Melbourne Vic 2000
    EOX
    editor:XY=100,80
    end:Static_Data


  • 4.  RE: Text to Columns ouput

    Employee
    Posted 03-13-2017 15:12

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

    Originally posted by: Buddha

    Thanks heaps guys, I had the split part but not the getItem part.

    if I don't know the maximum number of splits is there a way to set it up as a loop or something?


  • 5.  RE: Text to Columns ouput

    Employee
    Posted 03-14-2017 04:49

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

    Originally posted by: awilliams1024

    I'm not sure there is a way to do that. The problem would be with the emit statement:

    emit *,c1,c2,c3,c4,c5,c6

    You cannot use a the value of a variable as a field name within an emit statement. Also, the number of fields within an output record must be the same for all records. As the number of fields in the first record may not be the same as in subsequent records you would not be able to increase the number of output fields in the later records.

    Regards,
    Adrian


  • 6.  RE: Text to Columns ouput

    Employee
    Posted 03-14-2017 15:09

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

    Originally posted by: Buddha

    Thanks Adrian,

    The emits was the issue I was coming up against. thanks for confirming this for me (unfortunately)

    Buddha


  • 7.  RE: Text to Columns ouput

    Employee
    Posted 03-16-2017 14:34

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

    Originally posted by: prasmussen

    Buddha,

    If you really need a dynamic delimiter node with an unknown number of columns you can use the attached node. It's a custom java node so not an out of the box supported node; however, it'll get you what you need and you can customize as necessary.
    Attachments:
    DynamicDelimiter.txt