Link Search Menu Expand Document

Using lakeFS with DuckDB

DuckDB is an in-process SQL OLAP database management system. You can access data in lakeFS from DuckDB, as well as use DuckDB from within the web interface of lakeFS

Accessing lakeFS from DuckDB


Querying data in lakeFS from DuckDB is similar to querying data in S3 from DuckDB. It is done using the httpfs extension connecting to the S3 Gateway that lakeFS provides.

If not loaded already, install and load the HTTPFS extension:

INSTALL httpfs;
LOAD httpfs;

Then run the following to configure the connection.

-- "s3_region" is the S3 region on which your bucket resides. If local storage, or not S3, then just set it to "us-east-1".
SET s3_region='us-east-1';
-- the host (and port, if necessary) of your lakeFS server
SET s3_endpoint='';
-- the access credentials for your lakeFS user
SET s3_access_key_id='AKIAIOSFODNN7EXAMPLE'; 
-- the access credentials for your lakeFS user
SET s3_secret_access_key='wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'; 
SET s3_url_style='path';

-- Uncomment in case the endpoint listen on non-secure, for example running lakeFS locally.
-- SET s3_use_ssl=false;

Querying Data

Once configured, you can query data using the lakeFS S3 Gateway using the following URI pattern:


Since the S3 Gateway implemenets all S3 functionality required by DuckDB, you can query using globs and patterns, including support for Hive-partitioned data.


FROM parquet_scan('s3://example-repo/main/data/population/by-region/*.parquet', HIVE_PARTITIONING=1) 
ORDER BY name;

Writing Data

No special configuration required for writing to a branch. Assuming the configuration above and write permissions to a dev branch, a write operation would look like any DuckDB write:

CREATE TABLE sampled_population AS SELECT * 
FROM parquet_scan('s3://example-repo/main/data/population/by-region/*.parquet', HIVE_PARTITIONING=1) 
USING SAMPLE reservoir(50000 ROWS) REPEATABLE (100);

COPY sampled_population TO 's3://example-repo/main/data/population/sample.parquet'; -- actual write happens here

Using DuckDB in the lakeFS web UI

The lakeFS web UI includes DuckDB in the Object viewer page.

DuckDB query editor on the lakeFS objects page

Using this you can query objects in lakeFS directly using a lakefs path:


The DuckDB query editor is provided by DuckDB WASM. It renders and provides querying capabilities for any objects of the following types:

  • Parquet
  • CSV
  • TSV