Skip to content

Query DuckLake through direct catalog attachment - #85

Merged
viggy28 merged 2 commits into
mainfrom
feat/ducklake-direct-query
Aug 31, 2026
Merged

Query DuckLake through direct catalog attachment#85
viggy28 merged 2 commits into
mainfrom
feat/ducklake-direct-query

Conversation

@viggy28

@viggy28 viggy28 commented Aug 31, 2026

Copy link
Copy Markdown
Owner

Summary

  • query DuckLake tables directly through the attached streambed catalog
  • remove DuckLake table discovery, compatibility views, and periodic refreshes
  • support streambed.public.orders, public.orders, and orders naming
  • keep the query server isolated from the writer with a read-only DuckLake attachment
  • recreate the isolated query attachment per client query to contain session mutations and refresh DuckDB-backed catalog snapshots
  • preserve the existing Iceberg discovery and iceberg_scan(...) view path

Tests

  • direct standalone DuckLake catalog attachment
  • qualified and unqualified table names
  • read-after-write for existing tables
  • immediate visibility of newly created tables
  • query-side writes are rejected
  • query-side DETACH does not affect the writer and the next query self-heals
  • no generated DuckLake compatibility views
go test ./...

Closes #72

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4813d690f2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread cmd/streambed/main.go Outdated
DuckLakeCatalog: cfg.DuckLakeCatalog,
DuckLakeCatalogStore: cfg.DuckLakeCatalogStore,
DuckLakeDataPath: cfg.EffectiveDuckLakeDataPath(),
DuckLakeDB: duckLakeDB,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Do not expose the writer session to arbitrary queries

When DuckLake sync runs with --query-addr, this passes the writer's single DuckDB session to a server whose handleParse executes every client-supplied statement without a read-only restriction. A client can therefore run session-mutating SQL such as DETACH streambed; because the writer uses this exact session, its next fully qualified flush fails with a missing-catalog error and interrupts replication. Keep query clients on an isolated connection or reject statements that can mutate the shared session/catalog.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 606f942. The query server no longer shares the writer DB. It owns a separate DuckDB session, attaches DuckLake with READ_ONLY, and recreates that isolated attachment before every client query so session mutations such as DETACH cannot affect replication and the next query self-heals.

Comment thread cmd/streambed/main.go Outdated
Comment on lines +536 to +537
if querySrv != nil && duckWriter != nil {
if err := querySrv.SetDuckLakeDB(duckWriter.DB()); err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Swap the query handle before closing the old writer

When a DuckLake pipeline reconnects, the old writer DB is closed at lines 527–529 before this replacement is installed. During that interval, query requests can still acquire duckDBMu.RLock and call QueryContext on the closed handle, producing avoidable client errors on every reconnect; configuring the new session before taking the write lock lengthens the window. Move closing and swapping into one synchronized operation so requests see either the old live handle or the new one.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 606f942 by removing the shared writer/query handle and SetDuckLakeDB path entirely. Pipeline reconnects no longer swap or close a DB used by the query server.

@viggy28
viggy28 merged commit 1447a72 into main Aug 31, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DuckLake query-server mode using direct catalog attach

1 participant