Se si utilizza R o pitone per interfacciarsi con le API GBQ e non si preoccupano sql-iniezione, cioè. vuoi solo scambiare iterativamente i parametri nelle query, potresti voler esaminare la lingua dei modelli mustache (disponibile in R come 'whisker').
Se si utilizza R, è possibile scorrere/automatizzare le query con il pacchetto condusco R. Ecco uno script completo R che compirà un iterativa di swap-out dei parametri in una query utilizzando sia baffo e condusco:
library(bigrquery)
library(condusco)
library(whisker)
# create a simple function that will create a query
# using {{{mustache}}} placeholders for any parameters
create_results_table <- function(params){
destination_table <- '{{{dataset_id}}}.{{{table_prefix}}}_results_{{{year_low}}}_{{{year_high}}}'
query <- '
SELECT *
FROM `bigquery-public-data.samples.gsod`
WHERE year > {{{year_low}}}
AND year <= {{{year_high}}}
'
# use whisker to swap out {{{mustache}}} placeholders with parameters
query_exec(
whisker.render(query,params),
project=whisker.render('{{{project}}}', params),
destination_table = whisker.render(destination_table,params),
use_legacy_sql = FALSE
)
}
# create an invocation query to provide sets of parameters to create_results_table
invocation_query <- '
SELECT
"<YOUR PROJECT HERE>" as project,
"<YOUR DATASET_ID HERE>" as dataset_id,
"<YOUR TABLE PREFIX HERE>" as table_prefix,
num as year_low,
num+1 as year_high
FROM `bigquery-public-data.common_us.num_999999`
WHERE num BETWEEN 1992 AND 1995
'
# call condusco's run_pipeline_gbq to iteratively run create_results_table over invocation_query's results
run_pipeline_gbq(
create_results_table,
invocation_query,
project = '<YOUR PROJECT HERE>',
use_legacy_sql = FALSE
)
nostro [add-on per l'esecuzione di query BQ in Google Fogli] (https: // cromo. google.com/webstore/detail/owox-bi-bigquery-reports/fepofngogkjnejgcbdmmkddnpeojbbin) ti consente di impostare i parametri per le tue query e rieseguirli modificando solo i valori dei parametri preimpostati. –