GROUPfunc.ecl 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // Example code - use without restriction.
  3. //
  4. IMPORT $;
  5. accounts := $.DeclareData.Accounts;
  6. rec := RECORD
  7. accounts.PersonID;
  8. accounts.Account;
  9. accounts.opendate;
  10. accounts.balance;
  11. UNSIGNED1 Ranking := 0;
  12. END;
  13. tbl := TABLE(accounts,rec);
  14. rec RankGrpAccts(rec L, rec R) := TRANSFORM
  15. SELF.Ranking := L.Ranking + 1;
  16. SELF := R;
  17. END;
  18. GrpRecs := SORT(GROUP(SORT(tbl,PersonID),PersonID),-Opendate,-Balance);
  19. i1 := ITERATE(GrpRecs,RankGrpAccts(LEFT,RIGHT));
  20. OUTPUT(i1);
  21. rec RankSrtAccts(rec L, rec R) := TRANSFORM
  22. SELF.Ranking := IF(L.PersonID = R.PersonID,L.Ranking + 1, 1);
  23. SELF := R;
  24. END;
  25. SortRecs := SORT(tbl,PersonID,-Opendate,-Balance);
  26. i2 := ITERATE(SortRecs,RankSrtAccts(LEFT,RIGHT));
  27. OUTPUT(i2);
  28. //*********************************************************
  29. // create a reasonably large dataset
  30. bf := NORMALIZE(accounts,
  31. CLUSTERSIZE * 2,
  32. TRANSFORM(RECORDOF(accounts),SELF := LEFT));
  33. // that's randomly distributed and persisted
  34. ds0 := DISTRIBUTE(bf,RANDOM())
  35. : PERSIST('~$.DeclareData::PERSIST::TestGroupSort');
  36. ds1 := DISTRIBUTE(ds0,HASH32(personid));
  37. // do a global sort
  38. s1 := SORT(ds0,personid,opendate,-balance);
  39. a := OUTPUT(s1,,'~$.DeclareData::EXAMPLEDATA::TestGroupSort1',OVERWRITE);
  40. // do a distributed local sort
  41. s3 := SORT(ds1,personid,opendate,-balance,LOCAL);
  42. b := OUTPUT(s3,,'~$.DeclareData::EXAMPLEDATA::TestGroupSort2',OVERWRITE);
  43. // do a grouped local sort
  44. s4 := SORT(ds1,personid,LOCAL);
  45. g2 := GROUP(s4,personid,LOCAL);
  46. s5 := SORT(g2,opendate,-balance);
  47. c := OUTPUT(s5,,'~$.DeclareData::EXAMPLEDATA::TestGroupSort3',OVERWRITE);
  48. SEQUENTIAL(a,b,c);
  49. /**/