-
Notifications
You must be signed in to change notification settings - Fork 418
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
base: main
Are you sure you want to change the base?
feat: Upgrade tag SDK #3126
Conversation
Integration tests failure for 424b47af067b90540fd2c61a1d0ae3c058ca4fea |
Integration tests cancelled for 651c4e36cd88317fcbd19030f713ef50522c4ad0 |
Integration tests cancelled for acb0981ae15561392c73f553800c16f1a293794b |
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about dynamic table?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 za posprzatanie setupu
Test Plan
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