Skip to content

akrennmair/go-athena

 
 

Repository files navigation

go-athena

go-athena is a simple Golang database/sql driver for Amazon Athena.

import (
    "database/sql"
    _ "github.com/akrennmair/go-athena"
)

func main() {
  // Make sure the access key and access key id are url encoded first
  db, _ := sql.Open("athena", "db=default&output_location=s3://results&secret_key_id=XX&secret_access_key=YY")
  rows, _ := db.Query("SELECT url, code from cloudfront")

  for rows.Next() {
    var url string
    var code int
    rows.Scan(&url, &code)
  }
}

It provides a higher-level, idiomatic wrapper over the AWS Go SDK, comparable to the Athena JDBC driver AWS provides for Java users.

For example,

Caveats

database/sql exposes lots of methods that aren't supported in Athena. For example, Athena doesn't support transactions so Begin() is irrelevant. If a method must be supplied to satisfy a standard library interface but is unsupported, the driver will return an error indicating so.

Testing

Unit tests are in place to aim to achieve test coverage for as much of the package code as possible. This cannot fully replace end-to-end testing, and as Athena doesn't have a local version and revolves around S3, integration tests are in place to test against AWS itself. They can be enabled by running go test -tags=integration.

These tests require AWS credentials. The simplest way to provide them is via AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables, but you can use anything supported by the Default Credential Provider Chain.

The tests support a few environment variables:

  • ATHENA_DATABASE can be used to override the default database "go_athena_tests"
  • S3_BUCKET can be used to override the default S3 bucket of "go-athena-tests"

Please bear in mind that the integration tests are currently unmaintained.

Acknowlegments

This library started out as a fork of https://github.com/segmentio/go-athena. As that project seems to have been abandoned, this fork aims to be as feature-complete as possible and integrate all the changes that were submitted as PRs to the original package and committed to other forks. The following people's work has been included in this package:

  • Fredrik Petrini prepared statement support
  • Forud (fzerorubigd) support for authentication with access_key_id/secret_access_key
  • jkatagi support for workgroups

About

Golang database/sql driver for AWS Athena

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 97.2%
  • ANTLR 2.8%