-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Adding DuckDB Macros #8955
Comments
If you are interested in working on this issue, please go ahead and provide PR for that. |
@paveltiunov can you suggest a general shape for this solution? What would be the appropriate extension point for specifying the SQL that should be injected? Is there a reference point of how it's done in other places? There seems to be a |
I figured that I can install macros by creating a custom DuckDB Driver by adding the following to const DuckDBDriver = require('@cubejs-backend/duckdb-driver');
module.exports = {
driverFactory: () => {
return new DuckDBDriver({
initSql: `
CREATE OR REPLACE MACRO json_each(val) AS
TABLE (
SELECT CASE
WHEN json_array_length(j) >0 THEN unnest(range(json_array_length(j)::BIGINT))::VARCHAR
ELSE unnest(json_keys(j)) END as key,
CASE
WHEN json_array_length(j) >0 THEN
json_extract(j, key::BIGINT) ELSE
json_extract(j, key)
END as value
FROM (SELECT val as j)
);
`
})
}
}; |
Is your feature request related to a problem? Please describe.
DuckDB macros are temporary. They're scoped to a connection where they're created.
Describe the solution you'd like
I would like to be able to install macros by providing SQL that will be invoked when a connection to DuckDB is first created.
Describe alternatives you've considered
Not using macros would suck because there are some good once - such as duckdb/duckdb#3578 (comment)
Additional context
https://duckdb.org/docs/sql/statements/create_macro.html
The text was updated successfully, but these errors were encountered: