stop("This file is depreciated!!")



All of the info in this file has been split up into 

  02a1 - Query Parameters.r
  02a2 - Query Execution on RBox.r



This may be outdated















TBLS.itunes <- c("production.staging_raw_itunes", "public.staging_raw_itunes", "production.staging_raw_itunes_test")

## -------------------------------- ##
##         QUERY PARAMETERS         ##
## -------------------------------- ##
  TEST.RUN <- 15 # FALSE

  q.nm.prefx <- "SOTW_" # NULL
  qry_timestamp <- timeStamp(frmt=frmt.monthday_time)

  useProduction <- FALSE # TRUE
  schema <- NULL # "production"
  TBL <- "staging_raw_itunes_test"   

  colsToPull <- c("vendor_identifier", "upc", "isrc", "artist", "title", "record_company", 
                  "product_type_identifier", "units", "royalty_price", "download_date", 
                  "order_id", "postal_code", "customer_identifier", 
                  "sale_return", "customer_currency", "country_code", "royalty_currency", 
                  "preorder", "isan", "customer_price", "cma", "asset", 
                  "vendor_offer_code", "grid", "promo_code", "parent_id", "season_pass", 
                  "belongs_to_ioda", "attributable_purchase", "primary_genre")

  date_col <- "download_date" # "processedDayTime" 
  upc_col  <- "upc" #  if(grepl("itunes", TBL, ignore.case=TRUE)) "releaseId" else "upc"


  whereIn <- list(   upc = removeNA(SomLivre[, upc])
                  # , name = c("ex1", "ex2")
                 )
  names(whereIn)[names(whereIn) == "upc"] <- upc_col


  dateMin <- min(SomLivre[!is.na(get(upc_col)), date]) - 400
  dateMax <- NULL

  showWarnings = TRUE
  limit = NULL
## ------------------------------ ##



 #-------



## ------------------------------ ##
##        QUERY EXECUTION         ##
## ------------------------------ ##

  limit <- if (is.numeric(TEST.RUN)) TEST.RUN else if(isTRUE(TEST.RUN)) 10 else NULL

  if (length(schema) > 1 && length(schema) == length(TBL) ) 
    warning ("\n `schema` and `TBL` each have multiple lengths and will result in ", length(TBL) * length(schema) ," total tables queried.\nTo create schema/TBL combinations in parallel, use `mapply`.")

  if (length(schema)) {
    TBL    <- sapply(schema, schemaPaste, TBL)
    schema <- NULL
  }

  #### Queries will be saved in a list. 
  ##     QRY holds the string sent as the SQL Query
  ##    QRES holds the results that were returned by the query
  ##    q.nm is the list names that correspons to both of these
  ## 
  if (!exists("QRY"))
    QRY <- list()
  if (!exists("QRES"))
    QRES <- list()


  q.nm <- paste0(q.nm.prefx, TBL, "_UPC_", if(length(schema)) paste0(schema, "_"), qry_timestamp)
  # Construct the query


  QRY[q.nm] <- sapply(TBL, makeQry
                      , colsToPull=colsToPull, whereIn=whereIn, schema=schema
                      , dateCol=date_col, dateMin=dateMin, dateMax=dateMax
                      , limit=limit, useProduction=useProduction)

  # Submit the qruery and store the results
  QRES[q.nm] <- lapply(QRY[q.nm], runQry, verbose=TRUE)


## ------------------------------ ##

### GET RELEASE DATES

  QRES[["releaseDates"]] <- getReleaseDates(SomLivre[, upc])

