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: Upgrade tag SDK #3126

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

feat: Upgrade tag SDK #3126

wants to merge 5 commits into from

Conversation

sfc-gh-jmichalak
Copy link
Collaborator

@sfc-gh-jmichalak sfc-gh-jmichalak commented Oct 10, 2024

Test Plan

  • integration tests
  • unit tests

References

https://docs.snowflake.com/en/sql-reference/sql/create-tag
https://docs.snowflake.com/en/user-guide/object-tagging
https://docs.snowflake.com/en/sql-reference/functions/system_get_tag

TODO

  • change GetTag to not fail on null values
  • move tag assignments integration tests to a common place
  • rework tag, tag_association resource
  • remove tag_masking_policy_association_resource (tag_association will be used instead)

Copy link

Integration tests failure for 424b47af067b90540fd2c61a1d0ae3c058ca4fea

Copy link

Integration tests cancelled for 651c4e36cd88317fcbd19030f713ef50522c4ad0

Copy link

Integration tests cancelled for acb0981ae15561392c73f553800c16f1a293794b

@sfc-gh-jmichalak sfc-gh-jmichalak marked this pull request as ready for review October 11, 2024 14:11
Copy link

Integration tests failure for 47b9ac5dec645cea701af0885eb5b790ea5a0117

@@ -47,6 +47,7 @@ var tagSchema = map[string]*schema.Schema{
FullyQualifiedNameAttributeName: schemas.FullyQualifiedNameSchema,
}

// TODO: remove after rework of external table, materialized view, stage and table
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe let's create a ticket for it, assign it to this todo, and set the dependencies of listed reworks on this ticket. Otherwise there's a big chance we'll just forget about it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just add this point to each resource dedicated task (so link here three issues)

ObjectTypeAlert,
ObjectTypeBudget,
ObjectTypeClassification,
ObjectTypeExternalFunction,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could create a test that would go through all the object types to see which ones are valid ones, I just checked that, e.g. dynamic tables can also be used (with table data type ofc).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for such a test

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's related to #3126 (comment) - I can do this in the next PR.

@@ -25,6 +25,7 @@ const (
ObjectTypeNetworkPolicy ObjectType = "NETWORK POLICY"
ObjectTypePasswordPolicy ObjectType = "PASSWORD POLICY"
ObjectTypeSessionPolicy ObjectType = "SESSION POLICY"
ObjectTypePrivacyPolicy ObjectType = "PRIVACY POLICY"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sdk.ObjectType is used in more places than just tagging, are we sure, that we do not break other resources by adding it (e.g. grants)?

// SQL compilation error: Invalid value VIEW for argument OBJECT_TYPE. Please use object type TABLE for all kinds of table-like objects.
// TODO [SNOW-1022645]: discuss how we handle situation like this in the SDK
func normalizeGetTagObjectType(objectType ObjectType) ObjectType {
if slices.Contains([]ObjectType{ObjectTypeView, ObjectTypeMaterializedView, ObjectTypeExternalTable}, objectType) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about dynamic table?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially, I missed dynamic tables because they are missing from https://docs.snowflake.com/en/user-guide/object-tagging. Managing dynamic tables is not implemented in the SDK. I just checked it manually, and it turns out you can use GetTag with dynamic table as an argument.

// tv, err := client.SystemFunctions.GetTag(ctx, tagTest.ID(), id, sdk.ObjectTypeApplication)
// require.NoError(t, err)
// assert.Equal(t, "v1", tv)
// TODO: adjust after this is fixed on Snowflake side
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have any trackable issue? let's create one and like it here

tagTest.ID(),
},
})
require.NoError(t, err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can check if the GetTag return no tag after.

@@ -194,6 +195,33 @@ func TestInt_ExternalFunctions(t *testing.T) {
assertExternalFunction(t, externalFunction.ID(), true)
})

t.Run("alter external function: set and unset tags", func(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead adding such a func to each object, we could extract one integration test with parametrized setup and run it for all objects instead? (I know that currently we had setting/unsetting tags in each object but with the rework, we can pick more centralized approach)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do it in the next PR.

@@ -326,7 +326,7 @@ func TestInt_MaterializedViews(t *testing.T) {
err := client.Views.Alter(ctx, alterRequestSetTags)
require.NoError(t, err)

returnedTagValue, err := client.SystemFunctions.GetTag(ctx, tag.ID(), id, sdk.ObjectTypeTable)
returnedTagValue, err := client.SystemFunctions.GetTag(ctx, tag.ID(), id, sdk.ObjectTypeMaterializedView)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why in some tests we check for err nil and in some we also validate the tag's value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because when a tag is not set, GetTag returns an error. I'd like to change this, so that nil is returned as a tag value in the next PR.


s, err := client.Schemas.ShowByID(ctx, schemaID)
require.NoError(t, err)
schema, cleanupSchema := testClientHelper().Schema.CreateSchema(t)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 za posprzatanie setupu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants