chore: generate
This commit is contained in:
parent
85ef35dd64
commit
d09d5612f3
1 changed files with 26 additions and 31 deletions
|
|
@ -113,37 +113,32 @@ const poll: (
|
||||||
return yield* poll(client, queryExecutionId, attempt + 1)
|
return yield* poll(client, queryExecutionId, attempt + 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
const results: (
|
const results: (client: AwsAthenaClient, queryExecutionId: string) => Effect.Effect<AthenaData[], AthenaQueryError> =
|
||||||
client: AwsAthenaClient,
|
Effect.fn("Athena.results")(function* (client: AwsAthenaClient, queryExecutionId: string) {
|
||||||
queryExecutionId: string,
|
// Accumulate pages iteratively; recursive spreads copied every previously
|
||||||
) => Effect.Effect<AthenaData[], AthenaQueryError> = Effect.fn("Athena.results")(function* (
|
// fetched row per page and blew up memory on large result sets.
|
||||||
client: AwsAthenaClient,
|
const rows: AthenaData[] = []
|
||||||
queryExecutionId: string,
|
let nextToken: string | undefined
|
||||||
) {
|
while (true) {
|
||||||
// Accumulate pages iteratively; recursive spreads copied every previously
|
const result = yield* Effect.tryPromise({
|
||||||
// fetched row per page and blew up memory on large result sets.
|
try: () =>
|
||||||
const rows: AthenaData[] = []
|
client.send(
|
||||||
let nextToken: string | undefined
|
new GetQueryResultsCommand({
|
||||||
while (true) {
|
QueryExecutionId: queryExecutionId,
|
||||||
const result = yield* Effect.tryPromise({
|
NextToken: nextToken,
|
||||||
try: () =>
|
MaxResults: ATHENA_PAGE_SIZE,
|
||||||
client.send(
|
}),
|
||||||
new GetQueryResultsCommand({
|
),
|
||||||
QueryExecutionId: queryExecutionId,
|
catch: (cause) =>
|
||||||
NextToken: nextToken,
|
new AthenaQueryError({ message: "Failed to read Athena stats results", queryExecutionId, cause }),
|
||||||
MaxResults: ATHENA_PAGE_SIZE,
|
})
|
||||||
}),
|
const columns = result.ResultSet?.ResultSetMetadata?.ColumnInfo?.map((item) => item.Name ?? "") ?? []
|
||||||
),
|
// The first page starts with the header row.
|
||||||
catch: (cause) =>
|
for (const row of (result.ResultSet?.Rows ?? []).slice(nextToken ? 0 : 1)) rows.push(rowData(columns, row))
|
||||||
new AthenaQueryError({ message: "Failed to read Athena stats results", queryExecutionId, cause }),
|
if (!result.NextToken) return rows
|
||||||
})
|
nextToken = result.NextToken
|
||||||
const columns = result.ResultSet?.ResultSetMetadata?.ColumnInfo?.map((item) => item.Name ?? "") ?? []
|
}
|
||||||
// The first page starts with the header row.
|
})
|
||||||
for (const row of (result.ResultSet?.Rows ?? []).slice(nextToken ? 0 : 1)) rows.push(rowData(columns, row))
|
|
||||||
if (!result.NextToken) return rows
|
|
||||||
nextToken = result.NextToken
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
function rowData(columns: string[], row: Row): AthenaData {
|
function rowData(columns: string[], row: Row): AthenaData {
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue