Skip to content

Commit

Permalink
Merge pull request #69 from django-datama/master
Browse files Browse the repository at this point in the history
New : dryRun parameter for a query.
  • Loading branch information
MarkEdmondson1234 authored Jan 27, 2021
2 parents e2a15e3 + bdd9541 commit 3d8bc72
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions R/query.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ bqr_query <- function(projectId = bqr_get_global_project(),
query,
maxResults = 1000,
useLegacySql = TRUE,
useQueryCache = TRUE){
useQueryCache = TRUE,
dryRun = FALSE,
timeoutMs = 600*1000){
check_bq_auth()

if(endsWith(query, ".sql")){
Expand All @@ -54,21 +56,34 @@ bqr_query <- function(projectId = bqr_get_global_project(),
defaultDataset = list(
datasetId = datasetId,
projectId = projectId
)
),
timeoutMs = timeoutMs,
dryRun = dryRun
)

body <- rmNullObs(body)

# solve 404?
the_url <- sprintf("https://www.googleapis.com/bigquery/v2/projects/%s/queries", projectId)

q <- googleAuthR::gar_api_generator(the_url,
"POST",
data_parse_function = parse_bqr_query,
checkTrailingSlash = FALSE)

data <- try(q(the_body = body,
path_arguments = list(projects = projectId)))
if(dryRun){
q <- googleAuthR::gar_api_generator(the_url,
"POST",
checkTrailingSlash = FALSE)
data <- try(q(the_body = body,
path_arguments = list(projects = projectId)))
if(!is.error(data)){
data <- data$content
}

}else{
q <- googleAuthR::gar_api_generator(the_url,
"POST",
data_parse_function = parse_bqr_query,
checkTrailingSlash = FALSE)
data <- try(q(the_body = body,
path_arguments = list(projects = projectId)))
}

if(is.error(data)) {
warning(error.message(data))
Expand Down

0 comments on commit 3d8bc72

Please sign in to comment.