Skip to content

Implement database/sql driver with parameter binding and pooling#162

Open
wkk778 wants to merge 4 commits into
apache:mainfrom
wkk778:main
Open

Implement database/sql driver with parameter binding and pooling#162
wkk778 wants to merge 4 commits into
apache:mainfrom
wkk778:main

Conversation

@wkk778

@wkk778 wkk778 commented Jun 12, 2026

Copy link
Copy Markdown

No description provided.

asf-gitbox-commits and others added 2 commits June 12, 2026 15:52
… binding and connection pooling

- Add complete database/sql driver interface implementation
# Conflicts:
#	.github/workflows/go.yml
#	go.mod
#	go.sum
Comment thread database/iotdb_std.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a database/sql-compatible driver layer for the IoTDB Go client, including DSN parsing, parameter binding, and row/column scanning support, plus a suite of tests to validate basic query/scan behavior.

Changes:

  • Register and implement an iotdb database/sql/driver (connect/open, ping, exec, query, rows).
  • Add DSN parsing + query parameter binding helpers (positional, numeric, named).
  • Add column adapters and integration/unit tests for querying and scanning common IoTDB data types.

Reviewed changes

Copilot reviewed 33 out of 34 changed files in this pull request and generated 15 comments.

Show a summary per file
File Description
go.mod Adds github.com/pkg/errors dependency used by the new driver/binding code.
go.sum Updates sums for new dependencies.
client/session.go Adds Session.Ping(ctx) used by the sql driver pinger.
database/iotdb.go Introduces shared error values and transport abstractions used by the new driver.
database/iotdb_std.go Implements database/sql/driver connection behavior and registers the iotdb driver.
database/std_connect.go Defines the internal connection interface used by the stdlib driver wrapper.
database/std_conn_opener.go Implements a driver.Connector-style opener with address selection strategy.
database/conn.go Implements dialing and the pooled connection wrapper on top of client.SessionPool.
database/conn_exec.go Adds Exec path that binds parameters then executes statements.
database/rows.go Introduces internal rows wrapper around client.SessionDataSet.
database/rows_std.go Implements driver.Rows for database/sql iteration and scanning.
database/options.go Adds DSN parsing into Options and exposes driver/pool config fields.
database/query_parameters.go Adds helper to decide between native parameters and legacy bind interpolation.
database/bind.go Implements parameter interpolation (positional, numeric, named) and value formatting.
database/batch.go Adds a statement-like type intended for batch/prepared usage (currently stubbed).
database/context.go Defines query options stored in context and cloning/timeout behavior.
database/driver/driver.go Adds internal parameter wrapper types (NamedValue, NamedDateValue).
database/column/column.go Maps IoTDB type strings to column adapters for row value extraction.
database/column/bool.go BOOLEAN column adapter.
database/column/int32.go INT32 column adapter.
database/column/int64.go INT64 column adapter.
database/column/float.go FLOAT column adapter.
database/column/double.go DOUBLE column adapter.
database/column/string.go TEXT/STRING column adapter.
database/column/timestamp.go TIMESTAMP column adapter.
database/column/date.go DATE column adapter.
database/column/blob.go BLOB column adapter.
database/options_test.go Unit tests for DSN parsing behavior.
database/bind_test.go Unit tests for binding/interpolation and formatting.
database/conn_integration_test.go Integration tests for ping/pool/close/basic round trip.
database/query_test.go Integration tests for core SELECT/WHERE query behaviors.
database/query_agg_test.go Integration tests for aggregations/group-by/limit/align/metadata queries.
database/scan_types_test.go Integration tests for scanning IoTDB primitive types and text values.
database/iotdb_std_test.go Integration tests validating basic INSERT/SELECT via database/sql.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread database/conn.go
Comment thread database/iotdb_std.go
Comment thread database/iotdb_std.go
Comment thread database/bind.go
Comment thread database/column/blob.go
Comment thread database/column/int64.go
Comment thread database/column/date.go Outdated
Comment thread database/column/date.go Outdated
Comment thread database/column/date.go Outdated
Comment thread database/conn.go Outdated

@HTHou HTHou left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for taking on database/sql support. I found several correctness blockers around the driver contracts, result/session lifetime, NULL handling, and context propagation, so I’m requesting changes.

I verified the new package with go test -short ./database and go vet ./database. A full go test -short ./... attempt was killed locally during the Go linker step, so I do not have a full-repo test result from this machine.

Comment thread database/iotdb_std.go
Comment thread database/conn.go Outdated
Comment thread database/iotdb_std.go Outdated
Comment thread database/conn_exec.go
Comment thread database/rows_std.go
Comment thread database/bind.go
…ove type handling

- Add context support to ExecuteQueryStatement via new Option pattern
- Implement proper zero value returns for all column types (blob, bool, date, double, float, int32, int64)
- Replace stdBatch with stdStmt that implements full driver.Stmt interface
- Fix parameter binding regex to properly handle escaped question marks
- Improve connection pooling with timezone configuration and proper session management
- Add transaction support reporting with appropriate error messages
- Implement proper NULL value handling in row scanning
- Add comprehensive test coverage for new features and edge cases
- Introduce Options pattern for flexible client configuration
- Enhance session lifecycle management with proper resource cleanup
@shuwenwei

Copy link
Copy Markdown
Member

ExecContext still drops the caller context. database/iotdb_std.go passes ctx into std.conn.exec, but database/conn_exec.go accepts that context and then ignores it by calling session.ExecuteStatement(body). That method still delegates to ExecuteStatementWithContext(context.Background(), sql), so ExecContext deadlines/cancellation are not propagated to the RPC call.

QueryContext appears to have been updated correctly: database/conn.go now passes client.WithCtx(ctx) into ExecuteQueryStatement, and client/session.go uses that context for ExecuteQueryStatementV2, including the reconnect retry path. Please make the exec path mirror this by passing the original ctx into ExecuteStatementWithContext(ctx, body) or an equivalent context-aware exec method, and add regression coverage for ExecContext cancellation/deadline propagation.

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.

5 participants