-
Notifications
You must be signed in to change notification settings - Fork 322
feat: enable unsetting policy tags on schema fields #703
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -653,6 +653,56 @@ def test_update_table_schema(self): | |
| self.assertEqual(found.field_type, expected.field_type) | ||
| self.assertEqual(found.mode, expected.mode) | ||
|
|
||
| def test_unset_table_schema_attributes(self): | ||
| from google.cloud.bigquery.schema import PolicyTagList | ||
|
|
||
| dataset = self.temp_dataset(_make_dataset_id("unset_policy_tags")) | ||
| table_id = "test_table" | ||
| policy_tags = PolicyTagList( | ||
| names=[ | ||
| "projects/{}/locations/us/taxonomies/1/policyTags/2".format( | ||
| Config.CLIENT.project | ||
| ), | ||
| ] | ||
| ) | ||
|
|
||
| schema = [ | ||
| bigquery.SchemaField("full_name", "STRING", mode="REQUIRED"), | ||
| bigquery.SchemaField( | ||
| "secret_int", | ||
| "INTEGER", | ||
| mode="REQUIRED", | ||
| description="This field is numeric", | ||
| policy_tags=policy_tags, | ||
| ), | ||
| ] | ||
| table_arg = Table(dataset.table(table_id), schema=schema) | ||
| self.assertFalse(_table_exists(table_arg)) | ||
|
|
||
| table = helpers.retry_403(Config.CLIENT.create_table)(table_arg) | ||
| self.to_delete.insert(0, table) | ||
|
|
||
| self.assertTrue(_table_exists(table)) | ||
| self.assertEqual(policy_tags, table.schema[1].policy_tags) | ||
|
|
||
| # Amend the schema to replace the policy tags | ||
| new_schema = table.schema[:] | ||
| old_field = table.schema[1] | ||
| new_schema[1] = bigquery.SchemaField( | ||
| name=old_field.name, | ||
| field_type=old_field.field_type, | ||
| mode=old_field.mode, | ||
| description=None, | ||
| fields=old_field.fields, | ||
| policy_tags=None, | ||
| ) | ||
|
|
||
| table.schema = new_schema | ||
| updated_table = Config.CLIENT.update_table(table, ["schema"]) | ||
|
|
||
| self.assertFalse(updated_table.schema[1].description) # Empty string or None. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed there's a difference between when if description is not set (or set to In any case, it is possible to override the existing description, thus no extra code changes necessary for this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this matters. In fact, it's what requested in #558 (comment)
|
||
| self.assertEqual(updated_table.schema[1].policy_tags.names, ()) | ||
|
|
||
| def test_update_table_clustering_configuration(self): | ||
| dataset = self.temp_dataset(_make_dataset_id("update_table")) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.