Repository navigation
Description
infoctl query has to stay read-only (#15). At a0b5e6c the command is still a stub (crates/cli/src/main.rs:18-21); PR #46 implements it by running each query through DataFusion's sql_with_options with SQLOptions that deny DDL, DML and statements such as SET, and tests that COPY, INSERT, CREATE TABLE AS, DROP and SET are rejected. Three more ways to write, or to read files outside the warehouse, are blocked in PR #46 but not tested: CREATE EXTERNAL TABLE ... LOCATION (blocked only by with_allow_ddl(false)), a file path used as a table name, as in SELECT * FROM '/path' (blocked only because the query session never calls enable_url_table), and EXPLAIN ANALYZE INSERT (blocked because the with_allow_dml(false) check also looks inside what EXPLAIN ANALYZE wraps), so a later change to the options or the session could reopen any of them without CI noticing. Separately, PR #46 checks only that the --warehouse directory exists, while Warehouse::open_local opens the SQLite catalog with mode=rwc and so creates catalog.db when it is missing (crates/storage/src/lib.rs:88-95): pointed at an existing directory that is not a warehouse, such as .infostash rather than the default .infostash/warehouse, the command writes an empty catalog there and then answers as if the warehouse had no tables. The file name is set by the private CATALOG_FILE constant (crates/storage/src/lib.rs:69). Repeat it in the CLI check, with a comment that points at that constant, rather than add public API to crates/storage; the existing CLI tests build their warehouses through Warehouse::open_local, so they will fail if the two names ever differ. Run the tests with cargo test -p infostash-engine --test query and cargo test -p infostash-cli --test query. If PR #46 is still open, its author may fold this work into it; otherwise, start from main after PR #46 has merged. The QueryContext parameter, loading every table's head together before registering any, the memory limit with an output cap, and the short infoctl query RFC are separate work in #95.
Crates: crates/engine (tests/query.rs, next to statements_that_write_are_rejected) and crates/cli (src/lib.rs and tests/query.rs), all in files that PR #46 adds
Done when
- Test:
CREATE EXTERNAL TABLE t STORED AS CSV LOCATION '<path>', where the path names a small CSV file the test writes into its temp directory, is rejected with anError::Planwhose message containsnot supportedandCreateExternalTable. - Test:
EXPLAIN ANALYZE INSERT INTO ready.daily_revenue VALUES ('2026-10-03', 5)is rejected with anError::Planwhose message containsnot supported, and the table's row count is unchanged afterwards. - Test:
SELECT * FROM '<path>'on the same CSV file returns an error rather than the file's rows, so the test fails if the query session ever turns onenable_url_table; assert only that it fails, because with URL tables off the path is looked up as an ordinary table name and the error need not saynot supported. -
infoctl querychecks that<warehouse>/catalog.dbexists as a file before it callsWarehouse::open_local, next to the existingis_dir()check incrates/cli/src/lib.rs, and otherwise exits 1 with the sameno warehouse aterror that PR feat(cli): infoctl query runs read-only SQL against the warehouse #46 gives for a missing directory. - Test:
infoctl query --warehouse <dir> "select 1"on an existing empty directory exits 1 with that error and leaves the directory empty, next toa_missing_warehouse_is_an_error_and_creates_nothingincrates/cli/tests/query.rs.
Points: 1 (M4 three deny-list tests and catalog.db existence check 1)
Depends on: #15 (the infoctl query command this extends)
Blocks: nothing
Source: design review of 2026-11-01, section 7.3 (points from section 8.5, M4).
Activity
fix(cli): refuse a warehouse directory without a catalog
codecapo commentedon Nov 10, 2026
Follow-up from the review of #46:
infoctl querystill opens the catalog withmode=rwc, so a zero-byte or non-SQLitecatalog.dbis created or has catalog tables written into it on the first open. Add to this ticket:mode=roon the query path, through a read-only variant ofWarehouse::open_localor a flag, so no read-only command can create catalog tables;codecapo commentedon Nov 10, 2026
The read-only catalog follow-up noted above moved to #104, since this ticket closed with #46.