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

Add datasource.NewBigqueryClient #206

Merged
merged 1 commit into from
Apr 21, 2020
Merged
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
39 changes: 22 additions & 17 deletions datasource/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,24 +161,8 @@ func AnalyzeJSONString(str string) (*schema.Schema, error) {
// AnalyzeBigquery analyze `bq://`
func AnalyzeBigquery(urlstr string) (*schema.Schema, error) {
s := &schema.Schema{}
u, err := url.Parse(urlstr)
if err != nil {
return s, err
}

values := u.Query()
err = setEnvGoogleApplicationCredentials(values)
if err != nil {
return s, err
}

splitted := strings.Split(u.Path, "/")

projectID := u.Host
datasetID := splitted[1]

ctx := context.Background()
client, err := bigquery.NewClient(ctx, projectID)
client, projectID, datasetID, err := NewBigqueryClient(ctx, urlstr)
if err != nil {
return s, err
}
Expand All @@ -196,6 +180,27 @@ func AnalyzeBigquery(urlstr string) (*schema.Schema, error) {
return s, nil
}

// NewBigqueryClient returns new bigquery.Client
func NewBigqueryClient(ctx context.Context, urlstr string) (*bigquery.Client, string, string, error) {
u, err := url.Parse(urlstr)
if err != nil {
return nil, "", "", err
}
values := u.Query()
err = setEnvGoogleApplicationCredentials(values)
if err != nil {
return nil, "", "", err
}

splitted := strings.Split(u.Path, "/")

projectID := u.Host
datasetID := splitted[1]

client, err := bigquery.NewClient(ctx, projectID)
return client, projectID, datasetID, err
}

// AnalyzeSpanner analyze `spanner://`
func AnalyzeSpanner(urlstr string) (*schema.Schema, error) {
s := &schema.Schema{}
Expand Down