/* Transformation - There is really no SQL Equivalent here.*/
//Project
//Here you are saying transform one record set to another by
//applying a transformation on each record
Product clean(Product inrec) := TRANSFORM
SELF.productName := Std.Str.ToUpperCase(inrec.productName);
SELF := inrec;
END;
upperProducts := PROJECT(products, clean(LEFT));
OUTPUT(upperProducts);
//Iterate
//Here you are saying transform one record set to another by
//applying a transformation on a pair of records at a time
Product doCompute(Product l, Product r) := TRANSFORM
SELF.quantityInStock := IF(l.productVendor=r.productVendor,
l.quantityInStock + r.quantityInStock, 0);
SELF.productVendor := R.productVendor;
SELF := l;
END;
productsByVendorDS := SORT(products, productVendor);
vendorQtyDS := ITERATE(productsByVendorDS, doCompute(LEFT, RIGHT));
OUTPUT(vendorQtyDS);
//ROLLUP
//Here you are saying transform one record set to another by
//deduping and transforming the matching records during the
//dedup process
Product doRollup(Product l, Product r) := TRANSFORM
SELF.quantityInStock := IF(l.quantityInStock > r.quantityInStock,
l.quantityInStock, r.quantityInStock);
SELF := l;
END;
rolledUpDS := ROLLUP(vendorQtyDS,
LEFT.productVendor=RIGHT.productVendor,
doRollup(LEFT, RIGHT));
OUTPUT(rolledUpDS);