aws-athena-node-client
Version:
95 lines (94 loc) • 2.77 kB
TypeScript
import { AthenaClientConfig } from './AthenaClientConfig.js';
import { AthenaClient as AwsAthenaClient } from '@aws-sdk/client-athena';
import { Statistics } from './Statistics.js';
export interface QueryConfig {
readonly id?: string;
readonly parameters?: Record<string, unknown>;
readonly cacheInMinutes?: number;
readonly stats?: boolean;
}
export interface QueryWithResultsInS3Config extends QueryConfig {
s3LinkExpirationInSeconds?: number;
}
export declare class AthenaNodeClient {
private readonly _client;
private readonly _config;
private _queue;
constructor(client: AwsAthenaClient, config: AthenaClientConfig);
executeQuery<T extends object>(sql: string, config?: QueryConfig): Promise<{
id: string;
results: T[];
statistics?: Statistics;
}>;
/**
* Execute query in Athena and get S3 URL with CSV file
*/
executeQueryAndGetS3Key(sql: string, config?: QueryConfig): Promise<{
id: string;
bucket: string;
key: string;
statistics?: Statistics;
}>;
executeQueryAndGetDownloadSignedUrl(sql: string, config?: QueryWithResultsInS3Config): Promise<{
id: string;
url: string;
statistics?: Statistics;
}>;
/**
* Cancel a AWS Athena query
*
* @param {string} id Execution query ID
*
* @returns {Promise<void>}
*
* @memberof AthenaNodeClient
*/
cancelQuery(id: string): Promise<void>;
private executeQueryCommon;
/**
* Starts query execution and gets an ID for the operation
*
* @private
* @param {Query} query - Athena request params
* @returns {Promise<string>} - query execution id
* @memberof AthenaNodeClient
*/
private startQueryExecution;
/**
* Processes query results and parses them
*
* @private
* @template T
*
* @param {Query<T>} query
* @param {string} nextToken
*
* @returns {Promise<T[]>} - parsed query result rows
* @memberof AthenaNodeClient
*/
private getQueryResults;
/**
* Get statistics from a query execution
*
* @private
* @template T
*
*
* @returns {Promise<T[]>} - parsed query result rows
* @memberof AthenaNodeClient
* @param {string} executionId
*/
private getQueryStatistics;
private parseRow;
private parseRows;
private setColumnParsers;
/**
* Checks the query execution status until the query sends SUCCEEDED signal
*
* @private
* @param {Query} query - the query
* @returns {Promise<void>} - promise that will resolve once the operation has finished
* @memberof AthenaNodeClient
*/
private waitUntilSucceedQuery;
}