Skip to content
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
24 changes: 24 additions & 0 deletions src/lib/AthenaClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface AthenaClientConfig {
profile?: string;
accessKeyId?: string;
secretAccessKey?: string;
catalog?: string;
database: string;
outputLocation: string;
}
Expand Down Expand Up @@ -42,6 +43,7 @@ export default class AthenaClient {
OutputLocation: this.config.outputLocation,
},
QueryExecutionContext: {
Catalog: this.config.catalog || undefined,
Database: this.config.database,
},
};
Expand Down Expand Up @@ -88,6 +90,28 @@ export default class AthenaClient {
return rows;
}

async listTableMetadata(): Promise<athena.TableMetadata[]> {
let tables: athena.TableMetadata[] = [];
let nextToken: string | undefined = undefined;

for (;;) {
const result = await this.client.send(
new athena.ListTableMetadataCommand({
CatalogName: this.config.catalog || "AwsDataCatalog",
DatabaseName: this.config.database,
NextToken: nextToken,
})
);
tables = tables.concat(result.TableMetadataList || []);
nextToken = result.NextToken;
if (!nextToken) {
break;
}
}

return tables;
}

cancel(): void {
this.client.send(new athena.StopQueryExecutionCommand({ QueryExecutionId: this.executionId }));
}
Expand Down
21 changes: 14 additions & 7 deletions src/lib/DataSourceDefinition/Athena.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export default class Athena extends Base {
type: "string",
placeholder: "Optional - uses AWS environment/profile if empty",
},
{
name: "catalog",
label: "Catalog",
type: "string",
placeholder: "Optional - uses AwsDataCatalog if empty",
},
{
name: "database",
label: "Database",
Expand Down Expand Up @@ -74,18 +80,18 @@ export default class Athena extends Base {
}

async fetchTables(): Promise<{ name: string; type: string; schema?: string }[]> {
const rows = await this.client.execute("show tables");
return rows.map((row) => ({ name: row[0]!, type: "table" }));
const tables = await this.client.listTableMetadata();
return tables.map((table) => ({ name: table.Name!, type: "table" }));
}

async fetchTableSummary({ name }: { name: string }): Promise<TableSummary> {
const rows = await this.client.execute(`describe ${name}`);
const tables = await this.client.listTableMetadata();
const table = tables.find((t) => t.Name === name);
const columns = [...(table?.Columns || []), ...(table?.PartitionKeys || [])];

const defs = {
fields: ["name", "type"],
rows: rows
.map((row) => row[0])
.filter((v) => v !== null && v[0] !== "#" && v.trim() !== "")
.map((v) => (v || "").split("\t").map((c) => c.trim())),
rows: columns.map((column) => [column.Name!, column.Type || ""]),
};

return { name, defs };
Expand All @@ -95,6 +101,7 @@ export default class Athena extends Base {
return {
type: Athena.label,
region: this.config.region,
catalog: this.config.catalog || "AwsDataCatalog",
database: this.config.database,
};
}
Expand Down
Loading