R/get_template_load.R

Defines functions get_template_load

Documented in get_template_load

#' @title Retrieve loading template
#' 
#' @description Goes through the template load data to retrieve all the attributes mentionned.
#' 
#' @author Briac LE RAY (briac.leray@partnre.com)
#' 
#' @return A string with the correct format for loading.
#' @param line_template_list_sources The line from the template for the sources of data. Type = datataframe

#' @examples get_template_load(line_template_list_sources = my_filled_template)


get_template_load <- function(line_template_list_sources) {
  # Provides the template to add to the R file for loading.
  Nom_de_la_table_source = line_template_list_sources$Nom_de_la_table_source
  name_cre = str_sub(string = Nom_de_la_table_source, start = -5, end = -1) %>% tolower() # 5 last characters
  date_arrete = line_template_list_sources$Date_arrete
  Chemin_acces_hadoop = line_template_list_sources$Chemin_acces_hadoop
  
  # Case 1 : has to perform SQL search.
  if (!is.na(line_template_list_sources$Recherche_SQL)) {
    return(glue("# Load {Nom_de_la_table_source} ----
CREATE_TABLE(\"SELECT * FROM CIA_PR.cre_{name_cre}
where da_arr_cre='{date_arrete}'
and cd_si_don_entete in ('001', '002', '003')
\",
'cre_{name_cre}')
cre_{name_cre} = dbGetQuery(con, \"select * from sandbox_y8202.cre_{name_cre}\")
                names(cre_{name_cre}) = gsub('cre_{name_cre}.', '', names(cre_{name_cre}))"
    ))
  }
  
  # Case 2 : retrieve data directly from Hadoop
  else if (!is.na(Chemin_acces_hadoop)) {
    return(glue("# Load {Nom_de_la_table_source} ----
                {Nom_de_la_table_source} = import_data('{Chemin_acces_hadoop}')"))
  }
  
  # Case 3 : other way to retrieve data
  else {
    return(glue("# Load {Nom_de_la_table_source} ----
                # PLEASE ADD YOUR LOADING METHOD"))
  }
}
Tiipiac/StressTestOptimization documentation built on Dec. 18, 2021, 5:08 p.m.