ADF, dataflow - sort in expression language

MasTidar 41 Reputation points
2022-05-05T03:42:59.503+00:00

I have an input string that was delimited by white space. In the expression builder I try using expression language to split it. Splitting works fine as array output [] but issues come out when input string is not a sequence number (red box). So, I need to sort the array value but I don't know how to use it.

The ideal condition is

1 2 3 4
1 3 4
1 4
2 4
4

but sometimes input string is not sequential number.

1 4 2
1 2 4 3
3 4 1 2
anyone can help me how to use sort the array value ?
What am I confuse is

Sort expects a reference to two consecutive elements in the expression function as #item1 and #item2.

What I expect the output looks like these below:

input | output
1 4 2 | 1 2 4
1 2 4 3 | 1 2 3 4
3 4 1 2 | 1 2 3 4

anyone can give an example for me ?

199026-sort.jpg

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,623 questions
0 comments No comments
{count} votes

Accepted answer
  1. KranthiPakala-MSFT 46,642 Reputation points Microsoft Employee Moderator
    2022-05-06T23:34:02.477+00:00

    Hello @MasTidar ,

    Thanks for the question and using MS Q&A platform.

    Requirement:
    What I expect the output looks like these below:
    input | output
    1 4 2 | 1 2 4
    1 2 4 3 | 1 2 3 4
    3 4 1 2 | 1 2 3 4

    In order to achieve the above requirement, you can use below expression in your expression builder. This expression does split your input into an array and then sort the order and then replace the unwanted characters as needed.

    replace((replace((replace((toString(sort(split(input, ' '), compare(#item1, #item2)))), '","', ' ')),'["','')),'"]','')   -> Please note that `input` is the source column name in this sample  
    

    Below is the output for the expression:

    199817-image.png

    Hope this will help. Let us know if any further queries.

    ------------------------------

    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
    • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.