Per-query settings: kwarg for execute/query/query_value/query_each - #5
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
settings:keyword argument to#execute,#query,#query_value, and#query_each(mirrored onPool), 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::SetSettingandClient::Execute(Query)rather than the bareSelect(sql, cb)path. Symbol or String keys are accepted; values render via#to_son the wire, withtrue/falsecoerced to"1"/"0".Why
Previously the only ways to influence per-request behavior were:
Pool.new(settings: ...)(too global), orSETTINGS k=vin the SQL string (works but pushes config into the query text).A
settings:kwarg matches what the HTTP-basedclick_housegem exposes and keeps configuration out of the SQL.Out of scope
#insertdoes not acceptsettings:. The clickhouse-cppClient::Insert(table, block)entry point doesn't thread per-call settings through, andBeginInsert(Query)silently drops them (the impl callsSendQuery(query.GetText()), constructing a fresh setting-lessQuery). The README points at pool-wide defaults or#execute("INSERT ... SETTINGS k=v VALUES ...")as workarounds.Test plan
per-query settings:coveringfinalvia each read method,readonlyvia#execute, String-keyed settings,true/falsecoercion, and the empty-hash no-op.bundle exec rspec— 70 examples, 0 failures.bundle exec rubocopclean.