Skip to content

Commit

Permalink
[BigQuery] Add extra params to the QueryRequest (#2679)
Browse files Browse the repository at this point in the history
  • Loading branch information
kovstas authored May 29, 2021
1 parent 8193050 commit 0153ae7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ProblemFilters.exclude[IncompatibleSignatureProblem]("akka.stream.alpakka.googlecloud.bigquery.model.QueryRequest.unapply")
ProblemFilters.exclude[DirectMissingMethodProblem]("akka.stream.alpakka.googlecloud.bigquery.model.QueryRequest.copy")
ProblemFilters.exclude[DirectMissingMethodProblem]("akka.stream.alpakka.googlecloud.bigquery.model.QueryRequest.this")
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import scala.concurrent.duration.FiniteDuration
* @param timeout specifies the maximum amount of time that the client is willing to wait for the query to complete
* @param dryRun if set to `true` BigQuery doesn't run the job and instead returns statistics about the job such as how many bytes would be processed
* @param useLegacySql specifies whether to use BigQuery's legacy SQL dialect for this query
* @param location the geographic location where the job should run
* @param labels the labels associated with this query
* @param maximumBytesBilled limits the number of bytes billed for this query
* @param requestId a unique user provided identifier to ensure idempotent behavior for queries
*/
final case class QueryRequest private (query: String,
Expand All @@ -38,6 +41,9 @@ final case class QueryRequest private (query: String,
timeout: Option[FiniteDuration],
dryRun: Option[Boolean],
useLegacySql: Option[Boolean],
location: Option[String],
labels: Option[Map[String, String]],
maximumBytesBilled: Option[Long],
requestId: Option[String]) {

def getQuery = query
Expand All @@ -47,6 +53,9 @@ final case class QueryRequest private (query: String,
def getDryRun = dryRun.map(lang.Boolean.valueOf).asJava
def getUseLegacySql = useLegacySql.map(lang.Boolean.valueOf).asJava
def getRequestId = requestId.asJava
def getLocation = location.asJava
def getMaximumBytesBilled = maximumBytesBilled.asJava
def getLabels = labels.asJava

def withQuery(query: String) =
copy(query = query)
Expand Down Expand Up @@ -80,10 +89,34 @@ final case class QueryRequest private (query: String,
copy(requestId = requestId)
def withRequestId(requestId: util.Optional[String]) =
copy(requestId = requestId.asScala)

def withLocation(location: Option[String]) =
copy(location = location)
def withLocation(location: util.Optional[String]) =
copy(location = location.asScala)

def withMaximumBytesBilled(maximumBytesBilled: Option[Long]) =
copy(maximumBytesBilled = maximumBytesBilled)
def withMaximumBytesBilled(maximumBytesBilled: util.OptionalLong) =
copy(maximumBytesBilled = maximumBytesBilled.asScala)

def withLabels(labels: Option[Map[String, String]]) =
copy(labels = labels)
def withLabels(labels: util.Optional[util.Map[String, String]]) =
copy(labels = labels.asScala.map(_.asScala.toMap))
}

object QueryRequest {

def apply(query: String,
maxResults: Option[Int],
defaultDataset: Option[DatasetReference],
timeout: Option[FiniteDuration],
dryRun: Option[Boolean],
useLegacySql: Option[Boolean],
requestId: Option[String]): QueryRequest =
QueryRequest(query, maxResults, defaultDataset, timeout, dryRun, useLegacySql, None, None, None, requestId)

/**
* Java API: QueryRequest model
* @see [[https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query#queryrequest BigQuery reference]]
Expand Down Expand Up @@ -111,6 +144,9 @@ object QueryRequest {
timeout.asScala.map(_.asScala),
dryRun.asScala.map(_.booleanValue),
useLegacySql.asScala.map(_.booleanValue),
None,
None,
None,
requestId.asScala
)

Expand All @@ -122,6 +158,9 @@ object QueryRequest {
"timeoutMs",
"dryRun",
"useLegacySql",
"location",
"labels",
"maximumBytesBilled",
"requestId"
)
}
Expand Down

0 comments on commit 0153ae7

Please sign in to comment.