Skip to content

Commit 545db43

Browse files
committed
Pass CUBEJS_DB_QUERY_TIMEOUT to Firebolt driver
1 parent f1d2735 commit 545db43

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-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+
requestTimeoutEnv: 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+
requestTimeoutEnv: 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.requestTimeoutEnv },
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.requestTimeoutEnv },
279281
parameters,
280282
response: { hydrateRow: this.hydrateRow }
281283
});

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,20 @@ describe('FireboltDriver', () => {
2222
test('stream', async () => {
2323
await tests.testStream();
2424
});
25+
26+
test('query should fail on timeout', async () => {
27+
const slowQuery = 'SELECT checksum(*) FROM GENERATE_SERIES(1, 1000000000000)';
28+
const driver = new FireboltDriver({});
29+
30+
let timedOut = false;
31+
try {
32+
await driver.query(slowQuery);
33+
} catch (e) {
34+
if (String(e).toLowerCase().includes('Query timeout expired')) {
35+
timedOut = true;
36+
}
37+
}
38+
39+
expect(timedOut).toBe(true);
40+
}, 10000);
2541
});

packages/cubejs-firebolt-driver/test/test-env.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const REQUIRED_ENV_VARS = [
44
'CUBEJS_DB_NAME',
55
'CUBEJS_FIREBOLT_ENGINE_NAME',
66
'CUBEJS_FIREBOLT_ACCOUNT',
7+
'CUBEJS_DB_QUERY_TIMEOUT',
78
];
89

910
REQUIRED_ENV_VARS.forEach((key) => {

0 commit comments

Comments
 (0)