Build BigQuery SQL with Scala String interpolation, which supports BigQuery parameterized queries and prevent SQL injection automatically.
libraryDependencies += "net.pishen" %% "bql" % "<version>"
import bql._
val bigquery = BigQueryOptions.getDefaultInstance().getService()
val gender = "M"
val states = Seq("WA", "WI", "WV", "WY")
val bql = bql"""SELECT name, sum(number) as count
|FROM `bigquery-public-data.usa_names.usa_1910_2013`
|WHERE gender = ${gender}
|AND state IN UNNEST(${states})
|GROUP BY name
|ORDER BY count DESC
|LIMIT 10"""
bigquery.query(bql.queryConfig)