AlexR2D2 / metabase_duckdb_driver

Metabase DuckDB Driver shipped as 3rd party plugin
Apache License 2.0
70 stars 21 forks source link

Driver has problem with view referencing files in the same folder as the database #4

Open seajhawk opened 1 year ago

seajhawk commented 1 year ago

Considering that duckdb has not reach 1.0 yet and build-to-build there are database version incompatibilities. Also, I would like to incrementally add to my database month-by-month without having to re-create the database and restart the metabase container to release the lock on the duckdb database file.

However, when I open the Raw State view, I get the following error: IO Error: No files found that match the pattern "raw_state.parquet"

I'm guessing duckdb is looking for the raw_state.parquet file in the same folder where the metabase.jar is running, not the folder where the duckdb database is located.

I tried specifying the full path to the raw_state.parquet file when creating the view on my local machine, but I don't have a /home/data/duckdb folder so duckdb.exe complains.

Any thoughts on how we might get the view query to run and look for the files in a path relative to the duckdb database?

AlexR2D2 commented 1 year ago

I modified a bit the driver and now you can run without errors the SQL 'write' queries (like CREAT TABLE and etc), but Metabase engine sets DB connection to readOnly, so all of your changes will not be persistent. All you can do now is to create a view in each query session. For example:

create view raw_state as select * from '/app/database/*.parquet'; 
select * from raw_state; 
...

But, I found a workaround how to do exactly what you want. For example, you mounted the 'my.duckdb' database folder into /app/database Metabase container folder. Let's pretend that all of you *.parquet files in the same folder.

  1. Restart the docker container with Metabase and don't open any Metabase webpages (or do not refresh any already opened pages) to avoid duckdb database locking.
  2. Login into container "$ docker exec -it bash"
  3. container:$ apt-get install unzip
  4. container:$ cd /app/database
  5. container:$ wget https://github.com/duckdb/duckdb/releases/download/v0.5.0/duckdb_cli-linux-amd64.zip
  6. container:$ unzip duckdb_cli-linux-amd64.zip
  7. container:$ ./duckdb
  8. container:$ D .open my.duckdb
  9. container:$ D create view v1 as select from '/app/database/.parquet';
  10. container:$ D .exit
  11. go to the Metabase web pages, open admin settings, open duckdb DB page and push buttons.

later all you need is just copy the new raw_view_NNN.parquet file into the folder with the ducked database (mounted into container) and refresh Metabase web page.