Skip to content

Commit 0e6ecd9

Browse files
ramalingamtramalingamtKSDaemon
authored
feat(duckdb-driver): Add support for installing and loading DuckDB Extensions. (#8744)
* Added support for installing and loading DuckDB Extensions. * Lint fixes - checked-in. --------- Co-authored-by: ramalingamt <[email protected]> Co-authored-by: Konstantin Burkalev <[email protected]>
1 parent 6632140 commit 0e6ecd9

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,19 @@ const variables: Record<string, (...args: any) => any> = {
16131613
]
16141614
),
16151615

1616+
duckdbExtensions: ({
1617+
dataSource
1618+
}: {
1619+
dataSource: string,
1620+
}) => {
1621+
const extensions = process.env[
1622+
keyByDataSource('CUBEJS_DB_DUCKDB_EXTENSIONS', dataSource)
1623+
];
1624+
if (extensions) {
1625+
return extensions.split(',').map(e => e.trim());
1626+
}
1627+
return [];
1628+
},
16161629
/** ***************************************************************
16171630
* Presto Driver *
16181631
**************************************************************** */

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,36 @@ export class DuckDBDriver extends BaseDriver implements DriverInterface {
134134
}
135135
}
136136

137+
// Install & load extensions if configured in env variable.
138+
const extensions = getEnv('duckdbExtensions', this.config);
139+
for (const extension of extensions) {
140+
try {
141+
await execAsync(`INSTALL ${extension}`);
142+
} catch (e) {
143+
if (this.logger) {
144+
console.error(`DuckDB - error on installing ${extension}`, {
145+
e
146+
});
147+
}
148+
149+
// DuckDB will lose connection_ref on connection on error, this will lead to broken connection object
150+
throw e;
151+
}
152+
153+
try {
154+
await execAsync(`LOAD ${extension}`);
155+
} catch (e) {
156+
if (this.logger) {
157+
console.error(`DuckDB - error on loading ${extension}`, {
158+
e
159+
});
160+
}
161+
162+
// DuckDB will lose connection_ref on connection on error, this will lead to broken connection object
163+
throw e;
164+
}
165+
}
166+
137167
if (this.config.initSql) {
138168
try {
139169
await execAsync(this.config.initSql);

0 commit comments

Comments
 (0)