Skip to content

Commit f9c02ac

Browse files
author
Michel Davit
committed
Strict table expectation on export API
1 parent 513118f commit f9c02ac

File tree

2 files changed

+24
-37
lines changed

2 files changed

+24
-37
lines changed

scio-google-cloud-platform/src/main/scala/com/spotify/scio/bigquery/BigQueryTypes.scala

+16
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,22 @@ case class Table private (ref: GTableReference, filter: Option[Table.Filter]) ex
130130
}
131131

132132
object Table {
133+
134+
/**
135+
* @param selectedFields
136+
* names of the fields in the table that should be read. If empty, all fields will be read. If
137+
* the specified field is a nested field, all the sub-fields in the field will be selected.
138+
* Fields will always appear in the generated class in the same order as they appear in the
139+
* table, regardless of the order specified in selectedFields.
140+
* @param rowRestriction
141+
* SQL text filtering statement, similar ti a WHERE clause in a query. Currently, we support
142+
* combinations of predicates that are a comparison between a column and a constant value in SQL
143+
* statement. Aggregates are not supported. For example:
144+
*
145+
* {{{
146+
* "a > DATE '2014-09-27' AND (b > 5 AND c LIKE 'date')"
147+
* }}}
148+
*/
133149
final case class Filter(
134150
selectedFields: List[String],
135151
rowRestriction: Option[String]

scio-google-cloud-platform/src/main/scala/com/spotify/scio/bigquery/syntax/ScioContextSyntax.scala

+8-37
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,9 @@ import org.apache.beam.sdk.io.Compression
3030
import org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO.TypedRead.Method
3131
import org.apache.beam.sdk.io.fs.EmptyMatchTreatment
3232
import org.apache.beam.sdk.transforms.errorhandling.{BadRecord, ErrorHandler}
33-
import org.slf4j.{Logger, LoggerFactory}
34-
35-
object ScioContextOps {
36-
@transient private lazy val logger: Logger = LoggerFactory.getLogger(this.getClass)
37-
}
3833

3934
/** Enhanced version of [[ScioContext]] with BigQuery methods. */
4035
final class ScioContextOps(private val self: ScioContext) extends AnyVal {
41-
import ScioContextOps._
4236

4337
/**
4438
* Get an SCollection for a BigQuery SELECT query. Both
@@ -85,13 +79,10 @@ final class ScioContextOps(private val self: ScioContext) extends AnyVal {
8579
configOverride: BigQueryIO.ReadParam.ConfigOverride[TableRow] =
8680
BigQueryIO.ReadParam.DefaultConfigOverride
8781
): SCollection[TableRow] = {
88-
if (table.filter.nonEmpty) {
89-
logger.warn(
90-
"Using filtered table with standard API. " +
91-
"selectedFields and rowRestriction are ignored. " +
92-
"Use bigQueryStorage instead"
93-
)
94-
}
82+
require(
83+
table.filter.isEmpty,
84+
"Cannot use filtered table with standard API. Use bigQueryStorage instead"
85+
)
9586
val params = BigQueryIO.TableReadParam(
9687
BigQueryIO.Format.Default(),
9788
Method.DEFAULT,
@@ -107,13 +98,10 @@ final class ScioContextOps(private val self: ScioContext) extends AnyVal {
10798
configOverride: BigQueryIO.ReadParam.ConfigOverride[T] =
10899
BigQueryIO.ReadParam.DefaultConfigOverride
109100
): SCollection[T] = {
110-
if (table.filter.nonEmpty) {
111-
logger.warn(
112-
"Using filtered table with standard API. " +
113-
"selectedFields and rowRestriction are ignored. " +
114-
"Use bigQueryStorage instead"
115-
)
116-
}
101+
require(
102+
table.filter.isEmpty,
103+
"Cannot use filtered table with standard API. Use bigQueryStorage instead"
104+
)
117105
val params = BigQueryIO.TableReadParam(
118106
format,
119107
Method.DEFAULT,
@@ -123,23 +111,6 @@ final class ScioContextOps(private val self: ScioContext) extends AnyVal {
123111
self.read(BigQueryIO[T](table))(params)
124112
}
125113

126-
/**
127-
* Get an SCollection for a BigQuery table using the storage API.
128-
*
129-
* @param selectedFields
130-
* names of the fields in the table that should be read. If empty, all fields will be read. If
131-
* the specified field is a nested field, all the sub-fields in the field will be selected.
132-
* Fields will always appear in the generated class in the same order as they appear in the
133-
* table, regardless of the order specified in selectedFields.
134-
* @param rowRestriction
135-
* SQL text filtering statement, similar ti a WHERE clause in a query. Currently, we support
136-
* combinations of predicates that are a comparison between a column and a constant value in SQL
137-
* statement. Aggregates are not supported. For example:
138-
*
139-
* {{{
140-
* "a > DATE '2014-09-27' AND (b > 5 AND c LIKE 'date')"
141-
* }}}
142-
*/
143114
def bigQueryStorage(
144115
table: Table,
145116
errorHandler: ErrorHandler[BadRecord, _] = BigQueryIO.ReadParam.DefaultErrorHandler,

0 commit comments

Comments
 (0)