feat(rust): add prepared statement and parameter binding support#378
Open
vikrantpuppala wants to merge 8 commits intomainfrom
Open
feat(rust): add prepared statement and parameter binding support#378vikrantpuppala wants to merge 8 commits intomainfrom
vikrantpuppala wants to merge 8 commits intomainfrom
Conversation
gopalldb
reviewed
Apr 8, 2026
| } else if bytes[i] == b'\'' { | ||
| state = SqlParserState::InSingleQuote; | ||
| i += 1; | ||
| } else if i + 1 < len && bytes[i] == b'-' && bytes[i + 1] == b'-' { |
Collaborator
There was a problem hiding this comment.
shall we also include double quotes and backticks?
gopalldb
reviewed
Apr 8, 2026
| .to_adbc() | ||
| })?; | ||
|
|
||
| // Execute once per row in this batch |
Collaborator
There was a problem hiding this comment.
looks inefficient, but okay since server side batch support would be coming soon
gopalldb
reviewed
Apr 8, 2026
| return sql.to_string(); | ||
| } | ||
|
|
||
| // Build result string, replacing each `?` at marker positions with `'?'` |
Collaborator
There was a problem hiding this comment.
this is a gap, will change the datatype, but may need to live with this
gopalldb
reviewed
Apr 8, 2026
rust/src/statement/params.rs
Outdated
| DataType::Date32 => { | ||
| let arr = array.as_primitive::<Date32Type>(); | ||
| let days = arr.value(index); | ||
| let date = chrono::NaiveDate::from_num_days_from_ce_opt(days + 719_163) |
Collaborator
There was a problem hiding this comment.
arrow_array provides Date32Array::value_as_date(index), can we use that?
Design for adding parameterized query support to the Rust ADBC driver via the SEA API's positional parameters. Covers SQL marker parsing, Arrow-to-SEA type conversion, bind/bind_stream lifecycle, and testing strategy. Co-authored-by: Isaac
execute_schema() currently does a full execute, violating the ADBC spec
("get schema without executing") and causing side effects for DML. Add
DESCRIBE QUERY approach with parameter marker substitution to the
prepared statement design doc.
Co-authored-by: Isaac
Implement parameterized query support via the SEA API's positional parameters. Includes SQL marker parsing, Arrow-to-SEA type conversion, bind/bind_stream lifecycle, and execute_schema via DESCRIBE QUERY. Changes: - Add StatementParameter type and wire through ExecuteParams/SeaClient - Convert statement.rs to statement/ module with new params submodule - Implement prepare(), bind(), bind_stream(), get_parameter_schema() - Fix execute_schema() to use DESCRIBE QUERY (no side effects) - Add VecBatchReader and ResultReaderAdapter::from_batches() for bind_stream result collection - Add E2E tests for parameterized queries, bind_stream, execute_schema - Fix missing auth.type in integration and FFI test setup Co-authored-by: Isaac
Co-authored-by: Isaac
Both execute() paths now collect into (schema, Vec<RecordBatch>) and return a RecordBatchIterator, eliminating the need for VecBatchReader and ResultReaderAdapter::from_batches(). Co-authored-by: Isaac
- Remove unnecessary `unsafe impl Send for Statement` - Fix execute() to stream results lazily for non-bind_stream path instead of buffering all batches in memory - Close server-side statements after draining in execute_with_stream to prevent statement ID leaks - Fix format_decimal128 sign loss for negative values where |raw| < divisor - Fix timestamp nanosecond conversion for negative (pre-epoch) values using div_euclid/rem_euclid - Add UInt8/16/32/64 support to Arrow-to-Databricks type mapping - Add missing test cases for negative decimal edge cases Co-authored-by: Isaac
Move arrow_type_to_databricks() to metadata/type_mapping.rs alongside databricks_type_to_arrow() so both directions live in one file. Remove duplicate databricks_type_to_arrow_type() and parse_decimal_params() from statement/params.rs. Add module-level comment that both mapping functions must be updated together. Co-authored-by: Isaac
- Add double quote and backtick quote handling to SQL parser so `?` inside quoted identifiers is not treated as a parameter marker - Use arrow-array's built-in value_as_date/value_as_datetime helpers for Date32, Date64, and Timestamp conversions instead of manual epoch arithmetic - Add tests for double-quoted and backtick-quoted identifier parsing Co-authored-by: Isaac
402cad0 to
c2f1ad6
Compare
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
prepare(),bind(),bind_stream(),get_parameter_schema(), and fixexecute_schema()to useDESCRIBE QUERYinstead of full execution?marker parsing (ignoring string literals/comments), Arrow-to-Databricks type conversion, and value serializationbind_stream()executes one SEA API call per row (no batch INSERT optimization)databricks.auth.typein integration and FFI test setupFiles changed
src/types/sea.rsStatementParameterstruct,parametersfield onExecuteStatementRequestandExecuteParamssrc/statement/mod.rsprepare/bind/bind_stream/get_parameter_schemaimpl,execute_schemafix, updatedexecutesrc/statement/params.rs(new)src/client/sea.rsparametersfromExecuteParamstoExecuteStatementRequestsrc/reader/mod.rsVecBatchReader+ResultReaderAdapter::from_batches()for stream result collectiontests/prepared_statement_e2e.rs(new)tests/integration.rs,tests/ffi_round_trip.rsdatabricks.auth.typeoptionTest plan
cargo fmt,cargo clippycleanThis pull request was AI-assisted by Isaac.