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

br: handle special character in SQL (#37486) #37638

Merged
merged 3 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions br/pkg/storage/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,49 @@ func TestFormatBackendURL(t *testing.T) {
})
require.Equal(t, "azure://bucket/some%20prefix/", backendURL.String())
}

func TestParseRawURL(t *testing.T) {
cases := []struct {
url string
schema string
host string
path string
accessKey string
secretAccessKey string
}{
{
url: `s3://bucket/prefix/path?access-key=NXN7IPIOSAAKDEEOLMAF&secret-access-key=nREY/7DtPaIbYKrKlEEMMF/ExCiJEX=XMLPUANw`,
schema: "s3",
host: "bucket",
path: "/prefix/path",
accessKey: "NXN7IPIOSAAKDEEOLMAF", // fake ak/sk
secretAccessKey: "nREY/7DtPaIbYKrKlEEMMF/ExCiJEX=XMLPUANw", // w/o "+"
},
{
url: `s3://bucket/prefix/path?access-key=NXN7IPIOSAAKDEEOLMAF&secret-access-key=nREY/7Dt+PaIbYKrKlEEMMF/ExCiJEX=XMLPUANw`,
schema: "s3",
host: "bucket",
path: "/prefix/path",
accessKey: "NXN7IPIOSAAKDEEOLMAF", // fake ak/sk
secretAccessKey: "nREY/7Dt+PaIbYKrKlEEMMF/ExCiJEX=XMLPUANw", // with "+"
},
}

for _, c := range cases {
storageRawURL := c.url
storageURL, err := ParseRawURL(storageRawURL)
require.NoError(t, err)

require.Equal(t, c.schema, storageURL.Scheme)
require.Equal(t, c.host, storageURL.Host)
require.Equal(t, c.path, storageURL.Path)

require.Equal(t, 1, len(storageURL.Query()["access-key"]))
accessKey := storageURL.Query()["access-key"][0]
require.Equal(t, c.accessKey, accessKey)

require.Equal(t, 1, len(storageURL.Query()["secret-access-key"]))
secretAccessKey := storageURL.Query()["secret-access-key"][0]
require.Equal(t, c.secretAccessKey, secretAccessKey)
}
}
3 changes: 1 addition & 2 deletions executor/brie.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package executor

import (
"context"
"net/url"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -224,7 +223,7 @@ func (b *executorBuilder) buildBRIE(s *ast.BRIEStmt, schema *expression.Schema)
},
}

storageURL, err := url.Parse(s.Storage)
storageURL, err := storage.ParseRawURL(s.Storage)
if err != nil {
b.err = errors.Annotate(err, "invalid destination URL")
return nil
Expand Down