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

Stage provider support amazon, minio and COS #18839

Merged
merged 3 commits into from
Sep 18, 2024

Conversation

cpegeric
Copy link
Contributor

@cpegeric cpegeric commented Sep 18, 2024

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue # #18837

What this PR does / why we need it:

  1. Remove the check that the provider only supports minio.
  2. add 'COS' and 'AMAZON' provider support.

Copy link

PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

PR Reviewer Guide 🔍

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Key issues to review

Incomplete Provider Support
The getS3ServiceFromProvider function now supports 'cos', 'amazon', and 'minio', but it doesn't handle unsupported providers. Consider adding a default case to return an error for unsupported providers.

Potential Bug
The removal of the provider check might allow unsupported providers. Ensure that this change doesn't introduce unexpected behavior with other providers.

@matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label Sep 18, 2024
@mergify mergify bot added the kind/bug Something isn't working label Sep 18, 2024
Copy link

PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

PR Code Suggestions ✨

CategorySuggestion                                                                                                                                    Score
Enhancement
Add a test case for an unsupported provider to ensure error handling

Consider adding a test case for an unsupported provider to ensure the function
handles errors correctly.

pkg/sql/plan/function/stage_test.go [25-38]

 func TestS3ServiceProvider(t *testing.T) {
   protocol, err := getS3ServiceFromProvider("cos")
   require.Nil(t, err)
   assert.Equal(t, protocol, "s3")
 
   protocol, err = getS3ServiceFromProvider("amazon")
   require.Nil(t, err)
   assert.Equal(t, protocol, "s3")
 
   protocol, err = getS3ServiceFromProvider("minio")
   require.Nil(t, err)
   assert.Equal(t, protocol, "minio")
 
+  _, err = getS3ServiceFromProvider("unsupported")
+  assert.Error(t, err)
 }
 
  • Apply this suggestion
Suggestion importance[1-10]: 9

Why: Adding a test case for an unsupported provider is crucial for ensuring robust error handling, which is a significant improvement in testing completeness.

9
Use a map for provider-to-service mapping to improve scalability and maintainability

Consider using a map for provider-to-service mapping to make the function more
scalable and easier to maintain.

pkg/sql/plan/function/stage_util.go [155-163]

+var providerServiceMap = map[string]string{
+  S3_PROVIDER_COS:    S3_SERVICE,
+  S3_PROVIDER_AMAZON: S3_SERVICE,
+  S3_PROVIDER_MINIO:  MINIO_SERVICE,
+}
+
 func getS3ServiceFromProvider(provider string) (string, error) {
   provider = strings.ToLower(provider)
-  switch provider {
-  case S3_PROVIDER_COS:
-    return S3_SERVICE, nil
-  case S3_PROVIDER_AMAZON:
-    return S3_SERVICE, nil
-  case S3_PROVIDER_MINIO:
-    return MINIO_SERVICE, nil
+  if service, ok := providerServiceMap[provider]; ok {
+    return service, nil
+  }
+  return "", fmt.Errorf("unsupported provider: %s", provider)
+}
 
  • Apply this suggestion
Suggestion importance[1-10]: 8

Why: Using a map for provider-to-service mapping simplifies the code and improves scalability and maintainability, which is a valuable enhancement.

8
Best practice
Refactor the test function to use table-driven tests for better maintainability

Use table-driven tests to make the test cases more concise and easier to maintain.

pkg/sql/plan/function/stage_test.go [25-38]

 func TestS3ServiceProvider(t *testing.T) {
-  protocol, err := getS3ServiceFromProvider("cos")
-  require.Nil(t, err)
-  assert.Equal(t, protocol, "s3")
+  testCases := []struct {
+    provider string
+    expected string
+  }{
+    {"cos", "s3"},
+    {"amazon", "s3"},
+    {"minio", "minio"},
+  }
 
-  protocol, err = getS3ServiceFromProvider("amazon")
-  require.Nil(t, err)
-  assert.Equal(t, protocol, "s3")
-
-  protocol, err = getS3ServiceFromProvider("minio")
-  require.Nil(t, err)
-  assert.Equal(t, protocol, "minio")
-
+  for _, tc := range testCases {
+    t.Run(tc.provider, func(t *testing.T) {
+      protocol, err := getS3ServiceFromProvider(tc.provider)
+      require.NoError(t, err)
+      assert.Equal(t, tc.expected, protocol)
+    })
+  }
 }
 
  • Apply this suggestion
Suggestion importance[1-10]: 7

Why: Refactoring to table-driven tests enhances code maintainability and readability, though it is not as critical as adding new test cases.

7

💡 Need additional feedback ? start a PR chat

@mergify mergify bot merged commit 5456f61 into matrixorigin:main Sep 18, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug fix Enhancement kind/bug Something isn't working Review effort [1-5]: 2 size/S Denotes a PR that changes [10,99] lines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants