Skip to content

Commit

Permalink
feat(bigquery): expose IsCaseInsensitive for dataset metadata (google…
Browse files Browse the repository at this point in the history
…apis#11216)

This PR exposes the existing IsCaseInsensitive property of dataset metadata, which affects the behavior of table names contained within a given dataset.
  • Loading branch information
shollyman authored Dec 4, 2024
1 parent d3de944 commit 364b639
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
16 changes: 16 additions & 0 deletions bigquery/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ type DatasetMetadata struct {
// More information: https://cloud.google.com/resource-manager/docs/tags/tags-overview
Tags []*DatasetTag

// TRUE if the dataset and its table names are case-insensitive, otherwise
// FALSE. By default, this is FALSE, which means the dataset and its table
// names are case-sensitive. This field does not affect routine references.
IsCaseInsensitive bool

// ETag is the ETag obtained when reading metadata. Pass it to Dataset.Update to
// ensure that the metadata hasn't changed since it was read.
ETag string
Expand Down Expand Up @@ -154,6 +159,11 @@ type DatasetMetadataToUpdate struct {
// The entire access list. It is not possible to replace individual entries.
Access []*AccessEntry

// TRUE if the dataset and its table names are case-insensitive, otherwise
// FALSE. By default, this is FALSE, which means the dataset and its table
// names are case-sensitive. This field does not affect routine references.
IsCaseInsensitive optional.Bool

labelUpdater
}

Expand Down Expand Up @@ -243,6 +253,7 @@ func (dm *DatasetMetadata) toBQ() (*bq.Dataset, error) {
ds.DefaultCollation = dm.DefaultCollation
ds.MaxTimeTravelHours = int64(dm.MaxTimeTravel / time.Hour)
ds.StorageBillingModel = string(dm.StorageBillingModel)
ds.IsCaseInsensitive = dm.IsCaseInsensitive
ds.Labels = dm.Labels
var err error
ds.Access, err = accessListToBQ(dm.Access)
Expand Down Expand Up @@ -385,6 +396,7 @@ func bqToDatasetMetadata(d *bq.Dataset, c *Client) (*DatasetMetadata, error) {
FullID: d.Id,
Location: d.Location,
Labels: d.Labels,
IsCaseInsensitive: d.IsCaseInsensitive,
ETag: d.Etag,
}
for _, a := range d.Access {
Expand Down Expand Up @@ -517,6 +529,10 @@ func (dm *DatasetMetadataToUpdate) toBQ() (*bq.Dataset, error) {
ds.NullFields = append(ds.NullFields, "Access")
}
}
if dm.IsCaseInsensitive != nil {
ds.IsCaseInsensitive = optional.ToBool(dm.IsCaseInsensitive)
forceSend("IsCaseInsensitive")
}
labels, forces, nulls := dm.update()
ds.Labels = labels
ds.ForceSendFields = append(ds.ForceSendFields, forces...)
Expand Down
14 changes: 11 additions & 3 deletions bigquery/dataset_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ func TestIntegration_DatasetUpdateDefaultCollation(t *testing.T) {
ctx := context.Background()
ds := client.Dataset(datasetIDs.New())
err := ds.Create(ctx, &DatasetMetadata{
DefaultCollation: caseSensitiveCollation,
DefaultCollation: caseSensitiveCollation,
IsCaseInsensitive: true,
})
if err != nil {
t.Fatal(err)
Expand All @@ -263,19 +264,26 @@ func TestIntegration_DatasetUpdateDefaultCollation(t *testing.T) {
t.Fatal(err)
}
if md.DefaultCollation != caseSensitiveCollation {
t.Fatalf("got %q, want %q", md.DefaultCollation, caseSensitiveCollation)
t.Fatalf("DefaultCollation: got %q, want %q", md.DefaultCollation, caseSensitiveCollation)
}
if md.IsCaseInsensitive != true {
t.Fatalf("IsCaseInsensitive: got %t, want %t", md.IsCaseInsensitive, true)
}

// Update the default collation
md, err = ds.Update(ctx, DatasetMetadataToUpdate{
DefaultCollation: caseInsensitiveCollation,
DefaultCollation: caseInsensitiveCollation,
IsCaseInsensitive: false,
}, "")
if err != nil {
t.Fatal(err)
}
if md.DefaultCollation != caseInsensitiveCollation {
t.Fatalf("got %q, want %q", md.DefaultCollation, caseInsensitiveCollation)
}
if md.IsCaseInsensitive != false {
t.Fatalf("IsCaseInsensitive: got %t, want %t", md.IsCaseInsensitive, false)
}

// Omitting DefaultCollation doesn't change it.
md, err = ds.Update(ctx, DatasetMetadataToUpdate{Name: "xyz"}, "")
Expand Down
24 changes: 15 additions & 9 deletions bigquery/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,9 @@ func TestDatasetToBQ(t *testing.T) {
Connection: "conn",
ExternalSource: "external_src",
},
Location: "EU",
Labels: map[string]string{"x": "y"},
Location: "EU",
Labels: map[string]string{"x": "y"},
IsCaseInsensitive: true,
Access: []*AccessEntry{
{Role: OwnerRole, Entity: "example.com", EntityType: DomainEntity},
{
Expand All @@ -356,8 +357,9 @@ func TestDatasetToBQ(t *testing.T) {
Connection: "conn",
ExternalSource: "external_src",
},
Location: "EU",
Labels: map[string]string{"x": "y"},
Location: "EU",
Labels: map[string]string{"x": "y"},
IsCaseInsensitive: true,
Access: []*bq.DatasetAccess{
{Role: "OWNER", Domain: "example.com"},
{
Expand Down Expand Up @@ -416,8 +418,9 @@ func TestBQToDatasetMetadata(t *testing.T) {
Connection: "conn",
ExternalSource: "external_src",
},
Location: "EU",
Labels: map[string]string{"x": "y"},
Location: "EU",
Labels: map[string]string{"x": "y"},
IsCaseInsensitive: true,
Access: []*bq.DatasetAccess{
{Role: "READER", UserByEmail: "joe@example.com"},
{Role: "READER",
Expand Down Expand Up @@ -464,6 +467,7 @@ func TestBQToDatasetMetadata(t *testing.T) {
StorageBillingModel: LogicalStorageBillingModel,
Location: "EU",
Labels: map[string]string{"x": "y"},
IsCaseInsensitive: true,
Access: []*AccessEntry{
{Role: ReaderRole,
Entity: "joe@example.com",
Expand Down Expand Up @@ -509,6 +513,7 @@ func TestDatasetMetadataToUpdateToBQ(t *testing.T) {
Name: "name",
DefaultTableExpiration: time.Hour,
DefaultPartitionExpiration: 24 * time.Hour,
IsCaseInsensitive: true,
MaxTimeTravel: time.Duration(181 * time.Minute),
StorageBillingModel: PhysicalStorageBillingModel,
DefaultEncryptionConfig: &EncryptionConfig{
Expand Down Expand Up @@ -541,9 +546,10 @@ func TestDatasetMetadataToUpdateToBQ(t *testing.T) {
Connection: "conn",
ExternalSource: "external_src",
},
Labels: map[string]string{"label": "value"},
ForceSendFields: []string{"Description", "FriendlyName", "ExternalDatasetReference", "StorageBillingModel"},
NullFields: []string{"Labels.del"},
Labels: map[string]string{"label": "value"},
IsCaseInsensitive: true,
ForceSendFields: []string{"Description", "FriendlyName", "ExternalDatasetReference", "StorageBillingModel", "IsCaseInsensitive"},
NullFields: []string{"Labels.del"},
}
if diff := testutil.Diff(got, want); diff != "" {
t.Errorf("-got, +want:\n%s", diff)
Expand Down

0 comments on commit 364b639

Please sign in to comment.