Tue Aug 16, 2022 10:20 pm
Login Register Lost Password? Contact Us

Please Note: The HPCC Systems forums are moving to Stack Overflow. We invite you to post your questions on Stack Overflow utilizing the tag hpcc-ecl (https://stackoverflow.com/search?tab=newest&q=hpcc-ecl). This legacy forum will be active and monitored during our transition to Stack Overflow but will become read only beginning September 1, 2022.

Sort on Enumvalues rather than data.

Questions around writing code and queries

Wed Apr 21, 2021 9:01 am Change Time Zone

Hi ALL ,
In case have to sort on enum values rather the column values as need is in specific order
and which has to be consistent and in control rather to be dependent on data.
Is there a way to sort

MyRec := {STRING3 Value1,STRING3 Category1, STRING3 Category2};
SomeFile := DATASET([{'NVS','T','ABC'},{'NVS','C','ABC'},{'A','X','BAC'},

srtvalues := enum(unsigned1,AAA, ABC, BAC,AAC,PQR);
//need to sort on values of 3rd field which is static but can add latter
Srtd_values_ds := sort(SomeFile,srtvalues.AAA);
Posts: 29
Joined: Fri Feb 23, 2018 8:30 am

Mon Jun 21, 2021 9:29 am Change Time Zone

You need a mapping between your codes and a sort order.
This can be achieved using a lookup, e.g. DICTIONARY.
Something like this:
Code: Select all
MyRec := {STRING3 Value1,STRING3 Category1, STRING3 Category2};
SomeFile := DATASET([{'NVS','T','ABC'}

SortOrder := DATASET([{'AAA',1},{'ABC',2},{'BAC',3},{'AAC',4},{'PQR',5}],{STRING Code,UNSIGNED1 SortOrder});

Dict      := DICTIONARY(SortOrder,{Code => SortOrder});

Srtd_values_ds := sort(SomeFile,Dict[Category2].SortOrder);

Does this fit your needs?
Posts: 444
Joined: Sat Oct 01, 2011 7:26 pm

Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest