
colsToPull <- c("country_code"="storefront_name", "membership")
DT.apple <- makeQry(tbl=tbl, schema=schema, colsToPull=colsToPull, limit=12) %>% runQry(cluster=cluster)

# How many streams did each track receive?
# Percent split amongst membership

DT.apple <- makeQry(tbl=tbl, schema=schema, colsToPull=colsToPull, where="offline != 0", limit=12) %>% runQry(cluster=cluster)
makeQry(tbl=tbl, schema=schema, colsToAgg="utc_offset", aggFunc="max", datestamp="2015-07-04") %>% runQry(cluster=cluster)

makeQry(tbl=tbl, schema=schema, colsToAgg="quantity", colsToPull=c("media_type")) %>% runQry(cluster=cluster)
makeQry(tbl=tbl, schema=schema, colsToAgg="quantity", colsToPull=c("end_reason_type"), limit=NULL) %>% runQry(cluster=cluster) %>% {.[, perc := fwp(percOfTotal(quantity), dec=1)]} %>% {.}

DT.times <- makeQry(tbl=tbl, schema=schema, colsToPull=c("storefront_name", "utc_offset"), aggFunc="count") %>% runQry(cluster=cluster) %>% {.[storefront_name=="US"][order(storefront_name, utc_offset, decreasing=TRUE)]}
DT.times[, utc_hours := utc_offset / 3600]



DT.apple <- runQry("SELECT * FROM production.staging_raw_apple_music limit 3000")
makeSQLtable(DT.apple, sortkey=NULL, diststyle=NULL)
      And unloading it to "s3://dev-rsaporta/BI_Tables/staging_raw_apple_music/20150706_2159/staging_raw_apple_music_"

