{"action":"created","comment":{"url":"https://api.github.com/repos/spotify/scio/pulls/comments/229080812","pull_request_review_id":169495583,"id":229080812,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyOTA4MDgxMg==","diff_hunk":"@@ -0,0 +1,120 @@\n+/*\n+ * Copyright 2018 Spotify AB.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing,\n+ * software distributed under the License is distributed on an\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+ * KIND, either express or implied.  See the License for the\n+ * specific language governing permissions and limitations\n+ * under the License.\n+ */\n+\n+package com.spotify.scio.spanner\n+\n+import com.google.cloud.spanner._\n+import com.spotify.scio.ScioContext\n+import com.spotify.scio.io.{EmptyTap, EmptyTapOf, ScioIO, Tap}\n+import com.spotify.scio.values.SCollection\n+import org.apache.beam.sdk.io.gcp.spanner.SpannerIO.FailureMode\n+import org.apache.beam.sdk.io.gcp.spanner.{SpannerConfig, SpannerIO => BSpannerIO}\n+\n+import scala.collection.JavaConverters._\n+import scala.concurrent.Future\n+\n+sealed trait SpannerIO[T] extends ScioIO[T] {\n+  override final val tapT = EmptyTapOf[T]\n+  val config: SpannerConfig\n+\n+  override def testId: String =\n+    s\"${getClass.getSimpleName}\" +\n+      s\"(${config.getProjectId}, ${config.getInstanceId}, ${config.getDatabaseId})\"\n+}\n+\n+object SpannerRead {\n+  object ReadParam {\n+    private[spanner] val DefaultWithTransaction = false\n+    private[spanner] val DefaultWithBatching = true\n+  }\n+\n+  sealed trait ReadMethod\n+  case class FromTable(tableName: String, columns: Seq[String]) extends ReadMethod\n+  case class FromQuery(query: String) extends ReadMethod\n+\n+  final case class ReadParam private (\n+    readMethod: ReadMethod,\n+    withTransaction: Boolean = ReadParam.DefaultWithTransaction,\n+    withBatching: Boolean = ReadParam.DefaultWithBatching\n+  )\n+}\n+\n+final case class SpannerRead(config: SpannerConfig) extends SpannerIO[Struct] {\n+  import SpannerRead._\n+\n+  override type ReadP = ReadParam\n+  override type WriteP = Nothing\n+\n+  override protected def read(sc: ScioContext, params: ReadP): SCollection[Struct] = sc.wrap {\n+    var transform = BSpannerIO\n+      .read()\n+      .withSpannerConfig(config)\n+      .withBatching(params.withBatching)\n+\n+    transform = params.readMethod match {\n+      case x: FromTable => transform.withTable(x.tableName).withColumns(x.columns.asJava)\n+      case y: FromQuery => transform.withQuery(y.query)\n+    }\n+\n+    if (params.withTransaction) {\n+      val txn = BSpannerIO.createTransaction().withSpannerConfig(config)\n+      transform = transform.withTransaction(sc.applyInternal(txn))\n+    }\n+\n+    sc.applyInternal(transform)\n+  }\n+\n+  override protected def write(data: SCollection[Struct], params: WriteP): Future[Tap[Nothing]] =\n+    throw new IllegalStateException(\"SpannerRead is read-only\")\n+\n+  override def tap(params: ReadP): Tap[Nothing] =\n+    throw new NotImplementedError(\"SpannerRead tap is not implemented\")\n+}\n+\n+object SpannerWrite {\n+  object WriteParam {\n+    private[spanner] val DefaultFailureMode = FailureMode.FAIL_FAST\n+    private[spanner] val DefaultBatchSizeBytes = 1024L * 1024L\n+  }\n+\n+  final case class WriteParam private (\n+    failureMode: FailureMode = WriteParam.DefaultFailureMode,\n+    batchSizeBytes: Long = WriteParam.DefaultBatchSizeBytes\n+  )\n+}\n+\n+final case class SpannerWrite(config: SpannerConfig) extends SpannerIO[Mutation] {\n+  override type ReadP = Nothing\n+  override type WriteP = SpannerWrite.WriteParam\n+\n+  override protected def write(data: SCollection[Mutation],\n+                               params: WriteP): Future[Tap[Nothing]] = {\n+    var transform = BSpannerIO.write().withSpannerConfig(config)","path":"scio-spanner/src/main/scala/com/spotify/scio/spanner/SpannerIO.scala","position":106,"original_position":106,"commit_id":"66ddf3346f0f95fa5a899e2f853dfd557b95508a","original_commit_id":"66ddf3346f0f95fa5a899e2f853dfd557b95508a","user":{"login":"regadas","id":163899,"node_id":"MDQ6VXNlcjE2Mzg5OQ==","avatar_url":"https://avatars2.githubusercontent.com/u/163899?v=4","gravatar_id":"","url":"https://api.github.com/users/regadas","html_url":"https://github.com/regadas","followers_url":"https://api.github.com/users/regadas/followers","following_url":"https://api.github.com/users/regadas/following{/other_user}","gists_url":"https://api.github.com/users/regadas/gists{/gist_id}","starred_url":"https://api.github.com/users/regadas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/regadas/subscriptions","organizations_url":"https://api.github.com/users/regadas/orgs","repos_url":"https://api.github.com/users/regadas/repos","events_url":"https://api.github.com/users/regadas/events{/privacy}","received_events_url":"https://api.github.com/users/regadas/received_events","type":"User","site_admin":false},"body":"@ClaireMcGinty can you do it like this?\r\n\r\n```suggestion\r\n    val transform = BSpannerIO\r\n      .write()\r\n      .withSpannerConfig(config)\r\n      .withBatchSizeBytes(params.batchSizeBytes)\r\n      .withFailureMode(params.failureMode)\r\n```","created_at":"2018-10-29T20:12:47Z","updated_at":"2018-10-29T20:12:47Z","html_url":"https://github.com/spotify/scio/pull/1491#discussion_r229080812","pull_request_url":"https://api.github.com/repos/spotify/scio/pulls/1491","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/spotify/scio/pulls/comments/229080812"},"html":{"href":"https://github.com/spotify/scio/pull/1491#discussion_r229080812"},"pull_request":{"href":"https://api.github.com/repos/spotify/scio/pulls/1491"}}},"pull_request":{"url":"https://api.github.com/repos/spotify/scio/pulls/1491","id":226663284,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI2NjYzMjg0","html_url":"https://github.com/spotify/scio/pull/1491","diff_url":"https://github.com/spotify/scio/pull/1491.diff","patch_url":"https://github.com/spotify/scio/pull/1491.patch","issue_url":"https://api.github.com/repos/spotify/scio/issues/1491","number":1491,"state":"open","locked":false,"title":"add Spanner package","user":{"login":"ClaireMcGinty","id":1360529,"node_id":"MDQ6VXNlcjEzNjA1Mjk=","avatar_url":"https://avatars3.githubusercontent.com/u/1360529?v=4","gravatar_id":"","url":"https://api.github.com/users/ClaireMcGinty","html_url":"https://github.com/ClaireMcGinty","followers_url":"https://api.github.com/users/ClaireMcGinty/followers","following_url":"https://api.github.com/users/ClaireMcGinty/following{/other_user}","gists_url":"https://api.github.com/users/ClaireMcGinty/gists{/gist_id}","starred_url":"https://api.github.com/users/ClaireMcGinty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ClaireMcGinty/subscriptions","organizations_url":"https://api.github.com/users/ClaireMcGinty/orgs","repos_url":"https://api.github.com/users/ClaireMcGinty/repos","events_url":"https://api.github.com/users/ClaireMcGinty/events{/privacy}","received_events_url":"https://api.github.com/users/ClaireMcGinty/received_events","type":"User","site_admin":false},"body":"Currently supports writes from `Mutation`s and reads into `Struct`s. I have the spanner type macros saved for sometime further down the line.\r\n\r\nnotes:\r\n- Spanner integration test is kind of slow, takes 37 seconds\r\n- SpannerIO's `testId` doesn't support a unit having 2 spanner reads/writes to the same DB since it's just keyed by the `SpannerConfig` params, which don't include table name. For writes the table name is keyed into each `Mutation` object and reads give you a choice of specifying a table name or a literal query\r\n- Haven't implemented Taps yet","created_at":"2018-10-29T18:14:19Z","updated_at":"2018-10-29T20:12:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cb684816d51a2f91268d27ddceca4ce4abb39928","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/spotify/scio/pulls/1491/commits","review_comments_url":"https://api.github.com/repos/spotify/scio/pulls/1491/comments","review_comment_url":"https://api.github.com/repos/spotify/scio/pulls/comments{/number}","comments_url":"https://api.github.com/repos/spotify/scio/issues/1491/comments","statuses_url":"https://api.github.com/repos/spotify/scio/statuses/66ddf3346f0f95fa5a899e2f853dfd557b95508a","head":{"label":"spotify:claire/spanner_io","ref":"claire/spanner_io","sha":"66ddf3346f0f95fa5a899e2f853dfd557b95508a","user":{"login":"spotify","id":251374,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI1MTM3NA==","avatar_url":"https://avatars2.githubusercontent.com/u/251374?v=4","gravatar_id":"","url":"https://api.github.com/users/spotify","html_url":"https://github.com/spotify","followers_url":"https://api.github.com/users/spotify/followers","following_url":"https://api.github.com/users/spotify/following{/other_user}","gists_url":"https://api.github.com/users/spotify/gists{/gist_id}","starred_url":"https://api.github.com/users/spotify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spotify/subscriptions","organizations_url":"https://api.github.com/users/spotify/orgs","repos_url":"https://api.github.com/users/spotify/repos","events_url":"https://api.github.com/users/spotify/events{/privacy}","received_events_url":"https://api.github.com/users/spotify/received_events","type":"Organization","site_admin":false},"repo":{"id":32946662,"node_id":"MDEwOlJlcG9zaXRvcnkzMjk0NjY2Mg==","name":"scio","full_name":"spotify/scio","private":false,"owner":{"login":"spotify","id":251374,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI1MTM3NA==","avatar_url":"https://avatars2.githubusercontent.com/u/251374?v=4","gravatar_id":"","url":"https://api.github.com/users/spotify","html_url":"https://github.com/spotify","followers_url":"https://api.github.com/users/spotify/followers","following_url":"https://api.github.com/users/spotify/following{/other_user}","gists_url":"https://api.github.com/users/spotify/gists{/gist_id}","starred_url":"https://api.github.com/users/spotify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spotify/subscriptions","organizations_url":"https://api.github.com/users/spotify/orgs","repos_url":"https://api.github.com/users/spotify/repos","events_url":"https://api.github.com/users/spotify/events{/privacy}","received_events_url":"https://api.github.com/users/spotify/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/spotify/scio","description":"A Scala API for Apache Beam and Google Cloud Dataflow.","fork":false,"url":"https://api.github.com/repos/spotify/scio","forks_url":"https://api.github.com/repos/spotify/scio/forks","keys_url":"https://api.github.com/repos/spotify/scio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/spotify/scio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/spotify/scio/teams","hooks_url":"https://api.github.com/repos/spotify/scio/hooks","issue_events_url":"https://api.github.com/repos/spotify/scio/issues/events{/number}","events_url":"https://api.github.com/repos/spotify/scio/events","assignees_url":"https://api.github.com/repos/spotify/scio/assignees{/user}","branches_url":"https://api.github.com/repos/spotify/scio/branches{/branch}","tags_url":"https://api.github.com/repos/spotify/scio/tags","blobs_url":"https://api.github.com/repos/spotify/scio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/spotify/scio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/spotify/scio/git/refs{/sha}","trees_url":"https://api.github.com/repos/spotify/scio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/spotify/scio/statuses/{sha}","languages_url":"https://api.github.com/repos/spotify/scio/languages","stargazers_url":"https://api.github.com/repos/spotify/scio/stargazers","contributors_url":"https://api.github.com/repos/spotify/scio/contributors","subscribers_url":"https://api.github.com/repos/spotify/scio/subscribers","subscription_url":"https://api.github.com/repos/spotify/scio/subscription","commits_url":"https://api.github.com/repos/spotify/scio/commits{/sha}","git_commits_url":"https://api.github.com/repos/spotify/scio/git/commits{/sha}","comments_url":"https://api.github.com/repos/spotify/scio/comments{/number}","issue_comment_url":"https://api.github.com/repos/spotify/scio/issues/comments{/number}","contents_url":"https://api.github.com/repos/spotify/scio/contents/{+path}","compare_url":"https://api.github.com/repos/spotify/scio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/spotify/scio/merges","archive_url":"https://api.github.com/repos/spotify/scio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/spotify/scio/downloads","issues_url":"https://api.github.com/repos/spotify/scio/issues{/number}","pulls_url":"https://api.github.com/repos/spotify/scio/pulls{/number}","milestones_url":"https://api.github.com/repos/spotify/scio/milestones{/number}","notifications_url":"https://api.github.com/repos/spotify/scio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/spotify/scio/labels{/name}","releases_url":"https://api.github.com/repos/spotify/scio/releases{/id}","deployments_url":"https://api.github.com/repos/spotify/scio/deployments","created_at":"2015-03-26T19:07:34Z","updated_at":"2018-10-29T18:51:02Z","pushed_at":"2018-10-29T19:26:46Z","git_url":"git://github.com/spotify/scio.git","ssh_url":"git@github.com:spotify/scio.git","clone_url":"https://github.com/spotify/scio.git","svn_url":"https://github.com/spotify/scio","homepage":"https://spotify.github.io/scio","size":8752,"stargazers_count":1286,"watchers_count":1286,"language":"Scala","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":209,"mirror_url":null,"archived":false,"open_issues_count":42,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":209,"open_issues":42,"watchers":1286,"default_branch":"master"}},"base":{"label":"spotify:master","ref":"master","sha":"bef6571d24093ce9bdf656d7c6a55595ad2a2e11","user":{"login":"spotify","id":251374,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI1MTM3NA==","avatar_url":"https://avatars2.githubusercontent.com/u/251374?v=4","gravatar_id":"","url":"https://api.github.com/users/spotify","html_url":"https://github.com/spotify","followers_url":"https://api.github.com/users/spotify/followers","following_url":"https://api.github.com/users/spotify/following{/other_user}","gists_url":"https://api.github.com/users/spotify/gists{/gist_id}","starred_url":"https://api.github.com/users/spotify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spotify/subscriptions","organizations_url":"https://api.github.com/users/spotify/orgs","repos_url":"https://api.github.com/users/spotify/repos","events_url":"https://api.github.com/users/spotify/events{/privacy}","received_events_url":"https://api.github.com/users/spotify/received_events","type":"Organization","site_admin":false},"repo":{"id":32946662,"node_id":"MDEwOlJlcG9zaXRvcnkzMjk0NjY2Mg==","name":"scio","full_name":"spotify/scio","private":false,"owner":{"login":"spotify","id":251374,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI1MTM3NA==","avatar_url":"https://avatars2.githubusercontent.com/u/251374?v=4","gravatar_id":"","url":"https://api.github.com/users/spotify","html_url":"https://github.com/spotify","followers_url":"https://api.github.com/users/spotify/followers","following_url":"https://api.github.com/users/spotify/following{/other_user}","gists_url":"https://api.github.com/users/spotify/gists{/gist_id}","starred_url":"https://api.github.com/users/spotify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spotify/subscriptions","organizations_url":"https://api.github.com/users/spotify/orgs","repos_url":"https://api.github.com/users/spotify/repos","events_url":"https://api.github.com/users/spotify/events{/privacy}","received_events_url":"https://api.github.com/users/spotify/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/spotify/scio","description":"A Scala API for Apache Beam and Google Cloud Dataflow.","fork":false,"url":"https://api.github.com/repos/spotify/scio","forks_url":"https://api.github.com/repos/spotify/scio/forks","keys_url":"https://api.github.com/repos/spotify/scio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/spotify/scio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/spotify/scio/teams","hooks_url":"https://api.github.com/repos/spotify/scio/hooks","issue_events_url":"https://api.github.com/repos/spotify/scio/issues/events{/number}","events_url":"https://api.github.com/repos/spotify/scio/events","assignees_url":"https://api.github.com/repos/spotify/scio/assignees{/user}","branches_url":"https://api.github.com/repos/spotify/scio/branches{/branch}","tags_url":"https://api.github.com/repos/spotify/scio/tags","blobs_url":"https://api.github.com/repos/spotify/scio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/spotify/scio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/spotify/scio/git/refs{/sha}","trees_url":"https://api.github.com/repos/spotify/scio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/spotify/scio/statuses/{sha}","languages_url":"https://api.github.com/repos/spotify/scio/languages","stargazers_url":"https://api.github.com/repos/spotify/scio/stargazers","contributors_url":"https://api.github.com/repos/spotify/scio/contributors","subscribers_url":"https://api.github.com/repos/spotify/scio/subscribers","subscription_url":"https://api.github.com/repos/spotify/scio/subscription","commits_url":"https://api.github.com/repos/spotify/scio/commits{/sha}","git_commits_url":"https://api.github.com/repos/spotify/scio/git/commits{/sha}","comments_url":"https://api.github.com/repos/spotify/scio/comments{/number}","issue_comment_url":"https://api.github.com/repos/spotify/scio/issues/comments{/number}","contents_url":"https://api.github.com/repos/spotify/scio/contents/{+path}","compare_url":"https://api.github.com/repos/spotify/scio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/spotify/scio/merges","archive_url":"https://api.github.com/repos/spotify/scio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/spotify/scio/downloads","issues_url":"https://api.github.com/repos/spotify/scio/issues{/number}","pulls_url":"https://api.github.com/repos/spotify/scio/pulls{/number}","milestones_url":"https://api.github.com/repos/spotify/scio/milestones{/number}","notifications_url":"https://api.github.com/repos/spotify/scio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/spotify/scio/labels{/name}","releases_url":"https://api.github.com/repos/spotify/scio/releases{/id}","deployments_url":"https://api.github.com/repos/spotify/scio/deployments","created_at":"2015-03-26T19:07:34Z","updated_at":"2018-10-29T18:51:02Z","pushed_at":"2018-10-29T19:26:46Z","git_url":"git://github.com/spotify/scio.git","ssh_url":"git@github.com:spotify/scio.git","clone_url":"https://github.com/spotify/scio.git","svn_url":"https://github.com/spotify/scio","homepage":"https://spotify.github.io/scio","size":8752,"stargazers_count":1286,"watchers_count":1286,"language":"Scala","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":209,"mirror_url":null,"archived":false,"open_issues_count":42,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":209,"open_issues":42,"watchers":1286,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/spotify/scio/pulls/1491"},"html":{"href":"https://github.com/spotify/scio/pull/1491"},"issue":{"href":"https://api.github.com/repos/spotify/scio/issues/1491"},"comments":{"href":"https://api.github.com/repos/spotify/scio/issues/1491/comments"},"review_comments":{"href":"https://api.github.com/repos/spotify/scio/pulls/1491/comments"},"review_comment":{"href":"https://api.github.com/repos/spotify/scio/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/spotify/scio/pulls/1491/commits"},"statuses":{"href":"https://api.github.com/repos/spotify/scio/statuses/66ddf3346f0f95fa5a899e2f853dfd557b95508a"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"regadas"}}