Skip to content

Commit

Permalink
Add error and failure info to query result (#22)
Browse files Browse the repository at this point in the history
Closes #21
  • Loading branch information
regadas authored Jul 8, 2022
1 parent 3d94f54 commit 1186a09
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ export type Columns = {name: string; type: string}[];

export type QueryData = any[];

export type QueryFailureInfo = {
type: string;
message: string;
suppressed: string[];
stack: string[];
};

export type QueryError = {
message: string;
errorCode: number;
errorName: string;
errorType: string;
failureInfo: QueryFailureInfo;
};

export type QueryResult = {
id: string;
infoUri?: string;
Expand All @@ -105,12 +120,14 @@ export type QueryResult = {
data?: QueryData[];
stats?: QueryStats;
warnings?: string[];
error?: QueryError;
};

export type QueryInfo = {
queryId: string;
state: string;
query: string;
failureInfo?: QueryFailureInfo;
};

export type Query = {
Expand Down
34 changes: 34 additions & 0 deletions tests/it/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,38 @@ describe('trino', () => {
expect(info.state).toBe('FINISHED');
expect(info.query).toBe(singleCustomerQuery);
});

test.concurrent('QueryResult has error info', async () => {
const trino = new Trino({
catalog: 'tpcds',
schema: 'sf100000',
auth: new BasicAuth('test'),
});
const sqr = await trino.query('select * from foobar where id = -1');
const qr = await sqr.next();
expect(qr.error).toBeDefined();
expect(qr.error?.message).toBe(
"line 1:15: Table 'tpcds.sf100000.foobar' does not exist"
);

await sqr.close();
});

test.concurrent('QueryInfo has failure info', async () => {
const trino = new Trino({
catalog: 'tpcds',
schema: 'sf100000',
auth: new BasicAuth('test'),
});

const sqr = await trino.query('select * from foobar where id = -1');
const qr = await sqr.next();
await sqr.close();

const info = await trino.queryInfo(qr.id);
expect(info.state).toBe('FAILED');
expect(info.failureInfo?.message).toBe(
"line 1:15: Table 'tpcds.sf100000.foobar' does not exist"
);
});
});

0 comments on commit 1186a09

Please sign in to comment.