Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /* Transformation - There is really no SQL Equivalent here.*/
  2.  
  3. //Project
  4. //Here you are saying transform one record set to another by
  5. //applying a transformation on each record
  6. Product clean(Product inrec) := TRANSFORM
  7. SELF.productName := Std.Str.ToUpperCase(inrec.productName);
  8. SELF := inrec;
  9. END;
  10.  
  11. upperProducts := PROJECT(products, clean(LEFT));
  12.  
  13. OUTPUT(upperProducts);
  14.  
  15. //Iterate
  16. //Here you are saying transform one record set to another by
  17. //applying a transformation on a pair of records at a time
  18. Product doCompute(Product l, Product r) := TRANSFORM
  19. SELF.quantityInStock := IF(l.productVendor=r.productVendor,
  20. l.quantityInStock + r.quantityInStock, 0);
  21. SELF.productVendor := R.productVendor;
  22. SELF := l;
  23. END;
  24.  
  25. productsByVendorDS := SORT(products, productVendor);
  26. vendorQtyDS := ITERATE(productsByVendorDS, doCompute(LEFT, RIGHT));
  27.  
  28.  
  29. OUTPUT(vendorQtyDS);
  30.  
  31. //ROLLUP
  32. //Here you are saying transform one record set to another by
  33. //deduping and transforming the matching records during the
  34. //dedup process
  35. Product doRollup(Product l, Product r) := TRANSFORM
  36. SELF.quantityInStock := IF(l.quantityInStock > r.quantityInStock,
  37. l.quantityInStock, r.quantityInStock);
  38. SELF := l;
  39. END;
  40.  
  41. rolledUpDS := ROLLUP(vendorQtyDS,
  42. LEFT.productVendor=RIGHT.productVendor,
  43. doRollup(LEFT, RIGHT));
  44.  
  45. OUTPUT(rolledUpDS);