-
Notifications
You must be signed in to change notification settings - Fork 427
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
chore: Remove unused old implementation from snowflake pkg #2458
Conversation
sfc-gh-asawicki
commented
Feb 2, 2024
•
edited
Loading
edited
- Remove unused code from snowflake package
- Migrate datasources missed earlier
- Migrate small statements still using old package
Integration tests failure for 887f5e1466cf856b8c878490f6a8376c1d942e61 |
Integration tests failure for 004372c111fbec2037bb6649fa8d1f0f5259b0ff |
1 similar comment
Integration tests failure for 004372c111fbec2037bb6649fa8d1f0f5259b0ff |
Integration tests failure for ce142dcaa4ab0ae6155e86e8d30aa73bd728e28b |
pkg/datasources/resource_monitors.go
Outdated
|
||
account, err := snowflake.ReadCurrentAccount(db) | ||
account, err := client.ContextFunctions.Current(ctx) |
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 think this function should be named CurrentAccount() https://docs.snowflake.com/en/sql-reference/functions/current_account. Also should this be put in a helper struct so it can be something like client.Context.Sessions.CurrentAccount()? Or maybe just client.ContextSessions.CurrentAccount?
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 already have current account check another comment).
I don't understand the second part, though. It's already exposed in client's ContextFunctions interface.
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 don't have a proposal for the name other than client.ContextFunctions.SessionContext()
. Until we come up with a better name I don't mind staying with Current as only we are the users of the SDK.
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.
Renamed to CurrentSessionDetails (because CurrentSession was already taken too).
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, | ||
PreCheck: func() { acc.TestAccPreCheck(t) }, | ||
TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
tfversion.RequireAbove(tfversion.Version1_5_0), |
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.
eventually we should make this a configurable variable that can be set in one place and used everywhere. will allow us to upgrade required tf version as necessary
userPattern := d.Get("pattern").(string) | ||
|
||
account, err := snowflake.ReadCurrentAccount(db) | ||
if err != nil { | ||
account, err1 := client.ContextFunctions.CurrentAccount(ctx) |
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.
wait we already have CurrentAccount? Then what was the previous Current()? I don't see that anywhere in here: https://docs.snowflake.com/en/sql-reference/functions-context
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.
The problem is, we've already had a family of CurrentX()
functions. In the old snowflake package there was one method, fetching both account and region. To spare two invocation, I created a new one in the SDK, which fetches all these CurrentX params. We can name it differently if you have an idea how. CurrentAll? CurrentAccountAll? any ideas? cc: @sfc-gh-jcieslak
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.
if your concern is with multiple invocations, there is a way we can fix that by batching requests together. I don't know exactly how we would accomplish this, but it is worth thinking about.
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 was not a concern about the multiple invocations performance but the need to check the errors for each. Now, we fetch multiple values together, and I think it's easier to use it.
@@ -60,10 +62,12 @@ func UserPublicKeys() *schema.Resource { | |||
} | |||
|
|||
func checkUserExists(db *sql.DB, name string) (bool, error) { |
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.
this seems like a rather pointless function, we should probably remove this entirely. But not important right now
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 am not sure, but I tried not to modify the existing logic in this PR.
pkg/sdk/context_functions.go
Outdated
@@ -130,6 +159,21 @@ func (c *contextFunctions) CurrentUser(ctx context.Context) (string, error) { | |||
return s.CurrentUser, nil | |||
} | |||
|
|||
func (c *contextFunctions) Current(ctx context.Context) (*CurrentDetails, error) { |
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.
okay, i see now. Is this really necessary though? just because it was done in a similar way in the old snowflake package, doesn't mean we need to do it again here. also there are more current functions than just what is listed here.
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.
There are multiple times when we want to fetch both account and region, for me it is better to fetch all at once and not shoot for every single param.
pkg/datasources/resource_monitors.go
Outdated
|
||
account, err := snowflake.ReadCurrentAccount(db) | ||
account, err := client.ContextFunctions.Current(ctx) |
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 don't have a proposal for the name other than client.ContextFunctions.SessionContext()
. Until we come up with a better name I don't mind staying with Current as only we are the users of the SDK.
Integration tests failure for 89294266c45e1fb3a07c2f0587b2ffadf55d8fbb |
🤖 I have created a release *beep* *boop* --- # Release notes [0.86.0](v0.85.0...v0.86.0) (2024-02-15) ## 🎉 **What's new** * add refresh_mode and initialize to dynamic tables ([#2437](#2437)) ([d301b20](d301b20)) * add resource snowflake_user_password_policy_attachment ([#2162](#2162)) ([#2307](#2307)) ([93af462](93af462)) * create a workaround for granting privileges on all pipes ([#2477](#2477)) ([64f2346](64f2346)) * Handle IMPORTED PRIVILEGES privileges in privilege-to-role granting resources ([#2471](#2471)) ([eb20051](eb20051)) * use external functions ([#2454](#2454)) ([417d473](417d473)) * use funcs from sdk ([#2462](#2462)) ([a5f969c](a5f969c)) * use sdk for procedures ([#2450](#2450)) ([94ac78a](94ac78a)) * Use sdk in table constraint resource ([#2466](#2466)) ([d685603](d685603)) * Use tables from SDK ([#2453](#2453)) ([fdb4f88](fdb4f88)) ## 🔧 **Misc** * Add migration notes to the docs and change jira integration ([#2497](#2497)) ([b17f1af](b17f1af)) * Change email and issue reporter ([#2470](#2470)) ([5865655](5865655)) * Grants migration guide ([#2455](#2455)) ([62c70fd](62c70fd)) * Remove unused old implementation from snowflake pkg ([#2458](#2458)) ([2d0e508](2d0e508)) * update password policy attachment ([#2485](#2485)) ([6ec9ff7](6ec9ff7)) ## 🐛 **Bug fixes** * allow DT warehouse to be updated in-place ([#2439](#2439)) ([d565af1](d565af1)) * correct test dependencies ([#2493](#2493)) ([dfb247f](dfb247f)) * FileFormat not detecting changes correctly ([#2436](#2436)) ([018bb74](018bb74)) * Fix few smaller issues ([#2507](#2507)) ([a836871](a836871)) * Fix functions and small other fixes ([#2503](#2503)) ([0d4aba4](0d4aba4)), closes [#2490](#2490) * Fix tag tests in view and in materialized view ([#2457](#2457)) ([2de942a](2de942a)) * Fix task related issues ([#2479](#2479)) ([0385650](0385650)) * Fix tests that base on default data retention ([#2465](#2465)) ([682e28c](682e28c)) * grant privileges to share test terraform dependencies ([#2473](#2473)) ([ede8d95](ede8d95)) * parameter issues ([#2463](#2463)) ([7ee4986](7ee4986)) * parse dynamic table query from DDL ([#2438](#2438)) ([d76815c](d76815c)) * Remove title and body temporarily from jira integration ([#2499](#2499)) ([672c97d](672c97d)) * SHOW GRANTS mapping for share data type ([#2508](#2508)) ([feb4d44](feb4d44)) * user error handling ([#2486](#2486)) ([dfa52b2](dfa52b2)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: snowflake-release-please[bot] <105954990+snowflake-release-please[bot]@users.noreply.github.com>