Replies: 1 comment
|
Your observations line up with the current API: there is no public relation-scoped lifetime or release operation for the virtual name introduced by The name is resolved through the owning connection's context, and the derived relation remains lazy. Consequently, unregistering/dropping that name before the derived relation is bound or executed breaks it, while reusing the name can change what an already-created lazy relation binds to. Because a relation does not expose its connection, a library receiving only the relation cannot call the connection's public The only bounded pattern available today is to change the library contract so the caller supplies the connection as well, then:
That does not preserve a lazy returned relation. If laziness is required and the library owns neither the connection nor the registration lifetime, there is no supported cleanup pattern at present; staying inside relational operators is the only catalog-free route. I would file the late-rebinding reproduction separately as a bug or documentation issue, and treat relation-scoped replacement scans / missing relational ASOF, UNPIVOT, and UNION ALL BY NAME operations as feature work. In other words, this is a real API gap, not a cleanup method you overlooked. |
Uh oh!
There was an error while loading. Please reload this page.
Hi there 👋🏼 I am a Narwhals maintainer; Narwhals is a compatibility layer that lets library authors write dataframe-agnostic code, DuckDB included.
We wrap a
DuckDBPyRelationhanded to us by the user, and I'd like to check we're not missing somethingbefore accepting a limitation.
What I am trying to achieve
Run SQL against a user-supplied relation without leaving anything behind in their catalog.
A few operations we expose have no relational-API equivalent yet (
unpivot, ASOF joins, andunion all by name), hence we implement them withrel.query(virtual_table_name, sql). We moved torel.queryfromduckdb.sqldeliberately, since the latter runs on the process-global default connection, which isn't usable from multiple threads and I have been working on thread-safety recently.What I'd like is for the virtual table that
rel.queryregisters to be released once the relation derived from it is gone, or to be scoped in a way that lets us release it ourselves.Why I would like to achieve it
We are a library: the connection belongs to the user and typically outlives any individual call, so anything we register on it is effectively permanent from their point of view. Three things compound:
fetchall()into aCatalogException.Individually none of this is fatal, and the memory cost is small, yet we aim to avoid adding hidden costs for users as much as possible
Questions
rel.query()intended to live for the connection's lifetime, or is there a supported way to scope or release it that we've missed?unpivot, tracked in duckdb#16980 and duckdb#16996. If those land in the relational API our need forrel.query()disappears. That may be the real answer to all of the above.All reactions