pishen / bql   0.1.0

Apache License 2.0 GitHub

Build BigQuery SQL with Scala String interpolation

Scala versions: 2.13 2.12

bql

Maven Central javadoc

Build BigQuery SQL with Scala String interpolation, which supports BigQuery parameterized queries and prevent SQL injection automatically.

Installation

libraryDependencies += "net.pishen" %% "bql" % "<version>"

Usage

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)