Skip to content

Commit 3e0f9eb

Browse files
committed
Pass CUBEJS_DB_QUERY_TIMEOUT to Firebolt driver
1 parent f1d2735 commit 3e0f9eb

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

packages/cubejs-firebolt-driver/src/FireboltDriver.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export type FireboltDriverConfiguration = {
3030
readOnly?: boolean;
3131
apiEndpoint?: string;
3232
connection: ConnectionOptions;
33+
requestTimeout: number;
3334
};
3435

3536
const FireboltTypeToGeneric: Record<string, string> = {
@@ -91,6 +92,7 @@ export class FireboltDriver extends BaseDriver implements DriverInterface {
9192

9293
this.config = {
9394
readOnly: true,
95+
requestTimeout: getEnv('dbQueryTimeout') * 1000,
9496
apiEndpoint:
9597
getEnv('fireboltApiEndpoint', { dataSource }) || 'api.app.firebolt.io',
9698
...config,
@@ -225,7 +227,7 @@ export class FireboltDriver extends BaseDriver implements DriverInterface {
225227
const connection = await this.getConnection();
226228

227229
const statement = await connection.execute(query, {
228-
settings: { output_format: OutputFormat.JSON },
230+
settings: { output_format: OutputFormat.JSON, statement_timeout: this.config.requestTimeout },
229231
parameters,
230232
response: { hydrateRow: this.hydrateRow }
231233
});
@@ -275,7 +277,7 @@ export class FireboltDriver extends BaseDriver implements DriverInterface {
275277
const connection = await this.getConnection();
276278

277279
const statement = await connection.execute(query, {
278-
settings: { output_format: OutputFormat.JSON },
280+
settings: { output_format: OutputFormat.JSON, statement_timeout: this.config.requestTimeout },
279281
parameters,
280282
response: { hydrateRow: this.hydrateRow }
281283
});

packages/cubejs-firebolt-driver/test/FireboltDriver.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { DriverTests } from '@cubejs-backend/testing-shared';
22

33
import { FireboltDriver } from '../src';
4+
import { getEnv } from '@cubejs-backend/shared';
45

56
describe('FireboltDriver', () => {
67
let tests: DriverTests;
@@ -22,4 +23,22 @@ describe('FireboltDriver', () => {
2223
test('stream', async () => {
2324
await tests.testStream();
2425
});
26+
27+
test('query should fail on timeout', async () => {
28+
const slowQuery = 'SELECT checksum(*) FROM GENERATE_SERIES(1, 1000000000000)';
29+
// Set query timeout to 2 seconds
30+
process.env.CUBEJS_DB_QUERY_TIMEOUT = '2';
31+
const driver = new FireboltDriver({});
32+
33+
let timedOut = false;
34+
try {
35+
await driver.query(slowQuery);
36+
} catch (e) {
37+
if (String(e).toLowerCase().includes('timeout expired (2000 ms)')) {
38+
timedOut = true;
39+
}
40+
}
41+
42+
expect(timedOut).toBe(true);
43+
}, 10000);
2544
});

0 commit comments

Comments
 (0)