Data360 Analyze

 View Only
  • 1.  Conditionally write output to out1 or out2

    Posted 06-16-2021 08:16

    Hi

    I can't seem to get my data to write to out2 in the transform node. I've mocked up this simple example below to recreate the problem.

    Input Data below (that is connected to a Transform node)

    InputFileName, OutputLocation,TradeId, LEI, TradeDate, Notional, BuySellFlag, TotalQuantity, Price_SRC, Price_TGT, Output1, Output2, Output3
    PTS1,"FIRST", 001, ,22-01-2021, 100, B,4,101.4555,101.5,,,
    PTS1,"FIRST", 002,ABC,29-04-2021,3, X,,5,102.111,102.111,,
    PTS1,"SECOND",003,DEF,29-04-2021,5, X,,6,103.678,103.69,,
    PTS1,"SECOND", 004,XYZ,22-01-2021, 200, B,7,104,104.56,,,

    Inside the Transform node I have this code

    ConfigureFields:

    out1 += in1
    out2 += in1

    ProcessRecords:

    #Define an OutputData Function to output the data depending on the condition
    def OutputData(OutputFlag, OutHandle):
    if OutputFlag == "FIRST":
        out1 = OutHandle
        out1 +=in1
        node.write(0,out1)
    elif OutputFlag == "SECOND":
        out2 = OutHandle
        out2 +=in1
        node.write(0,out2)

    if in1.OutputLocation == "FIRST":
        OutputData("FIRST", out1)
    else:
        OutputData("SECOND", out2)

    After the transform runs all are written to out1 and none are written to out2.

    Please can you advise where I am going wrong here? why did none of them get written to out2?

    much appreciated!

    Scott



  • 2.  RE: Conditionally write output to out1 or out2

    Posted 06-16-2021 08:21

    ah okay it seems if I comment out the node.write lines it works fine. When would one actually need to use node.write?



  • 3.  RE: Conditionally write output to out1 or out2

    Employee
    Posted 06-16-2021 09:20

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

    Under Optional if you set the property ImplicitWriteMode to Never, then it would never output a row of data without you explicitly calling it, which you would do with node.write.

    Another common case would be if you had a list you wanted to expand out to have one row for each item in the list, you would need to use node.write(0,out1).

    In the case above, to write to out2 pin by explicitly calling it, you would use node.write(1,out2).



  • 4.  RE: Conditionally write output to out1 or out2

    Employee
    Posted 06-16-2021 09:21

    You can also use node.write() to write to an output based on it's index value instead of it's name. This is useful when creating custom library nodes as it allows the output pin to be renamed on an instance of the custom library node without breaking the code in the node. 

    Please see the API script binding section of the node help

    https://d3sa-preview.infogixsaas.com/docs/dist/help/Content/f-script/python/python-api.htm#Node

     

     

    Attached files

    node.write_using_Index.png

     



  • 5.  RE: Conditionally write output to out1 or out2

    Posted 06-17-2021 03:38

    thanks both for the detail explain, was very useful!