# 00.02 Tables Creating.r
.description = 
"This file lists the data.tables we will create throughout this process
and has flags for whether we will recreate or load from backup"

pulldata <- list(NULL

		### --- 1 --- ###

		### A, B, & C  Pertain to those UPC's for which we ran adds
		# A. The XLS data with Add-campaign info - from XLS file
		, SpotifyAdds       = TRUE  # TRUE
		# B. Release & Genre info pertaining to UPCs in use - from infinitDB
		, DB.Meta           = TRUE
		# C. Raw, line-by-line for UPCS in use - from RedShift
		, DB.raw            = TRUE


		# D. Release & Genre info for ALLLL upcs in our system - from infinitDB
		, DB.all.meta       = TRUE
		# E. Aggregate information for ALLLL upcs in our system - from RedShift
		, DB.all.count      = TRUE

		## MERGING count with meta data for ALLLL upcs - from RedShift
		, DB.all.countmeta  = TRUE
		## MERGING Campaign data with Meta data
		, DB.SpotifyMeta    = TRUE


		, DT.SpotifyMeta.Long = TRUE

	)


#                   Name      Size       Type     Rows Columns Key
# 1:              DB.raw  20.81 GB data.table 56658091      55 upc
# 2:    DB.all.countmeta   2.74 GB data.table 22285244      16 upc
# 3:        DB.all.count   2.02 GB data.table 44570488       6 upc
# 4:             DB.Meta 205.68 KB data.table      251      28 upc
# 5:      DB.SpotifyMeta 201.74 KB data.table      254      42 upc
# 6: DB.SpotifyMeta.Long 146.88 KB data.table      303      40 upc
# 7:         SpotifyAdds  99.76 KB data.table      257      26 upc


nameCheck <- function(tbl, pulldata, showWarnings=TRUE) {
	if (length(tbl) > 1)
		return(sapply(tbl, nameCheck, pulldata=pulldata))

	if (tbl %in% names(pulldata))
		return(tbl)

	## ELSE
	matched <- pmatch(toupper(tbl), toupper(names(pulldata)))

	if (is.na(matched)) {
		if (showWarnings)
			warning("\n", tbl, " is not a valid name in `pulldata`.\nOptions are  ", paste0(names(pulldata), collapse=",  "))
		return(NA)
	}

	tbl <- names(pulldata)[matched]
	if (showWarnings)
		warning("The correct spelling for this item is \"", tbl, "\"\nPlease correct your code.")
	return(tbl)
}
