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

Feature/support athena workgroup #9

Merged
merged 2 commits into from
Nov 13, 2020
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
2 changes: 2 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type conn struct {
athena athenaiface.AthenaAPI
db string
OutputLocation string
workgroup string

pollFrequency time.Duration
}
Expand Down Expand Up @@ -65,6 +66,7 @@ func (c *conn) startQuery(query string) (string, error) {
ResultConfiguration: &athena.ResultConfiguration{
OutputLocation: aws.String(c.OutputLocation),
},
WorkGroup: aws.String(c.workgroup),
})
if err != nil {
return "", err
Expand Down
13 changes: 13 additions & 0 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func init() {
// - `region` (optional)
// Override AWS region. Useful if it is not set with environment variable.
//
// - `workgroup` (optional)
// Athena's workgroup. This defaults to "primary".
//
// Credentials must be accessible via the SDK's Default Credential Provider Chain.
// For more advanced AWS credentials/session/config management, please supply
// a custom AWS session directly via `athena.Open()`.
Expand All @@ -80,6 +83,7 @@ func (d *Driver) Open(connStr string) (driver.Conn, error) {
db: cfg.Database,
OutputLocation: cfg.OutputLocation,
pollFrequency: cfg.PollFrequency,
workgroup: cfg.WorkGroup,
}, nil
}

Expand All @@ -99,6 +103,10 @@ func Open(cfg Config) (*sql.DB, error) {
return nil, errors.New("session is required")
}

if cfg.WorkGroup == "" {
cfg.WorkGroup = "primary"
}

// This hack was copied from jackc/pgx. Sorry :(
// https://github.com/jackc/pgx/blob/70a284f4f33a9cc28fd1223f6b83fb00deecfe33/stdlib/sql.go#L130-L136
openFromSessionMutex.Lock()
Expand All @@ -115,6 +123,7 @@ type Config struct {
Session *session.Session
Database string
OutputLocation string
WorkGroup string

PollFrequency time.Duration
}
Expand All @@ -138,6 +147,10 @@ func configFromConnectionString(connStr string) (*Config, error) {

cfg.Database = args.Get("db")
cfg.OutputLocation = args.Get("output_location")
cfg.WorkGroup = args.Get("workgroup")
if cfg.WorkGroup == "" {
cfg.WorkGroup = "primary"
}

frequencyStr := args.Get("poll_frequency")
if frequencyStr != "" {
Expand Down