Customer Portal

How do I read boolean in camel case and date w milliseconds

Comments 4

  • Avatar
    avackova
    0
    Comment actions Permalink
    Hello,
    Universal Data Reader can't handle such data. You need to read them as strings and convert to proper type in Reformat node:
    <?xml version="1.0" encoding="UTF-8"?>
    <Graph id="1281700646917" >
    <Global>
    <Metadata id="Metadata1" >
    <Record fieldDelimiter="|" name="data_types" recordDelimiter="\n" type="delimited">
    <Field format="yyyy-MM-dd HH:mm:ss.S" name="date_data" type="date"/>
    <Field name="boolean_data" type="boolean"/>
    </Record>
    </Metadata>
    <Metadata id="Metadata0">
    <Record fieldDelimiter="|" name="data_types_as_string" recordDelimiter="\n" type="delimited">
    <Field name="date_data" type="string"/>
    <Field name="boolean_data" type="string"/>
    </Record>
    </Metadata>
    <Property fileURL="workspace.prm" id="GraphParameter0"/>
    </Global>
    <Phase number="0">
    <Node fileURL="${DATAIN_DIR}/data.txt" id="DATA_READER0" type="DATA_READER"/>
    <Node id="REFORMAT0" type="REFORMAT">
    <attr name="transform"><![CDATA[//#TL

    // Transforms input record into output record.
    function transform() {
    $0.boolean_data := iif($boolean_data == "True", true, false);
    $0.date_data := str2date(substring($date_data,0,22),"yyyy-MM-dd HH:mm:ss.S");
    }

    // Called to return a user-defined error message when an error occurs.
    // function getMessage() {}

    // Called during component initialization.
    // function init() {}

    // Called after the component finishes.
    // function finished() {}
    ]]></attr>
    </Node>
    <Node debugPrint="true" id="TRASH0" type="TRASH"/>
    <Edge fromNode="DATA_READER0:0" guiBendpoints="" id="Edge0" inPort="Port 0 (in)" metadata="Metadata0" outPort="Port 0 (output)" toNode="REFORMAT0:0"/>
    <Edge fromNode="REFORMAT0:0" guiBendpoints="" id="Edge1" inPort="Port 0 (in)" metadata="Metadata1" outPort="Port 0 (out)" toNode="TRASH0:0"/>
    </Phase>
    </Graph>
  • Avatar
    crrb
    0
    Comment actions Permalink
    That was the approach I had settled on for the booleans. The source supplied milliseconds, but we really aren't interested in that value and as a result I discovered that a format of 'yyyy-MM-dd HH:mm:ss' or 'yyyy-MM-dd' can still read those fields in as date, it just truncates off the extraneous information.

    Thank you for getting a complete solution back to me. My apologies for the dup on the boolean question - I didn't realize that the first post actually went through.

    Thank you Agata,

    crrb
  • Avatar
    zram_k
    0
    Comment actions Permalink
    Good and helpful information. I have a similar scenario, but my date is coming in as "MM/dd/yyyy" and I can't seem to find a function that can read/transform this.

    I appreciate any help.
    Thank you
  • Avatar
    imriskal
    0
    Comment actions Permalink
    Hi, Zram_K,

    You can read such data either as date directly (Set metadata field to date and fill MM/dd/yyyy into field format property in this case.) or as string which can be retyped with str2date($in.0.input_date,"MM/dd/yyyy") function in CTL (Here will be two kinds of metadata - the first one with string type field and the second one with date type field again with format set to MM/dd/yyyy).

    Best regards,

Please sign in to leave a comment.