Skip to content

Commit 53f5f22

Browse files
authored
Added support for installing and loading DuckDB Extensions.
1 parent 73d9314 commit 53f5f22

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

docs/pages/product/configuration/data-sources/duckdb.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ deployment][ref-demo-deployment] in Cube Cloud.
7373
| `CUBEJS_DB_DUCKDB_S3_USE_SSL` | Use SSL for connection | A boolean |||
7474
| `CUBEJS_DB_DUCKDB_S3_URL_STYLE` | To choose the S3 URL style(vhost or path) | 'vhost' or 'path' |||
7575
| `CUBEJS_DB_DUCKDB_S3_SESSION_TOKEN` | The token for the S3 session | A valid Session Token |||
76+
| `CUBEJS_DB_DUCKDB_EXTENSIONS` | A comma-separated list of DuckDB extensions to install and load | A comma-separated list of DuckDB extensions |||
7677

7778
## Pre-Aggregation Feature Support
7879

docs/pages/reference/configuration/environment-variables.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,14 @@ The S3 session token.
315315
| -------------------------------------- | ---------------------- | --------------------- |
316316
| A valid S3 session token | N/A | N/A |
317317

318+
## `CUBEJS_DB_DUCKDB_EXTENSIONS`
319+
320+
A comma-separated list of DuckDB extensions to install and load.
321+
322+
| Possible Values | Default in Development | Default in Production |
323+
| ------------------------------------------- | ---------------------- | --------------------- |
324+
| A comma-separated list of DuckDB extensions | N/A | N/A |
325+
318326
## `CUBEJS_DB_ELASTIC_APIKEY_ID`
319327

320328
The [ID of the API key from elastic.co][elastic-docs-api-keys]. Required when

packages/cubejs-backend-shared/src/env.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,20 @@ const variables: Record<string, (...args: any) => any> = {
15351535
]
15361536
),
15371537

1538+
duckdbExtensions: ({
1539+
dataSource
1540+
}: {
1541+
dataSource: string,
1542+
}) => {
1543+
const extensions = process.env[
1544+
keyByDataSource('CUBEJS_DB_DUCKDB_EXTENSIONS', dataSource)
1545+
]
1546+
if (extensions) {
1547+
return extensions.split(',').map(e => e.trim());
1548+
}
1549+
return [];
1550+
},
1551+
15381552
/**
15391553
* Presto catalog.
15401554
*/

packages/cubejs-duckdb-driver/src/DuckDBDriver.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,36 @@ export class DuckDBDriver extends BaseDriver implements DriverInterface {
160160
}
161161
}
162162

163+
// Install & load extensions if configured in env variable.
164+
const extensions = getEnv('duckdbExtensions', this.config);
165+
for (const extension of extensions) {
166+
try {
167+
await execAsync('INSTALL ' + extension);
168+
} catch (e) {
169+
if (this.logger) {
170+
console.error('DuckDB - error on installing ' + extension, {
171+
e
172+
});
173+
}
174+
175+
// DuckDB will lose connection_ref on connection on error, this will lead to broken connection object
176+
throw e;
177+
}
178+
179+
try {
180+
await execAsync('LOAD ' + extension);
181+
} catch (e) {
182+
if (this.logger) {
183+
console.error('DuckDB - error on loading ' + extension, {
184+
e
185+
});
186+
}
187+
188+
// DuckDB will lose connection_ref on connection on error, this will lead to broken connection object
189+
throw e;
190+
}
191+
}
192+
163193
if (this.config.initSql) {
164194
try {
165195
await execAsync(this.config.initSql);

0 commit comments

Comments
 (0)