bigquery: Ignore NeverExpire in Table.Create
NeverExpire should be used exclusively with Table.Update. If a caller
mistakenly passes NeverExpire as an expiration time when creating a
table, the client will do the right thing and refrain from setting an
expiration time.
This change is a minor addendum to
66c04be700bac6ceb900202c198cc32d86631243.
Change-Id: If294548d3d79b43d94e2f9601aa17d2dfd387d18
Reviewed-on: https://code-review.googlesource.com/c/34750
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
diff --git a/bigquery/table.go b/bigquery/table.go
index 52d1af0..00abd7d 100644
--- a/bigquery/table.go
+++ b/bigquery/table.go
@@ -331,7 +331,7 @@
}
t.TimePartitioning = tm.TimePartitioning.toBQ()
t.Clustering = tm.Clustering.toBQ()
- if !tm.ExpirationTime.IsZero() {
+ if !tm.ExpirationTime.IsZero() && tm.ExpirationTime != NeverExpire {
t.ExpirationTime = tm.ExpirationTime.UnixNano() / 1e6
}
if tm.ExternalDataConfig != nil {
@@ -444,8 +444,7 @@
return newRowIterator(ctx, t, pf)
}
-// NeverExpire is a sentinel value used with TableMetadataToUpdate's
-// ExpirationTime to indicate that a table should never expire.
+// NeverExpire is a sentinel value used to remove a table'e expiration time.
var NeverExpire = time.Time{}.Add(-1)
// Update modifies specific Table metadata fields.
diff --git a/bigquery/table_test.go b/bigquery/table_test.go
index 84e2e8f..d761f07 100644
--- a/bigquery/table_test.go
+++ b/bigquery/table_test.go
@@ -194,6 +194,10 @@
},
},
},
+ {
+ &TableMetadata{ExpirationTime: NeverExpire},
+ &bq.Table{ExpirationTime: 0},
+ },
} {
got, err := test.in.toBQ()
if err != nil {