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

Split a List

  • 1.  Split a List

    Employee
    Posted 03-07-2013 09:48

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

    Originally posted by: zon

    Hi,

    I've a issue.
    I have a list, which I split using comma (,). Nevertheless, there are some fields, between "blades", and inside of those fields I have a comma.
    The split is not going well, when I have those kind of fields.
    Example:
    Here are two records:

    "210006544","7","2013/02/04-22-05-58.00",,"EUR",,,,,,,,"73721","238313003","21000654 4","TVC-210006544","214261046","D099214261046","0000001778 ",,"TVCABO",,,,,,,,,,,,,,,"1-60B5OKS"
    "210006544","7","2013/02/04-22-36-08.00",,"EUR",,,,,,,,"74067","238313003","21000654 4","TVC-210006544","239991312","239991312","0000000239",," PT - COMUNICA��ES, S.A.",,,,,,,,,,,,,,,"1-60B5OKS"

    The second record is the one that goes wrong, because of the field that says "PT - COMUNICA��ES, S.A.", due to the comma inside.
    How can I tell not to consider comma, if it is inside blades?
    I'm doing this with a filter node, with this code:
    +++++++++++++++++
    DataList = DATA.substr(8).split(",")
    EVENT_START_DATETIME = DataList.getItem(2).replace("\"", "")
    .
    .
    .
    +++++++++++++++++

    Regards,
    ZON


  • 2.  RE: Split a List

    Employee
    Posted 03-07-2013 11:28

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

    Originally posted by: ltolleson

    This is probably not the most elegant solution, but it works. I was trying to use RegEx to parse the string, but could never get that to work

    #Normalize delimiter to ","
    tempData = 'Data'.replace(",,",",\"\",").replace(",,",",\"\", ")

    #Remove " character from first and last character in string
    tempData = tempData.substr(1,tempData.strlen() - 2)

    #Split data by delimiter ","
    tempData = tempData.split("\",\"")

    emit *, tempData.str() as tempData


  • 3.  RE: Split a List

    Employee
    Posted 03-07-2013 11:53

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

    Originally posted by: zon

    Uau! I'll try...

    But, can I use Delimited node? I tried, but is turning error. The error is:

    ++++++++++++++++++++++++++++++++++++++++
    ERROR processing data:
    ::CreateFile() returned 123: '"210006544","7","2013/02/01-18-34-37.00",,"EUR",,,,,,,,"17442","238313003","21000654 4","TVC-210006544","214261046","D099214261046","0000001323 ",,"TVCABO",,,,,,,,,,,,,,,"1-60B5OKS"'

    Installing log (03/07/2013 16:55:22) ...
    2013-03-07 16:55:23; Level: 2; Type: 0; Desc: "::CreateFile() returned 123: '"210006544","7","2013/02/01-18-34-37.00",,"EUR",,,,,,,,"17442","238313003","21000654 4","TVC-210006544","214261046","D099214261046","0000001323 ",,"TVCABO",,,,,,,,,,,,,,,"1-60B5OKS"'"; File: ".\Io\JFile.cpp"; Line: 228; Context: "JFile::NativeOpen()"
    2013-03-07 16:55:23; Level: 2; Type: 0; Desc: "...exception seen"; File: ".\Io\JFile.cpp"; Line: 231; Context: "JFile::NativeOpen()"
    Uninstalling log (03/07/2013 16:55:23) ...
    +++++++++++++++++++++++++++++++++++++++++++

    These are the records sample that I'm trying do delimited:
    DATA
    "210006544","7","2013/02/01-18-34-37.00",,"EUR",,,,,,,,"17442","238313003","21000654 4","TVC-210006544","214261046","D099214261046","0000001323 ",,"TVCABO",,,,,,,,,,,,,,,"1-60B5OKS"
    "210006544","7","2013/02/01-19-03-24.00",,"EUR",,,,,,,,"18262","238313003","21000654 4","TVC-210006544","214261046","D099214261046","0000000703 ",,"TVCABO",,,,,,,,,,,,,,,"1-60B5OKS"
    "210006544","7","2013/02/02-12-20-46.00",,"EUR",,,,,,,,"26865","238313003","21000654 4","TVC-210006544","213835800","D091213835800","0000000125 ",,"VODAFONE PORTUGAL - Comunica��es Pessoais SA",,,,,,,,,,,,,,,"1-60B5OKS"
    "210006544","7","2013/02/02-12-23-44.00",,"EUR",,,,,,,,"26918","238313003","21000654 4","TVC-210006544","213835800","D091213835800","0000000059 ",,"VODAFONE PORTUGAL - Comunica��es Pessoais SA",,,,,,,,,,,,,,,"1-60B5OKS"
    "210006544","7","2013/02/02-13-54-49.00",,"EUR",,,,,,,,"28596","238313003","21000654 4","TVC-210006544","214261046","D099214261046","0000000643 ",,"TVCABO",,,,,,,,,,,,,,,"1-60B5OKS"
    "210006544","7","2013/02/04-22-05-58.00",,"EUR",,,,,,,,"73721","238313003","21000654 4","TVC-210006544","214261046","D099214261046","0000001778 ",,"TVCABO",,,,,,,,,,,,,,,"1-60B5OKS"
    "210006544","7","2013/02/04-22-36-08.00",,"EUR",,,,,,,,"74067","238313003","21000654 4","TVC-210006544","239991312","239991312","0000000239",," PT - COMUNICA��ES, S.A.",,,,,,,,,,,,,,,"1-60B5OKS"
    "210006544","7","2013/02/05-21-22-59.00",,"EUR",,,,,,,,"97047","238313003","21000654 4","TVC-210006544","214261046","D099214261046","0000000706 ",,"TVCABO",,,,,,,,,,,,,,,"1-60B5OKS"
    "210006560","7","2013/02/01-19-03-22.00",,"EUR",,,,,,,,"18261","823712823","21000656 0","TVC-210006560","210400400","210400400","0000000121",," PT PRIME - Solu��es Empresariais de Telecomunica��es e Sistemas SA",,,,,,,,,,,,,,,"1-5XY6VWJ"


    Can you help?
    Node configuration is:
    Field Delimiter - ,
    Record Delimiter - \n
    Field Names - XXX, XXX, XXX (is not important)
    QuoteCharacters - "

    Regards,
    ZON


  • 4.  RE: Split a List

    Employee
    Posted 03-07-2013 12:22

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

    Originally posted by: ltolleson

    Use the CSV File node. It should read this file with the default configuration.


  • 5.  RE: Split a List

    Employee
    Posted 03-08-2013 02:54

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

    Originally posted by: zon

    It's giving me the same error... :-(


  • 6.  RE: Split a List

    Employee
    Posted 03-08-2013 09:36

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

    Originally posted by: ltolleson

    What version of LAE are you using?

    Here is what I did that works for me.

    I copied your data from above, including the header row "DATA" and pasted it into a flat file. You do not need to do this since you already have your data in a file.

    I used the CSV File node to input the file and added the following 36 fields to the FieldNames parameter. This will override the header and make this list of field names the header for the data. This will read in the "DATA" header as the first row of data, so you will need to remove it with a filter node.

    field1,field2,field3,field4,field5,field6,field7,f ield8,field9,field10,field11,field12,field13,field 14,field15,field16,field17,field18,field19,field20 ,field21,field22,field23,field24,field25,field26,f ield27,field28,field29,field30,field31,field32,fie ld33,field34,field35,field36

    Let me know if you are still having issues after trying this.

    Thanks,
    Larry


  • 7.  RE: Split a List

    Employee
    Posted 03-08-2013 10:00

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

    Originally posted by: zon

    Version 4.5.1.0 Build 318

    I did like you said...still giving the error.
    I attached some images that might help.

    Cheers,
    ZON
    Attachments:
    Split.zip


  • 8.  RE: Split a List

    Employee
    Posted 03-08-2013 11:13

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

    Originally posted by: ltolleson

    Ok, I misunderstood what you are doing. I thought you were reading the data in from a file, but you already have the read into BRE. In that case use the filter node in the attached graph to parse the data. It creates a list, which you can then use to pull out each individual data field. I coded a few examples in the emit statement.

    Thanks,
    Larry
    Attachments:
    ParseCommaData.brg


  • 9.  RE: Split a List

    Employee
    Posted 03-11-2013 04:29

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

    Originally posted by: zon

    Hi,

    I managed to make your idea work! Thanks a lot.

    Nevertheless, I have another issue: there might be some CDRs, were last field (35) is empty...in those cases, it's returning error, saying: index out of bounds.
    How can I work around this?

    Cheers,
    ZON


  • 10.  RE: Split a List

    Employee
    Posted 03-11-2013 06:58

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

    Originally posted by: mmarinelli

    If you change your output statements from the form:

    emit tempData2[35] as field35

    to this form:

    emit str(tempData2[35]) unless tempData2.len() < 36 then str(null) as field35

    you can avoid the index out of bounds error you're getting. This new code checks to see if there is actually a value at tempData[index] before attempting to evaluate it. You can optimize this by setting a variable to the tempData2.len() return value and using that variable instead of executing the operator at each emit.


  • 11.  RE: Split a List

    Employee
    Posted 03-11-2013 07:28

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

    Originally posted by: zon

    Perfect! It worked...

    Thanks a lot!
    Problem solved!

    Cheers,
    ZON