Sign inSign up

floci/floci-duck

Sponsored OSS

By Floci

Updated 4 months ago

DuckDB-powered SQL executor for local AWS Athena and Firehose emulation

Image
Data science
1

10K+

floci/floci-duck repository overview

Floci Duck

Floci Duck

Any Cloud. Locally.
A lightweight DuckDB-powered SQL executor sidecar for Floci

Release License: MIT Stars


floci-duck is the query engine behind Floci's Athena and Cost and Usage Reports support. It exposes a small HTTP interface that executes SQL through DuckDB, with S3-compatible storage wired in via the httpfs extension.

Written in Rust for minimal overhead. It is a sidecar, not a standalone emulator: Floci talks to it, you normally do not.

ComponentRolePort
flociAWS runtime4566
floci-duckDuckDB executor sidecar3000

Quick Start

The bundled docker-compose.yml brings up both Floci and floci-duck:

docker compose up --build

The executor is available at http://localhost:3000.

Build from source
cargo build --release
./target/release/floci-duck

On startup floci-duck runs a preflight check that installs the httpfs DuckDB extension to local disk, so every later request loads it instantly with no network download. If preflight fails, for example on a first boot with no network, a warning is logged and the extension installs on the first request that needs it.

Modes

ModeEndpointBehavior
S3 SelectPOST /queryRuns a query and returns rows as JSON
FirehosePOST /executeRuns any SQL directly: DDL, DML, COPY, and so on
AthenaPOST /execute with output_s3_pathWraps the SQL in COPY … TO … FORMAT CSV and writes results to S3

Parquet, CSV, and JSON are read and written directly from and to S3.

API

GET /health

Returns 200 OK with body OK.

POST /query

Executes a query and returns the result rows.

FieldTypeDescription
sqlStringThe SQL query to execute
s3_endpointStringS3-compatible endpoint, for example http://floci:4566
s3_regionString, optionalDefaults to FLOCI_DUCK_S3_REGION or us-east-1
s3_access_keyString, optionalS3 access key ID
s3_secret_keyString, optionalS3 secret access key
s3_use_sslBoolean, optionalAuto-detected from the endpoint scheme if omitted
s3_url_styleString, optionalpath or vhost. Default path
setup_sqlString, optionalSQL run before the main query, in the same session: views, temp tables, extensions
{
  "status": "success",
  "rows": [
    { "id": 1, "name": "Alice", "amount": 99.5 }
  ]
}

On error, status is "error", message carries the details, and rows is omitted.

POST /execute

Executes a statement with no row output. Takes the same S3 fields as /query, plus:

FieldTypeDescription
output_s3_pathString, optionalEnables Athena mode: results are exported here as CSV
variablesMap, optionalKey-value pairs substituted into the SQL as {{key}} placeholders
{
  "sql": "SELECT name, count(*) FROM users GROUP BY 1",
  "s3_endpoint": "http://floci:4566",
  "output_s3_path": "s3://results-bucket/report.csv"
}

S3 credentials in the request body are optional when the matching FLOCI_DUCK_S3_* environment variables are set.

Configuration

VariableDefaultDescription
FLOCI_DUCK_PORT3000Port the server listens on
FLOCI_DUCK_LOGinfoLog level: error, warn, info, debug, trace
FLOCI_DUCK_EXT_DIR(DuckDB default)Extension directory, useful in Docker to persist extensions across restarts
FLOCI_DUCK_S3_REGIONus-east-1Default S3 region
FLOCI_DUCK_S3_ACCESS_KEYflociadminDefault S3 access key ID
FLOCI_DUCK_S3_SECRET_KEYflociadminDefault S3 secret access key
FLOCI_DUCK_S3_USE_SSLautoAuto-detected from the endpoint scheme if unset
FLOCI_DUCK_S3_URL_STYLEpathpath or vhost

Observability

Every request carries a correlation ID, taken from the incoming x-correlation-id header or generated as a UUID v4. It is propagated through every log line for that request, including those emitted deep inside the executor, and appears as a bare value inside the span context.

curl -X POST http://localhost:3000/query \
  -H "Content-Type: application/json" \
  -H "x-correlation-id: my-trace-id-123" \
  -d '{ "sql": "SELECT 1", "s3_endpoint": "http://floci:4566" }'

Testing

duck-test is the integration test CLI. It needs a running server plus jq and curl, and the aws CLI for the init, parquet, and validate suites.

make dev-infra        # bring up infrastructure and create S3 resources
./duck-test all       # run every suite
./duck-test health query
./duck-test parquet --bucket my-bucket
./duck-test all -v    # print full JSON responses
SuiteWhat it tests
initCreates the S3 bucket and lists resources
healthServer liveness
queryBasic SELECT, NULLs, numeric types, setup_sql, correlation ID, error handling
executeFirehose mode, Athena mode (CSV to S3), variable substitution
parquetFull S3 round-trip: write, SELECT, filter, aggregate, DESCRIBE
httphttpfs loads and S3 settings are applied
validateDownloads the latest result file from S3 and prints it
allEvery suite in order

All options can be set as flags or environment variables (FLOCI_DUCK_URL, FLOCI_DUCK_S3_ENDPOINT, and so on).

Resources

License

MIT. Part of the Floci ecosystem.

Tag summary

Content type

Image

Digest

sha256:eadf68e49

Size

17.6 MB

Last updated

4 months ago

docker pull floci/floci-duck

This week's pulls

Pulls:

3,116

Last week