Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(duckdb): Added support for installing and loading DuckDB Extensions. #8744

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/pages/product/configuration/data-sources/duckdb.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ deployment][ref-demo-deployment] in Cube Cloud.
| `CUBEJS_DB_DUCKDB_S3_USE_SSL` | Use SSL for connection | A boolean | ❌ | ❌ |
| `CUBEJS_DB_DUCKDB_S3_URL_STYLE` | To choose the S3 URL style(vhost or path) | 'vhost' or 'path' | ❌ | ❌ |
| `CUBEJS_DB_DUCKDB_S3_SESSION_TOKEN` | The token for the S3 session | A valid Session Token | ❌ | ✅ |
| `CUBEJS_DB_DUCKDB_EXTENSIONS` | A comma-separated list of DuckDB extensions to install and load | A comma-separated list of DuckDB extensions | ❌ | ✅ |

## Pre-Aggregation Feature Support

Expand Down
8 changes: 8 additions & 0 deletions docs/pages/reference/configuration/environment-variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@ The S3 session token.
| -------------------------------------- | ---------------------- | --------------------- |
| A valid S3 session token | N/A | N/A |

## `CUBEJS_DB_DUCKDB_EXTENSIONS`

A comma-separated list of DuckDB extensions to install and load.

| Possible Values | Default in Development | Default in Production |
| ------------------------------------------- | ---------------------- | --------------------- |
| A comma-separated list of DuckDB extensions | N/A | N/A |

## `CUBEJS_DB_ELASTIC_APIKEY_ID`

The [ID of the API key from elastic.co][elastic-docs-api-keys]. Required when
Expand Down
13 changes: 13 additions & 0 deletions packages/cubejs-backend-shared/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,19 @@
]
),

duckdbExtensions: ({

Check failure on line 1616 in packages/cubejs-backend-shared/src/env.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 0
dataSource
}: {
dataSource: string,
}) => {
const extensions = process.env[
keyByDataSource('CUBEJS_DB_DUCKDB_EXTENSIONS', dataSource)
]

Check failure on line 1623 in packages/cubejs-backend-shared/src/env.ts

View workflow job for this annotation

GitHub Actions / lint

Missing semicolon
if (extensions) {
return extensions.split(',').map(e => e.trim());
}
return [];
},
/** ***************************************************************
* Presto Driver *
**************************************************************** */
Expand Down
30 changes: 30 additions & 0 deletions packages/cubejs-duckdb-driver/src/DuckDBDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,36 @@ export class DuckDBDriver extends BaseDriver implements DriverInterface {
}
}

// Install & load extensions if configured in env variable.
const extensions = getEnv('duckdbExtensions', this.config);
for (const extension of extensions) {
try {
await execAsync('INSTALL ' + extension);
} catch (e) {
if (this.logger) {
console.error('DuckDB - error on installing ' + extension, {
e
});
}

// DuckDB will lose connection_ref on connection on error, this will lead to broken connection object
throw e;
}

try {
await execAsync('LOAD ' + extension);
} catch (e) {
if (this.logger) {
console.error('DuckDB - error on loading ' + extension, {
e
});
}

// DuckDB will lose connection_ref on connection on error, this will lead to broken connection object
throw e;
}
}

if (this.config.initSql) {
try {
await execAsync(this.config.initSql);
Expand Down
Loading