@@ -180,7 +180,8 @@ func ParsePDT(fq string) (PDT, error) {
180180
181181// UpdateTable will update an existing table. Returns error if the table
182182// doesn't already exist, or if the schema changes are incompatible.
183- func (pdt PDT ) UpdateTable (ctx context.Context , client * bigquery.Client , schema bigquery.Schema ) error {
183+ func (pdt PDT ) UpdateTable (ctx context.Context , client * bigquery.Client , schema bigquery.Schema ,
184+ partitioning * bigquery.TimePartitioning ) error {
184185 // See if dataset exists, or create it.
185186 ds := client .Dataset (pdt .Dataset )
186187 _ , err := ds .Metadata (ctx )
@@ -198,9 +199,14 @@ func (pdt PDT) UpdateTable(ctx context.Context, client *bigquery.Client, schema
198199 return err
199200 }
200201
202+ // If a partition field is set, enforce partition filtering.
203+ // This prevents unintentional full data scans on large tables.
204+ requirePartition := partitioning != nil && partitioning .Field != ""
205+
201206 // If table already exists, attempt to update the schema.
202207 changes := bigquery.TableMetadataToUpdate {
203- Schema : schema ,
208+ Schema : schema ,
209+ RequirePartitionFilter : requirePartition ,
204210 }
205211
206212 _ , err = t .Update (ctx , changes , meta .ETag )
@@ -225,11 +231,16 @@ func (pdt PDT) CreateTable(ctx context.Context, client *bigquery.Client, schema
225231
226232 t := ds .Table (pdt .Table )
227233
234+ // If a partition field is set, enforce partition filtering.
235+ // This prevents unintentional full data scans on large tables.
236+ requirePartition := partitioning != nil && partitioning .Field != ""
237+
228238 meta := & bigquery.TableMetadata {
229- Schema : schema ,
230- TimePartitioning : partitioning ,
231- Clustering : clustering ,
232- Description : description ,
239+ Schema : schema ,
240+ TimePartitioning : partitioning ,
241+ RequirePartitionFilter : requirePartition ,
242+ Clustering : clustering ,
243+ Description : description ,
233244 }
234245
235246 err := t .Create (ctx , meta )
0 commit comments