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

Migrate to aws sdk v2 #325

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

Migrate to aws sdk v2 #325

wants to merge 7 commits into from

Conversation

njvrzm
Copy link
Contributor

@njvrzm njvrzm commented Dec 3, 2024

This is a proof of concept demonstration of migrating data sources' direct use of the aws-sdk-go from v1 to v2.

I've tested it with one provisioned datasource ("AWS Redshift assume role"). I haven't exercised it thoroughly yet but what I have tried - health check, simple query - does work.

@njvrzm njvrzm added the effort/medium 2 to 3 days label Dec 3, 2024
@njvrzm njvrzm self-assigned this Dec 3, 2024
@njvrzm njvrzm requested a review from a team as a code owner December 3, 2024 10:13
@njvrzm njvrzm requested review from iwysiu and nmarrs December 3, 2024 10:13
@njvrzm njvrzm requested review from idastambuk and removed request for nmarrs December 4, 2024 16:17
Copy link
Contributor

@iwysiu iwysiu left a comment

Choose a reason for hiding this comment

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

Overall looks good! There are some style nits in here (which I'm not sure how applicable they are for a POC) but nice to see that it works with the v2 sdk

return c.Stop(&api.ExecuteQueryOutput{ID: queryID})
}

func (c *API) Stop(output *api.ExecuteQueryOutput) error {
_, err := c.DataClient.CancelStatement(&redshiftdataapiservice.CancelStatementInput{
_, err := c.DataClient.CancelStatement(context.TODO(), &redshiftdata.CancelStatementInput{
Copy link
Contributor

Choose a reason for hiding this comment

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

Not in this commit but do you think we should we do a v2 of the async sdk that passes a context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that's a good idea!

res = append(res, *sc)
}
}
res = append(res, out.Databases...)
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume we're not worried about nil databases anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, this is one of quite a lot of places where the sdk v2 returns non-pointer values where v1 returned pointers...

@@ -183,7 +178,7 @@ func (r *Rows) Close() error {
func (r *Rows) fetchNextPage(token *string) error {
var err error

r.result, err = r.service.GetStatementResult(&redshiftdataapiservice.GetStatementResultInput{
r.result, err = r.service.GetStatementResult(context.TODO(), &redshiftdata.GetStatementResultInput{
Copy link
Contributor

Choose a reason for hiding this comment

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

could we pass a context into fetchNextPage? it looks like at least 1 of the places its called could.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could where it's called from newRows but not from what I think is the main user - the Next method on line 43 here, which implements an interface from sql/driver. Although - we could do the not-ideal thing of storing the context on our Rows struct. Since the Rows struct is tied to a particular query ID that's probably not a bad idea here...

ret[i] = nil
// FIXME: I think this is the correct translation of the existing behavior but I'm not
// sure it's actually the correct behavior
if isNull, ok := curr.(*redshiftdatatypes.FieldMemberIsNull); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can you do

Suggested change
if isNull, ok := curr.(*redshiftdatatypes.FieldMemberIsNull); ok {
if isNull, ok := curr.(*redshiftdataV2types.FieldMemberIsNull); ok && isNull.Value {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking back, yeah, that is actually a more accurate translation. I'm still not sure it's the right thing to do, but it's at least the samest thing to do :)

@njvrzm njvrzm force-pushed the njvrzm/migrate_to_aws_sdk_v2 branch from 49b48fa to ffdcd29 Compare December 17, 2024 10:27
@idastambuk
Copy link
Contributor

Built it and clicked around a bit and everything looks good! Tried it with access & secret key and assume role datasources Resource calls as well as queries work fine.

@njvrzm njvrzm force-pushed the njvrzm/migrate_to_aws_sdk_v2 branch from 5ba4b4a to d7fd505 Compare January 2, 2025 14:25
@njvrzm njvrzm force-pushed the njvrzm/migrate_to_aws_sdk_v2 branch from 7db51ed to 468dd32 Compare January 8, 2025 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/medium 2 to 3 days
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants