Skip to content

Commit

Permalink
Add isDML check to runDML
Browse files Browse the repository at this point in the history
  • Loading branch information
fallonchen committed Apr 3, 2023
1 parent f087369 commit 773eeb6
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.google.api.client.googleapis.json.GoogleJsonResponseException
import com.google.api.services.bigquery.model.{TableReference, TableSchema}
import com.google.cloud.hadoop.util.ApiErrorExtractor
import com.spotify.scio.bigquery.client.BigQuery
import com.spotify.scio.bigquery.client.BigQuery.isDML
import com.spotify.scio.bigquery.types.BigQueryType.HasAnnotation
import org.apache.beam.sdk.io.gcp.bigquery.BigQueryHelpers

Expand Down Expand Up @@ -125,6 +126,8 @@ class MockBigQuery private (private val bq: BigQuery) {

/** Run live DML statement against BigQuery service, substituting mocked tables with test data. */
def runDML(dmlStatement: String): TableReference = {
require(isDML(dmlStatement), s"Expecting DML statement but got '$dmlStatement'")

val isLegacy = bq.query.isLegacySql(dmlStatement)
val mockDml = mapping.foldLeft(dmlStatement) { case (q, (src, dst)) =>
q.replace(toTableSpec(src, isLegacy), toTableSpec(dst, isLegacy))
Expand Down

0 comments on commit 773eeb6

Please sign in to comment.