20141006 -- this is a sloppy script, in that it requires manual work. There are four tables to check The simple comparisons: production.fact tables against bi.agg tables More complicated: accounting against analytics. Specifically, royaltydollar should equal gross ## THESE SHOULD, IN THEORY, ALL BE THE SAME # --------------- BY ACCOUNTING MONTH -------------------- # DT.prod_fact.itunes <- { runQry( " SELECT storeid, accountingperiodid as periodid, sum(sales) AS paidunits, sum(gross) AS gross FROM production.fact_sales where storeid = 1 -- and accountingyear == 2013 and accountingmonth BETWEEN 1 and 4 and accountingyear >= 2013 and (transactiontypeid in (SELECT transactiontypeid from dim_transactiontype where transactiontypeabbr in ('DV', 'VR'))) group by 1, 2 order by 2 ; ")} addDateCols.periodid_(DT.prod_fact.itunes, drop=TRUE, repl="month") DT.bi.itunes <- { runQry( " SELECT storeid, download_accounting_month as month, sum(paidunits) AS paidunits, sum(gest) AS gest FROM bi.analytics -- where download_accounting_month BETWEEN '2013-01-01' and '2013-04-01' where download_accounting_month >= '2013-01-01' and storeid = 1 and (transac_typeid in (SELECT transactiontypeid from dim_transactiontype where transactiontypeabbr in ('DV', 'VR'))) group by 1, 2 order by 2 " )} # --------------- BY ACTIVITY DATE -------------------- # ## THESE SHOULD BE THE SAME DT.prod.itunes <- { runQry(paste( " SELECT storeid, ", sql1stOfMonth("download_activity_date", "month"), ", sum(paidunits) AS paidunits, sum(royaltydollar) AS royaltydollar FROM production.fact_analytics -- where download_activity_date BETWEEN '2013-01-01' and '2013-04-01' where download_activity_date >= '2013-01-01' and storeid = 1 and (transactiontypeid in (SELECT transactiontypeid from dim_transactiontype where transactiontypeabbr in ('DV', 'VR'))) group by 1, 2 order by 2 ; "))} DT.bi.itunes <- { runQry(paste( " SELECT storeid, ", sql1stOfMonth("download_activity_date", "month"), ", sum(paidunits) AS paidunits, sum(gest) AS gest FROM bi.analytics -- where download_activity_date BETWEEN '2013-01-01' and '2013-04-01' where download_activity_date >= '2013-01-01' and storeid = 1 and (transac_typeid in (SELECT transactiontypeid from dim_transactiontype where transactiontypeabbr in ('DV', 'VR'))) group by 1, 2 order by 2 " ))} matchKey(DT.prod.itunes, DT.bi.itunes, c("storeid", "month"), organize=TRUE) DT.itunes.compare <- merge(DT.prod.itunes, DT.bi.itunes, all=TRUE, suffix=c(".prod", ".bi")) setcolorder(DT.itunes.compare, c(key(DT.itunes.compare), sort(setdiff(names(DT.itunes.compare), key(DT.itunes.compare))))) DT.itunes.compare DT.itunes.compare[, paidunits.OK := paidunits.bi == paidunits.prod] stopifnot(DT.itunes.compare[month <= Sys.Date() - 60, paidunits.bi == paidunits.prod])