Skip to content

feat: add parameterized query support - #2

Draft
brettm-elastiflow wants to merge 13 commits into
feat-add-arrow-streamingfrom
feat-add-parameterized-query-support
Draft

brettm-elastiflow wants to merge 13 commits into
feat-add-arrow-streamingfrom
feat-add-parameterized-query-support

Conversation

@brettm-elastiflow

@brettm-elastiflow brettm-elastiflow commented Aug 27, 2026

Copy link
Copy Markdown

Do not merge, this branch is intended to be merged upstream. This PR is only for internal review.

This adds two things:

  • Binding wrappers for the with_params variants of chDB query APIs:
    • execute_with_params
    • execute_stream_with_params
    • execute_stream_arrow_with_params
  • Parameters builder API for providing Rust types as parameter values. chDB only accepts parameters as strings, and so any Rust value you want to provide as a parameter must be serialized to chDB-compatible strings

Not done:

  • serde integration for chDB serialization: I considered this to be out of scope for now. Practically speaking,/ though, this is going to be required for custom types to be used.

@brettm-elastiflow
brettm-elastiflow force-pushed the feat-add-parameterized-query-support branch from aa3b147 to e80365d Compare August 27, 2026 12:32

@larry-c-ef larry-c-ef left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several questions, but the code looks good.

Comment thread examples/13_query_with_params.rs
Comment thread src/query_param.rs Outdated
Comment thread src/query_param.rs Outdated
Comment thread src/query_param.rs Outdated
Comment thread src/connection.rs Outdated
Comment thread src/connection.rs Outdated
Comment thread src/connection.rs
Comment thread examples/README.md
Comment thread src/arrow_query_stream.rs
Comment thread src/session.rs
@brettm-elastiflow
brettm-elastiflow force-pushed the feat-add-parameterized-query-support branch from 116ea92 to cae8656 Compare August 28, 2026 00:06
@larry-c-ef
larry-c-ef force-pushed the feat-add-arrow-streaming branch from c5ba5eb to 7efb7b4 Compare September 9, 2026 15:19
wudidapaopao and others added 10 commits September 10, 2026 01:07
feat(streaming): add query result and arrow batch streaming
Wire a typed QueryParam surface through Connection, Session, and the
stateless execute helpers before implementing the libchdb FFI. Values
encode as strings; SQL still declares {name:Type}. Text and Arrow
stream entry points are included.

- src/query_param.rs: Added QueryParam/QueryParams with scalar, option,
  array, and raw literal encoding
- src/connection.rs: Stubbed query_with_params,
  query_stream_with_params, and query_stream_arrow_with_params
- src/session.rs: Stubbed execute_with_params,
  execute_stream_with_params, and execute_stream_arrow_with_params
- src/lib.rs: Exported query_param types and stubbed
  execute_with_params / execute_stream_with_params /
  execute_stream_arrow_with_params
- src/query_stream.rs: Stubbed parameterized stream constructors for
  chdb_stream_query_with_params
- src/arrow_query_stream.rs: Stubbed parameterized Arrow stream
  constructors for chdb_stream_query_arrow_with_params
Implement the materialized parameterized query path so typed
QueryParam values bind through chdb_query_with_params instead of
remaining a stub.

- src/query_param.rs: Added EncodedParams to build parallel
  NUL-terminated name/value CString arrays for the C ABI
- src/connection.rs: Implemented query_with_params via
  chdb_query_with_params, including empty-params fallthrough

Co-authored-by: Cursor <cursoragent@cursor.com>
Parameterized text streams can bind {name:Type} placeholders through
the same EncodedParams path as materialized queries.

libchdb reports missing-parameter errors on the first fetch rather than
stream start, so the substitution-error test asserts on next_chunk.

- src/query_stream.rs: Implemented start_query_with_params via
  chdb_stream_query_with_params
- tests/query_with_params.rs: Assert missing-param Substitution error
  on next_chunk for text streams

Co-authored-by: Cursor <cursoragent@cursor.com>
Parameterized Arrow streams bind {name:Type} placeholders through
EncodedParams, matching the materialized and text-stream paths.

- src/arrow_query_stream.rs: Implemented start_query_with_params via
  chdb_stream_query_arrow_with_params
- tests/query_with_params.rs: Assert missing-param Substitution error
  on next_batch for Arrow streams

Co-authored-by: Cursor <cursoragent@cursor.com>
Show Session::execute_with_params with a warehouse stock table,
including tuple arrays for same-typed binds and QueryParams for
mixed types.

- examples/12_query_with_params.rs: Added inventory lookup example
- examples/README.md: Listed the new example

Co-authored-by: Cursor <cursoragent@cursor.com>
@brettm-elastiflow
brettm-elastiflow force-pushed the feat-add-parameterized-query-support branch from cae8656 to 7b7b1f0 Compare September 9, 2026 17:39
The engine cannot run two queries on one connection. Parameterized
stream entry points still took `&self` after the rebase onto main,
and text-stream start still called a removed error helper instead of
destroying the C handle.

- docs/examples.md: Linked example 13 next to the streaming examples
- src/arrow_query_stream.rs: Borrow mutably; destroy failed starts;
  cover empty filters, retry-after-error, and syntax errors
- src/connection.rs: Take `&mut self` on parameterized stream methods
- src/query_stream.rs: Borrow mutably; destroy failed starts; cover
  retry-after-error and syntax errors
- src/session.rs: Take `&mut self` on parameterized streams; unwrap
  the optional connection like the non-parameterized paths
- tests/query_with_params.rs: Use mutable connections and sessions
  for stream cases

Co-authored-by: Cursor <cursoragent@cursor.com>
@brettm-elastiflow
brettm-elastiflow force-pushed the feat-add-parameterized-query-support branch from 13a67d9 to 3dd29e0 Compare September 9, 2026 20:14
A first-time visitor will find this API on docs.rs and in
docs/examples.md, not in the crate README. The README covers install
and engine constraints; parameterized queries are a query API.

- docs/examples.md: Added a top-level Parameterized Queries section
  with execute_with_params and QueryParams samples
- src/lib.rs: Listed parameterized queries in crate Features; documented
  errors and stream fetch-time substitution on execute_*_with_params
- src/query_param.rs: Documented QueryParams::new/bind, QueryParam
  variants, and that encoding does not change the SQL type
- src/connection.rs: Documented exclusive borrow, empty params, and
  stream substitution-on-fetch for the with_params methods
- src/session.rs: Added examples and Errors for execute_with_params
  and the parameterized stream methods

Co-authored-by: Cursor <cursoragent@cursor.com>
@brettm-elastiflow
brettm-elastiflow force-pushed the feat-add-parameterized-query-support branch from 3dd29e0 to c70d262 Compare September 9, 2026 20:36
chDB parses parameter strings with deserializeTextEscaped, so a value
like C:\temp became C: + TAB + emp. Text is a literal; Raw stays
pass-through for already-escaped input.

- src/query_param.rs: Encode backslash, tab, and newline on Text; do
  the same plus quotes for nested array elements
- tests/query_with_params.rs: Added chDB round-trips for C:\temp and
  a literal tab

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

3 participants