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

SORT in PI

Hi XI Gurus,

I have a problem regarding sorting again. Is there any way I can use sort but the characters after an "_" will not be part of the sorting?

EX.

test_1.0

variable_5.5

test_0.5

variable_0.1

expected output should be

test_1.0

test_0.5

variable_5.5

variable_0.1

what's happening in my mapping is

test_0.5

test_1.0

variable_0.1

variable_5.5

w/c is very wrong when mapped to the target fields.

I tried using substring first before I sort but I get this

test_1.0

test_5.5

variable_0.5

variable_0.1

please help. much appreciated. thanks!

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    Posted on May 26, 2011 at 05:59 AM

    Hi ,

    try doing this using UDF.

    Regards,

    Sheetal

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 26, 2011 at 06:22 AM

    HI,

    I think if you are getting values as

    test_1.0

    variable_5.5

    test_0.5

    variable_0.1

    then use standard function Sort which is available in mapping.

    Functions > Node Functions > Sort

    double click sort function and select (Case sensitive and ascending)

    and it will give output as

    test_1.0

    test_0.5

    variable_5.5

    variable_0.1

    No need to use substring and other logic.

    In mapping just use standard function Sort as following

    Source field > sort > Target field

    Thanks,

    Bhupesh

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 26, 2011 at 07:22 AM

    I asked a JAVA expert to create a UDF. thanks!

    Add a comment
    10|10000 characters needed characters exceeded

    • You can use this.

      for (int i = 0; i < var1.length; i++) {

      for (int j = i + 1; j < var1.length; j++) {

      if ((var1[j]).compareTo(var1<i>) < 0) {

      String temp = var1<i>;

      var1<i> = var1[j];

      var1[j] = temp;

      }

      }

      }

      return var1;

      }

      +++++++++++++++++++++++

      May be your java expert can use this.

      Edited by: Pothana Yadav on May 26, 2011 12:40 PM

  • author's profile photo Former Member
    Former Member
    Posted on May 26, 2011 at 06:39 AM

    hi,

    use the SORT function to sort the values and then use a UDF function to change to order of the sub-text.

    i really don't see any other way

    regards.

    roi grosfeld

    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.