You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A failed CREATE OR REPLACE, or DROP SCHEMA CASCADE, leaves a prepared query reading old rows #326
🌀 Claude: Two statements change a table without a prepared query noticing. The prepared query then returns old rows and doesn't raise. CodeRabbit found both while reviewing #323. I reproduced each on main at 447791a (0.7.1), with DataFusion 55.0.0.
importnumpyasnp, xarrayasxrfromxarray_sqlimportContextdefds(v):
returnxr.Dataset({"v": ("i", v)}, coords={"i": np.arange(len(v))})
defsplit(v): # two groups of dims, so from_dataset makes tables g.i and g.i_jreturnxr.Dataset(
{"v": ("i", v), "t": (("i", "j"), np.ones((len(v), 2)))},
coords={"i": np.arange(len(v)), "j": np.arange(2)},
)
1. A CREATE OR REPLACE TABLE that fails while it runs. DataFusion drops the old table before it computes the new rows. If computing them fails, the old table is gone, but Context.sql raised before it could count the replacement:
ctx=Context(); ctx.from_dataset("a", ds(np.arange(3.0)))
q=ctx.prepare("SELECT v FROM a ORDER BY i")
ctx.sql("CREATE OR REPLACE TABLE a AS SELECT 1 / (v - v) AS v FROM (VALUES (CAST(1 AS INT))) t(v)")
# Arrow error: Divide by zero errorctx.table_exist("a") # Falseq()["v"] # [0.0, 1.0, 2.0], from a table that no longer exists
A statement that fails while it's planned, such as one that reads a missing table, leaves the old table in place.
2. DROP SCHEMA ... CASCADE. It drops every table in the schema, but only DROP TABLE and CREATE OR REPLACE are counted:
ctx=Context(); ctx.from_dataset("g", split(np.arange(3.0)))
q=ctx.prepare("SELECT v FROM g.i ORDER BY i")
ctx.sql("DROP SCHEMA g CASCADE")
ctx.sql("CREATE SCHEMA g"); ctx.sql("CREATE TABLE g.i AS SELECT 9.0 AS v, 0 AS i")
q()["v"] # [0.0, 1.0, 2.0], with no error
Activity
Count a failed CREATE OR REPLACE, and DROP SCHEMA
Release 0.8.0 (#327)
Make Context's records of its tables and functions public (xqlsystems…