Skip to content

A prepared query can't write a table it names with its schema (public.a) #322

Closed

Description

@alxmrs

🌀 Claude: A prepared query that names its table with the schema can't write it.

PreparedQuery decides which Datasets a call may write from the names in the query's plan. A plan prints a table as the query wrote it, so FROM public.a reads public.a, which isn't the key a the Dataset is registered under:

import numpy as np, xarray as xr
from xarray_sql import Context

ctx = Context()
ctx.from_dataset("a", xr.Dataset({"v": ("i", np.arange(3.0))}, coords={"i": np.arange(3)}))
q = ctx.prepare("SELECT v FROM public.a ORDER BY i")
q(a=xr.Dataset({"v": ("i", np.array([7.0, 8, 9]))}, coords={"i": np.arange(3)}))
ValueError: the query reads no Dataset registered as 'a' when it was prepared

Reproduced on main at 447791a (0.7.1), with DataFusion 55.0.0. FROM datafusion.public.a fails the same way. It errors, so it never gives a wrong answer.

The 0.8.0 hooks PR fixes it: the public Context.tables_read leaves out the default catalog and schema, as replacements already does since 0.7.1, and PreparedQuery uses it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions