|
1 | | -import { PrestoClientConfig, PrestoError, PrestoQuery, PrestoResponse } from './client.types' |
2 | | -import { Column, Table } from './information-schema.types' |
| 1 | +import { QUERY_INFO_URL, STATEMENT_URL } from './constants' |
| 2 | +import { |
| 3 | + Column, |
| 4 | + PrestoClientConfig, |
| 5 | + PrestoError, |
| 6 | + PrestoQuery, |
| 7 | + PrestoResponse, |
| 8 | + QueryInfo, |
| 9 | + Table, |
| 10 | +} from './types' |
3 | 11 |
|
4 | 12 | export class PrestoClient { |
5 | 13 | private baseUrl: string |
@@ -42,7 +50,7 @@ export class PrestoClient { |
42 | 50 | timezone, |
43 | 51 | user, |
44 | 52 | }: PrestoClientConfig) { |
45 | | - this.baseUrl = `${host || 'http://localhost'}:${port || 8080}/v1/statement` |
| 53 | + this.baseUrl = `${host || 'http://localhost'}:${port || 8080}` |
46 | 54 | this.catalog = catalog |
47 | 55 | this.interval = interval |
48 | 56 | this.schema = schema |
@@ -141,6 +149,25 @@ export class PrestoClient { |
141 | 149 | ) as Column[] |
142 | 150 | } |
143 | 151 |
|
| 152 | + /** |
| 153 | + * Retrieves all the information for a given query |
| 154 | + * @param {string} queryId The query identifier string |
| 155 | + * @returns {Promise<QueryInfo | undefined>} All the query information |
| 156 | + */ |
| 157 | + async getQueryInfo(queryId: string): Promise<QueryInfo | undefined> { |
| 158 | + const queryInfoResponse = await this.request({ |
| 159 | + headers: this.headers, |
| 160 | + method: 'GET', |
| 161 | + url: `${this.baseUrl}${QUERY_INFO_URL}${queryId}`, |
| 162 | + }) |
| 163 | + |
| 164 | + if (queryInfoResponse.status !== 200) { |
| 165 | + throw new Error(`Query failed: ${JSON.stringify(await queryInfoResponse.text())}`) |
| 166 | + } |
| 167 | + |
| 168 | + return (await queryInfoResponse.json()) as QueryInfo |
| 169 | + } |
| 170 | + |
144 | 171 | /** |
145 | 172 | * Retrieves all schemas within a given catalog. |
146 | 173 | * @param {string} catalog - The name of the catalog for which to retrieve schemas. |
@@ -209,7 +236,12 @@ export class PrestoClient { |
209 | 236 | headers['X-Presto-Schema'] = schema |
210 | 237 | } |
211 | 238 |
|
212 | | - const firstResponse = await this.request({ body: query, headers, method: 'POST', url: this.baseUrl }) |
| 239 | + const firstResponse = await this.request({ |
| 240 | + body: query, |
| 241 | + headers, |
| 242 | + method: 'POST', |
| 243 | + url: `${this.baseUrl}${STATEMENT_URL}`, |
| 244 | + }) |
213 | 245 |
|
214 | 246 | if (firstResponse.status !== 200) { |
215 | 247 | throw new Error(`Query failed: ${JSON.stringify(await firstResponse.text())}`) |
|
0 commit comments