Skip to Content
author's profile photo Former Member
Former Member

One line transform to multiple Nodes in UDF

Hi,

I have a problem about UDF. Using fixed length,4, to split the source string and write them into one table with many rows.

LIKE THIS:

Source

<record>

<details>

TESTSTRING

</details>

</record>

Target

<result>

<name>1</name>

<data>1</data>

<status>1</status>

</result>

<result>

<name>2</name>

<data>2</data>

<status>2</status>

</result>

<result>

<name>3</name>

<data>3</data>

<status>3</status>

</result>

I create a UDF, for example, var1 is the length of the source string.

public void calculate2(int[] var1, ResultList title, ResultList name, ResultList result, ResultList status, Container container) throws StreamTransformationException{

int i = var1[0]+1;

for (int i2 = 1; i2 < i; i2++)

{

title.addValue(i2);

name.addValue(i2);

result.addValue(i2);

status.addValue(i2);

}

}

UDF:

Mapping:

Test result :

<result1> <name>1</name> <name>2</name> <name>3</name> <result>1</result> <result>2</result> <result>3</result> <status>1</status> <status>2</status> <status>3</status> </result1> <result1/> <result1/>

Test Result

Do you have any good ideas?

Thanks a lot!

Regards,

Lily

ESR TEST RESULT.jpg (103.9 kB)
ESR UFD.jpg (64.8 kB)
ESR Mapping.jpg (114.5 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Jul 28, 2016 at 06:41 AM

    Change your UDF by adding a context Change to the name , result and status node as shown in bold below.

    int i = var1[0]+1;

    for (int i2 = 1; i2 < i; i2++)

    {

    title.addValue(i2);

    name.addValue(i2);

    name.addContextChange();

    result.addValue(i2);

    result.addContextChange();

    status.addValue(i2);

    status.addContextChange();

    }

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.