Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,32 @@
package com.spotify.scio.bigquery

import java.util.UUID

import com.google.api.client.googleapis.json.GoogleJsonResponseException
import com.google.api.services.bigquery.model.{TableFieldSchema, TableSchema}
import com.google.cloud.storage.Storage.BlobListOption
import com.google.cloud.storage.{Blob, StorageOptions}
import com.spotify.scio.bigquery.client.{BigQuery, ParquetCompression}
import org.apache.beam.sdk.io.gcp.bigquery.BigQueryHelpers
import org.scalatest.BeforeAndAfterAll
import org.scalatest.matchers.should.Matchers
import org.scalatest.flatspec.AnyFlatSpec

import scala.jdk.CollectionConverters._
import scala.util.Success
import scala.util.{Success, Try}

// integration/runMain com.spotify.scio.PopulateTestData to re-populate data for integration tests
class BigQueryClientIT extends AnyFlatSpec with Matchers {
class BigQueryClientIT extends AnyFlatSpec with Matchers with BeforeAndAfterAll {
private[this] val bq = BigQuery.defaultInstance()

val legacyQuery =
"SELECT word, word_count FROM [bigquery-public-data:samples.shakespeare] LIMIT 10"
val sqlQuery =
"SELECT word, word_count FROM `bigquery-public-data.samples.shakespeare` LIMIT 10"

// First BQ service call fails on GHA; see https://github.com/spotify/scio/issues/5702
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment to #5702 that it seems to be more of a github actions issue and not the code itself

override protected def beforeAll(): Unit =
Try(bq.query.rows(sqlQuery).toList)

"QueryService.run" should "run DML queries" in {
val schema =
BigQueryUtil.parseSchema("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ package com.spotify.scio.bigquery.types
import com.google.api.services.bigquery.model.TableReference
import com.spotify.scio.bigquery.client.BigQuery
import com.spotify.scio.bigquery.{Query, Table}
import org.scalatest.Assertion
import org.scalatest.{Assertion, BeforeAndAfterAll}
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

import scala.annotation.StaticAnnotation
import scala.jdk.CollectionConverters._
import scala.reflect.runtime.universe._
import scala.util.Try

object BigQueryTypeIT {
@BigQueryType.fromQuery(
Expand Down Expand Up @@ -88,7 +89,7 @@ object BigQueryTypeIT {
}

// integration/runMain com.spotify.scio.PopulateTestData to re-populate data for integration tests
class BigQueryTypeIT extends AnyFlatSpec with Matchers {
class BigQueryTypeIT extends AnyFlatSpec with Matchers with BeforeAndAfterAll {
import BigQueryTypeIT._

val bq: BigQuery = BigQuery.defaultInstance()
Expand All @@ -102,6 +103,10 @@ class BigQueryTypeIT extends AnyFlatSpec with Matchers {
val sqlLatestQuery =
"SELECT word, word_count FROM `data-integration-test.partition_a.table_%s`"

// First BQ service call fails on GHA; see https://github.com/spotify/scio/issues/5702
override protected def beforeAll(): Unit =
Try(bq.query.rows(sqlQuery).toList)

"fromQuery" should "work with legacy syntax" in {
val bqt = BigQueryType[LegacyT]
bqt.isQuery shouldBe true
Expand All @@ -128,17 +133,15 @@ class BigQueryTypeIT extends AnyFlatSpec with Matchers {
fields.map(_.getMode) shouldBe Seq("NULLABLE", "NULLABLE")
}

// Ignore persistent test failure: see https://github.com/spotify/scio/issues/5702
ignore should "round trip rows with legacy syntax" in {
it should "round trip rows with legacy syntax" in {
val bqt = BigQueryType[LegacyT]
val rows = bq.query.rows(legacyQuery).toList
val typed = Seq(LegacyT("Romeo", 117L))
rows.map(bqt.fromTableRow) shouldBe typed
typed.map(bqt.toTableRow).map(bqt.fromTableRow) shouldBe typed
}

// Ignore persistent test failure: see https://github.com/spotify/scio/issues/5702
ignore should "round trip rows with SQL syntax" in {
it should "round trip rows with SQL syntax" in {
val bqt = BigQueryType[SqlT]
val rows = bq.query.rows(sqlQuery).toList
val typed = Seq(SqlT(Some("Romeo"), Some(117L)))
Expand Down
Loading