Sun Aug 07, 2022 3:24 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.



Combining rows

Comments and questions related to the Enterprise Control Language

Thu Apr 18, 2019 3:23 pm Change Time Zone

Hi,

Let's consider we have

Code: Select all
EXPORT layout := RECORD
    INTEGER id;
    INTEGER value1;
    INTEGER value2;
END;


How to convert this:

Code: Select all
id value1 value2
1   10      5
1   20      0
2    5     10
2    5      0
2    0     15


to:

Code: Select all
id value1 value2
1   30      5
2   10     25


Best,
vzeufack
 
Posts: 41
Joined: Tue Sep 25, 2018 3:52 pm

Thu Apr 18, 2019 3:36 pm Change Time Zone

vzeufack,

Either the TABLE or ROLLUP functions (both covered in the Intro to ECL Part 2 class) will do that:
Code: Select all
layout := RECORD
  INTEGER id;
  INTEGER value1;
  INTEGER value2;
END;
ds := DATASET([ {1,   10,      5},
                {1,   20,      0},
                {2,    5,     10},
                {2,    5,      0},
                {2,    0,     15}
              ],layout);
ROLLUP(ds,LEFT.id=RIGHT.id,
       TRANSFORM(layout,
                 SELF.value1 := LEFT.value1 + RIGHT.value1,
                 SELF.value2 := LEFT.value2 + RIGHT.value2,
                 SELF := LEFT));
TABLE(ds,
      {id,
       INTEGER value1 := SUM(GROUP,ds.value1),
       INTEGER value2 := SUM(GROUP,ds.value2)},
      id);

HTH,

Richard
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1619
Joined: Wed Oct 26, 2011 7:40 pm

Thu Apr 18, 2019 6:36 pm Change Time Zone

Thanks very much Richard!
vzeufack
 
Posts: 41
Joined: Tue Sep 25, 2018 3:52 pm

Fri May 03, 2019 10:55 am Change Time Zone

Hi,

There are now YouTube Videos on ROLLUP:
https://www.youtube.com/watch?v=LE5HDegz5II&t=65s
https://www.youtube.com/watch?v=E-R138uuR3M

These might help.
Allan
Allan
 
Posts: 444
Joined: Sat Oct 01, 2011 7:26 pm


Return to ECL

Who is online

Users browsing this forum: No registered users and 1 guest

cron