Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(bigquery): amend name for MaxTimeTravel on datasets #7707

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions bigquery/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ type DatasetMetadata struct {
// More information: https://cloud.google.com/bigquery/docs/reference/standard-sql/collation-concepts
DefaultCollation string

// MaxTimeTravelHours represents the number of hours for the max time travel for all tables
// MaxTimeTravel represents the number of hours for the max time travel for all tables
// in the dataset. Durations are rounded towards zero for the nearest hourly value.
MaxTimeTravelHours time.Duration
MaxTimeTravel time.Duration

// Storage billing model to be used for all tables in the dataset.
// Can be set to PHYSICAL. Default is LOGICAL.
Expand Down Expand Up @@ -135,9 +135,9 @@ type DatasetMetadataToUpdate struct {
// created in the dataset.
DefaultCollation optional.String

// MaxTimeTravelHours represents the number of hours for the max time travel for all tables
// MaxTimeTravel represents the number of hours for the max time travel for all tables
// in the dataset. Durations are rounded towards zero for the nearest hourly value.
MaxTimeTravelHours optional.Duration
MaxTimeTravel optional.Duration

// Storage billing model to be used for all tables in the dataset.
// Can be set to PHYSICAL. Default is LOGICAL.
Expand Down Expand Up @@ -216,7 +216,7 @@ func (dm *DatasetMetadata) toBQ() (*bq.Dataset, error) {
ds.DefaultTableExpirationMs = int64(dm.DefaultTableExpiration / time.Millisecond)
ds.DefaultPartitionExpirationMs = int64(dm.DefaultPartitionExpiration / time.Millisecond)
ds.DefaultCollation = dm.DefaultCollation
ds.MaxTimeTravelHours = int64(dm.MaxTimeTravelHours / time.Hour)
ds.MaxTimeTravelHours = int64(dm.MaxTimeTravel / time.Hour)
ds.StorageBillingModel = string(dm.StorageBillingModel)
ds.Labels = dm.Labels
var err error
Expand Down Expand Up @@ -304,7 +304,7 @@ func bqToDatasetMetadata(d *bq.Dataset, c *Client) (*DatasetMetadata, error) {
DefaultTableExpiration: time.Duration(d.DefaultTableExpirationMs) * time.Millisecond,
DefaultPartitionExpiration: time.Duration(d.DefaultPartitionExpirationMs) * time.Millisecond,
DefaultCollation: d.DefaultCollation,
MaxTimeTravelHours: time.Duration(d.MaxTimeTravelHours) * time.Hour,
MaxTimeTravel: time.Duration(d.MaxTimeTravelHours) * time.Hour,
StorageBillingModel: d.StorageBillingModel,
DefaultEncryptionConfig: bqToEncryptionConfig(d.DefaultEncryptionConfiguration),
Description: d.Description,
Expand Down Expand Up @@ -395,8 +395,8 @@ func (dm *DatasetMetadataToUpdate) toBQ() (*bq.Dataset, error) {
ds.DefaultCollation = optional.ToString(dm.DefaultCollation)
forceSend("DefaultCollation")
}
if dm.MaxTimeTravelHours != nil {
dur := optional.ToDuration(dm.MaxTimeTravelHours)
if dm.MaxTimeTravel != nil {
dur := optional.ToDuration(dm.MaxTimeTravel)
if dur == 0 {
// Send a null to delete the field.
ds.NullFields = append(ds.NullFields, "MaxTimeTravelHours")
Expand Down
6 changes: 3 additions & 3 deletions bigquery/dataset_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,16 @@ func TestIntegration_DatasetUpdateDefaultExpirationAndMaxTimeTravel(t *testing.T
// Set the default expiration time.
md, err := dataset.Update(ctx, DatasetMetadataToUpdate{
DefaultTableExpiration: wantExpiration,
MaxTimeTravelHours: wantTimeTravel,
MaxTimeTravel: wantTimeTravel,
}, "")
if err != nil {
t.Fatal(err)
}
if got := md.DefaultTableExpiration; got != wantExpiration {
t.Fatalf("DefaultTableExpiration want %s got %s", wantExpiration, md.DefaultTableExpiration)
}
if got := md.MaxTimeTravelHours; got != wantTimeTravel {
t.Fatalf("MaxTimeTravelHours want %s got %s", wantTimeTravel, md.MaxTimeTravelHours)
if got := md.MaxTimeTravel; got != wantTimeTravel {
t.Fatalf("MaxTimeTravelHours want %s got %s", wantTimeTravel, md.MaxTimeTravel)
}
// Omitting DefaultTableExpiration doesn't change it.
md, err = dataset.Update(ctx, DatasetMetadataToUpdate{Name: "xyz"}, "")
Expand Down
6 changes: 3 additions & 3 deletions bigquery/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func TestDatasetToBQ(t *testing.T) {
Name: "name",
Description: "desc",
DefaultTableExpiration: time.Hour,
MaxTimeTravelHours: time.Duration(181 * time.Minute),
MaxTimeTravel: time.Duration(181 * time.Minute),
DefaultPartitionExpiration: 24 * time.Hour,
DefaultEncryptionConfig: &EncryptionConfig{
KMSKeyName: "some_key",
Expand Down Expand Up @@ -431,7 +431,7 @@ func TestBQToDatasetMetadata(t *testing.T) {
Name: "name",
Description: "desc",
DefaultTableExpiration: time.Hour,
MaxTimeTravelHours: time.Duration(3 * time.Hour),
MaxTimeTravel: time.Duration(3 * time.Hour),
DefaultPartitionExpiration: 24 * time.Hour,
DefaultEncryptionConfig: &EncryptionConfig{
KMSKeyName: "some_key",
Expand Down Expand Up @@ -471,7 +471,7 @@ func TestDatasetMetadataToUpdateToBQ(t *testing.T) {
Name: "name",
DefaultTableExpiration: time.Hour,
DefaultPartitionExpiration: 24 * time.Hour,
MaxTimeTravelHours: time.Duration(181 * time.Minute),
MaxTimeTravel: time.Duration(181 * time.Minute),
StorageBillingModel: PhysicalStorageBillingModel,
DefaultEncryptionConfig: &EncryptionConfig{
KMSKeyName: "some_key",
Expand Down