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

feat(bigquery): add table resource tags support #9084

Merged
merged 8 commits into from
Dec 14, 2023

Conversation

shollyman
Copy link
Contributor

@shollyman shollyman commented Dec 6, 2023

This PR adds support for resource tags on BigQuery tables.

Due to the nature of the feature, testing necessitates special provisioning with resourcemanager to establish a parent with the proper keys and values defined, which can then be bound to the table.

While implementing, testing was done in a personal test project, with the following commands to establish the necessary tags/values:

gcloud resource-manager tags keys create test_tag_key --parent=projects/shollyman-testing

gcloud resource-manager tags values create COFFEE --parent=tagKeys/281483438148747
gcloud resource-manager tags values create TEA --parent=tagKeys/281483438148747
gcloud resource-manager tags values create WATER --parent=tagKeys/281483438148747

This integration test was used to smoke test that the feature works:

func TestIntegration_TableResourceTags(t *testing.T) {
	if client == nil {
		t.Skip("Integration tests skipped")
	}

	testKey := "shollyman-testing/test_tag_key"

	ctx := context.Background()
	table := dataset.Table(tableIDs.New())
	resourceTags := map[string]string{
		testKey: "COFFEE",
	}
	if err := table.Create(context.Background(), &TableMetadata{
		Schema:       schema,
		ResourceTags: resourceTags,
	}); err != nil {
		t.Fatalf("table.Create: %v", err)
	}
	defer table.Delete(ctx)
	md, err := table.Metadata(ctx)
	if err != nil {
		t.Fatalf("table.Metadata: %v", err)
	}

	var found bool
	for k, v := range md.ResourceTags {
		if k == testKey && v == "COFFEE" {
			found = true
			break
		}
	}
	if !found {
		t.Errorf("tag key/value not found")
	}

	updatedTags := map[string]string{
		testKey: "COFFEE",
	}
	// Update table DefaultCollation to case-sensitive
	updated, err := table.Update(ctx, TableMetadataToUpdate{
		ResourceTags: updatedTags,
	}, md.ETag)
	if err != nil {
		t.Fatalf("table.Update: %v", err)
	}

	found = false
	for k, v := range updated.ResourceTags {
		if k == testKey && v == "COFFEE" {
			found = true
			break
		}
	}
	if !found {
		t.Errorf("tag key/value not found")
	}

}

I've removed the integration test for the time being after verification, given the complexity of the setup outside of the BQ service.

@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: bigquery Issues related to the BigQuery API. labels Dec 6, 2023
@shollyman shollyman added the automerge Merge the pull request once unit tests and other checks pass. label Dec 14, 2023
@gcf-merge-on-green gcf-merge-on-green bot merged commit 3569cc2 into googleapis:main Dec 14, 2023
9 checks passed
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Dec 14, 2023
@shollyman shollyman deleted the more-table-tags branch December 14, 2023 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the BigQuery API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants