Skip to content

Commit

Permalink
Merge 2371ca7 into 395bd04
Browse files Browse the repository at this point in the history
  • Loading branch information
marctalbott committed May 18, 2020
2 parents 395bd04 + 2371ca7 commit d2cd7b0
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ To depend on the `MockGoogle*` classes, additionally depend on:

Contains utility functions for talking to Google APIs via com.google.cloud client library (more recent) via gRPC.

Latest SBT dependency: `"org.broadinstitute.dsde.workbench" %% "workbench-google2" % "0.9-e66171c"`
Latest SBT dependency: `"org.broadinstitute.dsde.workbench" %% "workbench-google2" % "1.0-TRAVIS-REPLACE-ME"`

To start the Google PubSub emulator for unit testing:

Expand Down
3 changes: 2 additions & 1 deletion google2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ This file documents changes to the `workbench-google2` library, including notes
## 1.0
Changed:
- Renamed KubernetesSerializableName extension classes
- Added BigQuery

SBT dependency: `"org.broadinstitute.dsde.workbench" %% "workbench-google2" % "1.0-e66171c"`
SBT dependency: `"org.broadinstitute.dsde.workbench" %% "workbench-google2" % "1.0-TRAVIS-REPLACE-ME"`

## 0.9
Changed:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.broadinstitute.dsde.workbench.google2

import cats.effect.{Blocker, ContextShift, Sync}
import com.google.cloud.bigquery.{BigQuery, JobId, QueryJobConfiguration, TableResult}


private[google2] class GoogleBigQueryInterpreter[F[_]: Sync: ContextShift](client: BigQuery,
blocker: Blocker) extends GoogleBigQueryService[F] {

override def query(queryJobConfiguration: QueryJobConfiguration, options: BigQuery.JobOption*): F[TableResult] = {
blockingF(Sync[F].delay[TableResult] {
client.query(queryJobConfiguration, options: _*)
})
}

override def query(queryJobConfiguration: QueryJobConfiguration, jobId: JobId, options: BigQuery.JobOption*): F[TableResult] = {
blockingF(Sync[F].delay[TableResult] {
client.query(queryJobConfiguration, jobId, options: _*)
})
}

private def blockingF[A](fa: F[A]): F[A] = blocker.blockOn(fa)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.broadinstitute.dsde.workbench.google2

import cats.effect.{Blocker, ContextShift, Resource, Sync}
import com.google.cloud.bigquery.BigQueryOptions.DefaultBigQueryFactory
import com.google.cloud.bigquery.{BigQuery, BigQueryOptions, JobId, QueryJobConfiguration, TableResult}


trait GoogleBigQueryService[F[_]] {
def query(queryJobConfiguration: QueryJobConfiguration, options: BigQuery.JobOption*): F[TableResult]

def query(queryJobConfiguration: QueryJobConfiguration, jobId: JobId, options: BigQuery.JobOption*): F[TableResult]
}

object GoogleBigQueryService {
def resource[F[_]: Sync: ContextShift](pathToJson: String, blocker: Blocker): Resource[F, GoogleBigQueryService[F]] =
for {
credentials <- credentialResource(pathToJson)
client <- Resource.liftF[F, BigQuery](
Sync[F].delay(
new DefaultBigQueryFactory().create(
BigQueryOptions.newBuilder()
.setCredentials(credentials)
.build())
)
)
} yield new GoogleBigQueryInterpreter[F](client, blocker)
}


2 changes: 2 additions & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ object Dependencies {
val googleComputeNew: ModuleID = "com.google.cloud" % "google-cloud-compute" % "0.118.0-alpha"
val googleContainer: ModuleID = "com.google.cloud" % "google-cloud-container" % "1.0.4"
val kubernetesClient: ModuleID = "io.kubernetes" % "client-java" % "5.0.0" % "compile"
val googleBigQueryNew: ModuleID = "com.google.cloud" % "google-cloud-bigquery" % "1.114.0"
//the below v1 module is a dependency for v2 because it contains the OAuth scopes necessary to created scoped credentials
val googleContainerV1: ModuleID = "com.google.apis" % "google-api-services-container" % s"v1-rev74-$googleV"

Expand Down Expand Up @@ -162,6 +163,7 @@ object Dependencies {
googleKms,
googleDataproc,
googleComputeNew,
googleBigQueryNew,
http4sCirce,
http4sBlazeClient,
http4sDsl,
Expand Down

0 comments on commit d2cd7b0

Please sign in to comment.