bigquery: add Location to TableMetadata.
Location is available on table metadata from the encapsulating dataset.
It cannot be set as part of table creation, nor updated.
Change-Id: I0e37e013ba7fb015e1104a6fd069b49735f717de
Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/49910
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Cody Oss <codyoss@google.com>
diff --git a/bigquery/integration_test.go b/bigquery/integration_test.go
index cc5e33b..8d1cb79 100644
--- a/bigquery/integration_test.go
+++ b/bigquery/integration_test.go
@@ -2134,6 +2134,18 @@
if err != nil {
t.Fatal(err)
}
+
+ tableMetadata, err := table.Metadata(ctx)
+ if err != nil {
+ t.Fatalf("failed to get table metadata: %v", err)
+ }
+ wantLoc := loc
+ if loc == "" && client.Location != "" {
+ wantLoc = client.Location
+ }
+ if tableMetadata.Location != wantLoc {
+ t.Errorf("Location on table doesn't match. Got %s want %s", tableMetadata.Location, wantLoc)
+ }
defer table.Delete(ctx)
loader := table.LoaderFrom(NewReaderSource(strings.NewReader("a,0\nb,1\nc,2\n")))
loader.Location = loc
diff --git a/bigquery/table.go b/bigquery/table.go
index dcea1d3..e5e2c4e 100644
--- a/bigquery/table.go
+++ b/bigquery/table.go
@@ -45,6 +45,9 @@
// The user-friendly name for the table.
Name string
+ // Output-only location of the table, based on the encapsulating dataset.
+ Location string
+
// The user-friendly description of the table.
Description string
@@ -479,6 +482,7 @@
md := &TableMetadata{
Description: t.Description,
Name: t.FriendlyName,
+ Location: t.Location,
Type: TableType(t.Type),
FullID: t.Id,
Labels: t.Labels,
diff --git a/bigquery/table_test.go b/bigquery/table_test.go
index dad4189..8a0f2f7 100644
--- a/bigquery/table_test.go
+++ b/bigquery/table_test.go
@@ -68,6 +68,7 @@
&TableMetadata{
Description: "desc",
Name: "fname",
+ Location: "loc",
ViewQuery: "view-query",
FullID: "id",
Type: ExternalTable,