From 3cd5f19b8a5be3707b4198cd0901726099d23cb0 Mon Sep 17 00:00:00 2001 From: Mike Jacobsson Date: Fri, 2 Apr 2021 20:55:57 +1000 Subject: [PATCH] add support for catalogs, required for federated query --- README.md | 2 ++ index.d.ts | 1 + lib/athenaExpress.js | 1 + lib/helpers.js | 1 + 4 files changed, 5 insertions(+) diff --git a/README.md b/README.md index f62592f..d6c57bb 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,7 @@ const aws = require("aws-sdk"); const athenaExpressConfig = { aws, /* required */ s3: "STRING_VALUE", /* optional format 's3://bucketname'*/ + catalog: "STRING_VALUE", /* optional - data source */ db: "STRING_VALUE", /* optional */ workgroup: "STRING_VALUE", /* optional */ formatJson: BOOLEAN, /* optional default=true */ @@ -141,6 +142,7 @@ const athenaExpress = new AthenaExpress(athenaExpressConfig); | Parameter | Format | Default Value | Description | | ------------- | ------------- | ------------- | ------------- | | s3 | string | `athena-express` creates a new bucket for you | The location in Amazon S3 where your query results are stored, such as `s3://path/to/query/bucket/`.
`athena-express` will create a new bucket for you if you don't provide a value for this param but sometimes that could cause an issue if you had recently deleted a bucket with the same name. (something to do with cache). When that happens, just specify you own bucket name. Alternatively you can also use `workgroup`. | +| catalog | string | Athena data source / catalog, required for federated connectors | | db | string | `default` | Athena database name that the SQL queries should be executed in. When a `db` name is specified in the config, you can execute SQL queries without needing to explicitly mention DB name. e.g.
` athenaExpress.query("SELECT * FROM movies LIMIT 3")`
as opposed to
` athenaExpress.query({sql: "SELECT * FROM movies LIMIT 3", db: "moviedb"});` | | workgroup | string | `primary` | The name of the workgroup in which the query is being started.
Note: athena-express cannot create workgroups (as it includes a lot of configuration) so you will need to create one beforehand IFF you intend to use a non default workgroup. Learn More here. [Setting up Workgroups](https://docs.aws.amazon.com/athena/latest/ug/user-created-workgroups.html) | |formatJson | boolean | `true` | Override as false if you rather get the raw unformatted output from S3. | diff --git a/index.d.ts b/index.d.ts index 6265b66..01aeb3b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -4,6 +4,7 @@ declare module 'athena-express' { aws: typeof aws; s3: string; getStats: boolean; + catalog: string, db: string, workgroup: string, formatJson: boolean, diff --git a/lib/athenaExpress.js b/lib/athenaExpress.js index 99c0fd9..18afece 100644 --- a/lib/athenaExpress.js +++ b/lib/athenaExpress.js @@ -22,6 +22,7 @@ module.exports = class AthenaExpress { .substring(0, 10) .toLowerCase()}-${new Date().getFullYear()}`, encryption: init.encryption, + catalog: init.catalog, db: init.db || "default", workgroup: init.workgroup || "primary", retry: Number(init.retry) || 200, diff --git a/lib/helpers.js b/lib/helpers.js index 4d1e662..0e75bf5 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -15,6 +15,7 @@ function startQueryExecution(query, config) { OutputLocation: config.s3Bucket, }, QueryExecutionContext: { + Catalog: config.catalog, Database: query.db || config.db, }, };