Skip to content

Per-query settings: kwarg for execute/query/query_value/query_each - #5

Merged
tycooon merged 2 commits into
masterfrom
claude/pensive-cartwright-05d0d5
May 27, 2026
Merged

Per-query settings: kwarg for execute/query/query_value/query_each#5
tycooon merged 2 commits into
masterfrom
claude/pensive-cartwright-05d0d5

Conversation

@tycooon

@tycooon tycooon commented May 27, 2026

Copy link
Copy Markdown
Member

Summary

Adds a settings: keyword argument to #execute, #query, #query_value, and #query_each (mirrored on Pool), so callers can pass ClickHouse session settings on a per-request basis — e.g. client.query("SELECT * FROM t", settings: { final: 1 }).

Settings are routed through clickhouse-cpp's Query::SetSetting and Client::Execute(Query) rather than the bare Select(sql, cb) path. Symbol or String keys are accepted; values render via #to_s on the wire, with true / false coerced to "1" / "0".

Why

Previously the only ways to influence per-request behavior were:

  • pool-wide session defaults via Pool.new(settings: ...) (too global), or
  • inline SETTINGS k=v in the SQL string (works but pushes config into the query text).

A settings: kwarg matches what the HTTP-based click_house gem exposes and keeps configuration out of the SQL.

Out of scope

#insert does not accept settings:. The clickhouse-cpp Client::Insert(table, block) entry point doesn't thread per-call settings through, and BeginInsert(Query) silently drops them (the impl calls SendQuery(query.GetText()), constructing a fresh setting-less Query). The README points at pool-wide defaults or #execute("INSERT ... SETTINGS k=v VALUES ...") as workarounds.

Test plan

  • 7 new specs under per-query settings: covering final via each read method, readonly via #execute, String-keyed settings, true / false coercion, and the empty-hash no-op.
  • bundle exec rspec — 70 examples, 0 failures.
  • bundle exec rubocop clean.

tycooon added 2 commits May 27, 2026 12:07
Routes through clickhouse-cpp's Query::SetSetting and Client::Execute(Query)
so callers can pass session settings (e.g. final=1, max_threads=1) on a
per-request basis without falling back to inline SETTINGS clauses or
pool-wide defaults.

Symbol or String keys accepted; values render via #to_s with true/false
coerced to "1"/"0". #insert is intentionally not covered — clickhouse-cpp's
Client::Insert(table, block) has no hook for per-call settings; the README
points at the pool-wide / inline SQL workarounds.
@tycooon
tycooon merged commit 795e074 into master May 27, 2026
9 checks passed
@tycooon
tycooon deleted the claude/pensive-cartwright-05d0d5 branch May 27, 2026 09:16
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.

1 participant